<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
    <title>André Baltazar - Blog</title>
    <icon>https://andrebaltazar.com/favicon.ico</icon>
    <updated>2026-07-20T19:24:30+00:00</updated>
    <id>https://andrebaltazar.com/rss</id>
    <link type="text/html" href="https://andrebaltazar.com/blog" rel="alternate"/>
    <author>
        <name>André Baltazar</name>
        <email>me@andrebaltazar.com</email>
        <uri>https://andrebaltazar.com/</uri>
    </author>
    <entry>
    <id>https://andrebaltazar.com/blog/bd73/20260720-8-years-minus-2-days-since-last-blog-post</id>
    <title>8 year (- 2 days) since last blog post</title>
    <link rel="alternate" href="https://andrebaltazar.com/blog/bd73/20260720-8-years-minus-2-days-since-last-blog-post"/>
    <updated>2026-07-20T19:24:30+00:00</updated>
    <content type="html">&lt;p&gt;It&apos;s been quite a while since I wrote here... 8 years - 2 days to be exact. Still alive.&lt;/p&gt;
&lt;p&gt;Life happened during this time away. New skills were forged, and also dwindled away by the force of AI. LLMs are everywhere.&lt;/p&gt;
&lt;p&gt;They have changed the way I work, how I search for information, and how much code I actually remember how to write without some assistance. It is great to describe a problem and immediately get something that almost works. The “almost” part is important. You still need to understand what it produced, especially when it confidently invents a function, a configuration option, or an entire version of reality.&lt;/p&gt;
&lt;p&gt;Coming back to this website felt a little like opening a time capsule. Some of the code was written by a version of me that apparently liked creating features and then forgetting to finish them. There was an empty Let&apos;s Encrypt administration page, a Journal prototype with buttons that did nothing, and a Twitter widget that had stopped being useful a long time ago.&lt;/p&gt;
&lt;p&gt;Naturally, there were also several unfinished projects. At least that part of the website was still accurate.&lt;/p&gt;
&lt;p&gt;The site itself was still running on an old version of PHP. Somehow, most of it continued to work. The blog posts were still here, the images and GIFs still rendered, and the database survived all these years. That is probably more than I should have expected from code I had barely touched since 2018.&lt;/p&gt;
&lt;p&gt;It has now been moved to PHP 8.4 inside its own Docker container. The design was also updated, the broken Twitter widget was removed. The tags are still colored, of course. Some things are too important to remove.&lt;/p&gt;
&lt;p&gt;The Lab also received a new design. I would like to say this means it will be updated regularly with new experiments and finished projects, but the last eight years provide strong evidence against making that promise. It will continue to be a place for ideas, prototypes, and projects that may or may not reach the finish line.&lt;/p&gt;
&lt;p&gt;A lot has changed since the previous post, both in software and outside it. Frameworks appeared, became popular, and were replaced before I even had time to complain about them here. AI started writing code. JavaScript probably gained another few thousand ways to build the same website. PHP is still alive. Apparently, so is this blog.&lt;/p&gt;
&lt;p&gt;I don&apos;t know how frequently I will post from now on. Hopefully, the next one will arrive sooner than eight years from now. If it does not, at least the website should be better prepared to wait for it.&lt;/p&gt;
&lt;p&gt;Thanks for reading. See you in eight years! (Hopefully sooner.)&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;(Disclaimer: This article was fully written by AI from the completion of the first two initial lines, but it is eerily accurate.)&lt;/strong&gt;&lt;/p&gt;</content>
</entry>
<entry>
    <id>https://andrebaltazar.com/blog/e53b/20180722-flutter-animated-backgrounds</id>
    <title>Flutter Animated Backgrounds</title>
    <link rel="alternate" href="https://andrebaltazar.com/blog/e53b/20180722-flutter-animated-backgrounds"/>
    <updated>2018-07-22T21:16:11+00:00</updated>
    <content type="html">&lt;p&gt;In this post I will show you how to create a simple animated background from scratch using the Animated Backgrounds package available at &lt;a href=&quot;https://pub.dartlang.org/packages/animated_background/&quot;&gt;&lt;a href=&quot;https://pub.dartlang.org/packages/animated_background/&quot;&gt;https://pub.dartlang.org/packages/animated_background/&lt;/a&gt;&lt;/a&gt;, created by me.&lt;/p&gt;
&lt;p&gt;By the end of this post we will have an app with a background looking like this:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;./modules/blog/resources/e53b_cdef.gif&quot; alt=&quot;Bubbles&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Note that this background is interactive and you can pop the bubbles before they reach their maximum size. Also note that this post may be too detailed for new users. If you just want to check the code, go to my GitHub at &lt;a href=&quot;https://github.com/AndreBaltazar8/animated_background_example&quot;&gt;&lt;a href=&quot;https://github.com/AndreBaltazar8/animated_background_example&quot;&gt;https://github.com/AndreBaltazar8/animated_background_example&lt;/a&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;1. Getting Started&lt;/h2&gt;
&lt;p&gt;If you are new to Flutter go to the &lt;a href=&quot;https://flutter.io/&quot;&gt;Flutter website&lt;/a&gt; to download it. This should take you 5 to 10 minutes and you will be ready to develop applications in Flutter. I also suggest you to take some time to learn some basic concepts on their website.&lt;/p&gt;
&lt;p&gt;Building an animated background with this package is simple, all you need to do is implement a few methods that update and render the objects the represent that animated components of your background. Follow the steps below to get started.&lt;/p&gt;
&lt;p&gt;First of all, we need to have a project. If you are viewing this tutorial, you probably have a project you want to integrate this in, but I will create a new project to keep things simple.&lt;/p&gt;
&lt;p&gt;To create a new project just run &lt;code&gt;flutter create animated_background_example&lt;/code&gt; on your terminal. This should give you a fresh Flutter project.&lt;/p&gt;
&lt;p&gt;Open the project on your editor and open up the &lt;code&gt;pubspec.yaml&lt;/code&gt; file and add the package to your dependencies like this:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-yaml&quot;&gt;dependencies:
  animated_background: ^0.0.4&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;(Note: the current version might be different, please check the &lt;a href=&quot;https://pub.dartlang.org/packages/animated_background/&quot;&gt;package page&lt;/a&gt; and get the latest version.)&lt;/p&gt;
&lt;p&gt;After that run the &lt;code&gt;flutter packages get&lt;/code&gt; command to get the package.&lt;/p&gt;
&lt;p&gt;Your project is now ready to use animated backgrounds.&lt;/p&gt;
&lt;h2&gt;2. Creating an animated background with a default behaviour&lt;/h2&gt;
&lt;p&gt;Let&apos;s start by creating a background with a default behaviour. This is a behaviour that is already implemented in the package and available to everyone.&lt;/p&gt;
&lt;p&gt;Open the &lt;code&gt;lib/main.dart&lt;/code&gt; file that contains the root of your application. In this file you will see the Home Page widget that creates home page for your application. We will be extending this file to add our animated background.&lt;/p&gt;
&lt;p&gt;The package provides a widget appropriately named &lt;code&gt;AnimatedBackground&lt;/code&gt; that is used to add the background. This is the only widget necessary to render the animated background.&lt;/p&gt;
&lt;p&gt;To be able to use the widget we need to import it. This can be done with the code below (put it on the top of the file).&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-dart&quot;&gt;import &apos;package:animated_background/animated_background.dart&apos;;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In the &lt;code&gt;build&lt;/code&gt; method of the &lt;code&gt;_MyHomePageState&lt;/code&gt; class, we have the creation of the main widgets of the app. This is here we will insert an &lt;code&gt;AnimatedBackground&lt;/code&gt; widget.&lt;/p&gt;
&lt;p&gt;Wrap the &lt;code&gt;Center&lt;/code&gt; widget with an &lt;code&gt;AnimatedBackground&lt;/code&gt; widget and provide the &lt;code&gt;behaviour&lt;/code&gt; and &lt;code&gt;vsync&lt;/code&gt; parameters with the values &lt;code&gt;RandomParticleBehaviour()&lt;/code&gt; and &lt;code&gt;this&lt;/code&gt;, respectively.&lt;/p&gt;
&lt;p&gt;Your build method should now look like this:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-dart&quot;&gt;  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text(widget.title),
      ),
      body: AnimatedBackground(
        behaviour: RandomParticleBehaviour(),
        vsync: this,
        child: new Center(
          child: new Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: &amp;lt;Widget&amp;gt;[
              new Text(
                &apos;You have pushed the button this many times:&apos;,
              ),
              new Text(
                &apos;$_counter&apos;,
                style: Theme.of(context).textTheme.display1,
              ),
            ],
          ),
        ),
      ),
      floatingActionButton: new FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: &apos;Increment&apos;,
        child: new Icon(Icons.add),
      ),
    );
  }&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This will have an error on the &lt;code&gt;this&lt;/code&gt; value provided to the &lt;code&gt;vsync&lt;/code&gt; parameter. Before we fix this, let me explain what this parameter does. In order to animate the background we need to receive a tick from the application allowing us to update the background. This is done via this parameter where we specify a &lt;code&gt;TickerProvider&lt;/code&gt; that is used to create a ticker which will update our background.&lt;/p&gt;
&lt;p&gt;One simple way of getting a ticker provider is by making the state use the mixin &lt;code&gt;TickerProviderStateMixin&lt;/code&gt;. To do this edit the &lt;code&gt;_MyHomePageState&lt;/code&gt; declaration to use the mixin. It should look like the following:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-dart&quot;&gt;class _MyHomePageState extends State&amp;lt;MyHomePage&amp;gt; with TickerProviderStateMixin {
  // Class implementation
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You can now run the application! It should look like this:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;./modules/blog/resources/e53b_abcd.gif&quot; alt=&quot;Default Behaviour&quot; /&gt;&lt;/p&gt;
&lt;p&gt;You can experiment with all particle options available through the &lt;code&gt;options&lt;/code&gt; parameter of the behaviour to get different effects and even use images as the shape particles. An example app with configurable particle behaviour can be found inside the package, or on GitHub at: &lt;a href=&quot;https://github.com/AndreBaltazar8/flutter_animated_background/tree/master/example&quot;&gt;&lt;a href=&quot;https://github.com/AndreBaltazar8/flutter_animated_background/tree/master/example&quot;&gt;https://github.com/AndreBaltazar8/flutter_animated_background/tree/master/example&lt;/a&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;3. Creating a new behaviour (our new background)&lt;/h2&gt;
&lt;p&gt;From this point forwards things get serious. It requires some understanding of rendering in Flutter, but I will try to make it as simple as I can.&lt;/p&gt;
&lt;p&gt;As I showed in the start, we are trying to get a bubble like effect for our background. This is similar to the particles but we will be implementing it without using the particles behaviour as a base, because particles have movement, and we do not need that.&lt;/p&gt;
&lt;p&gt;Lets start by creating a class to hold the information about each bubble. For each bubble we will need the following information: its position, its current and final sizes and finally the color. The class will look like the following:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-dart&quot;&gt;class Bubble {
  Offset position;
  double radius;
  double targetRadius;
  Color color;
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now lets create the behaviour for these bubbles, lets call it &lt;code&gt;BubbleBehaviour&lt;/code&gt; and implement the &lt;code&gt;Behaviour&lt;/code&gt; class.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-dart&quot;&gt;class BubbleBehaviour extends Behaviour {
  @override
  void init() {
    // TODO: implement init
  }

  @override
  void initFrom(Behaviour oldBehaviour) {
    // TODO: implement initFrom
  }

  // TODO: implement isInitialized
  @override
  bool get isInitialized =&amp;gt; null;

  @override
  void paint(PaintingContext context, Offset offset) {
    // TODO: implement paint
  }

  @override
  bool tick(double delta, Duration elapsed) {
    // TODO: implement tick
  }
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Lets start by implementing the initialization of the bubbles. First we need a container to put the bubbles in. We will use a list for that. Inside the class declare a field of type &lt;code&gt;List&amp;lt;Bubble&amp;gt;&lt;/code&gt; that will hold our bubbles and name it &lt;code&gt;_bubbles&lt;/code&gt;, making it private and only editable by our class. One other thing that we need is how many bubbles will we display on screen. For this implementation we can use a constant number, so define with the number of bubbles you would like. Make sure this number is not too large, because it will cause performance problems if you create way too many bubbles.&lt;/p&gt;
&lt;p&gt;We are now ready to create our bubbles. For this, we use the &lt;code&gt;init&lt;/code&gt; method, which is called when the behaviour should be initialized. In this method we can generate the bubbles and assign them to the list. We use the following piece of code to achieve that:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-dart&quot;&gt;_bubbles = List&amp;lt;Bubble&amp;gt;.generate(numBubbles, (_) {
  Bubble bubble = Bubble();
  _initBubble(bubble);
  return bubble;
});&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We use the &lt;code&gt;generator&lt;/code&gt; constructor of a &lt;code&gt;List&lt;/code&gt; that allows us to generate a specified amount of values of a class. In this case we are generating &lt;code&gt;numBubbles&lt;/code&gt; amount of &lt;code&gt;Bubble&lt;/code&gt; instances, and calling &lt;code&gt;_initBubble&lt;/code&gt; with them as a parameter when they are created. This method will initialize each bubble according to our behaviour.&lt;/p&gt;
&lt;p&gt;Now that we initialized our bubbles we can implement the &lt;code&gt;isInitialized&lt;/code&gt; getter, that is used to check if the behaviour is initialized or not. We just need to make it return &lt;code&gt;true&lt;/code&gt; if the behaviour is initialized. We can simply return &lt;code&gt;_bubbles != null&lt;/code&gt; as the value.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-dart&quot;&gt;@override
bool get isInitialized =&amp;gt; _bubbles != null;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now we should also implement the &lt;code&gt;initFrom&lt;/code&gt; method which is used to initialize the behaviour from an old behaviour that was being used by the AnimatedBackground. This method will be called when the application updates state for example. In our case, we want to preserve the bubbles so we need to copy them from the old behaviour. To do this we can use this simple code:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-dart&quot;&gt;@override
void initFrom(Behaviour oldBehaviour) {
  if (oldBehaviour is BubbleBehaviour) {
    _bubbles = oldBehaviour._bubbles;
  }
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;For the final part of the initialization, we need to implement the &lt;code&gt;_initBubble&lt;/code&gt; method that we used before. This will take care of initializing the bubble.&lt;/p&gt;
&lt;p&gt;Since we want to initialize the bubble in a random position on the screen, we need to have a way to generate these random numbers. For this we can use the &lt;code&gt;Random&lt;/code&gt; class provided in &lt;code&gt;dart:math&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Import it using &lt;code&gt;import &apos;dart:math&apos;;&lt;/code&gt; and create an instance of the &lt;code&gt;Random&lt;/code&gt; class. This instance can be a static instance on the &lt;code&gt;BubbleBehaviour&lt;/code&gt; class.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-dart&quot;&gt;static Random random = Random();&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Lets start implementing our &lt;code&gt;_initBubble&lt;/code&gt; method. We start by generating a random position for both coordinates of the bubble. To do this we generate a random number with &lt;code&gt;random.nextDouble()&lt;/code&gt; multiply it by the screen size on that axis and assign that to the coordinate. To get the screen size, we can use the &lt;code&gt;size&lt;/code&gt; getter that is available for all &lt;code&gt;Behaviour&lt;/code&gt; classes. The initialization of the position will look like the following:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-dart&quot;&gt;void _initBubble(Bubble bubble) {
  bubble.position = Offset(
    random.nextDouble() * size.width,
    random.nextDouble() * size.height,
  );
  // TODO: missing other initializations
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Next we need to initialize our radius and target radius. For the &lt;code&gt;radius&lt;/code&gt; we can specify the value &lt;code&gt;0.0&lt;/code&gt;, because we want to make the bubble grow in size to the target radius. In the case of the target radius, we need to get a random number for it. We again make use of the &lt;code&gt;random.nextDouble&lt;/code&gt; method and with two new constants &lt;code&gt;maxTargetRadius&lt;/code&gt; and &lt;code&gt;minTargetRadius&lt;/code&gt; we can initialize the target radius. Since the color is all we have left to initialize, we can also initialize it to some color, for example, &lt;code&gt;Colors.red.shade300&lt;/code&gt; from the material design color swatches. You can take care of randomizing a color after, to make it cooler, but for now we will use only one color.&lt;/p&gt;
&lt;p&gt;The final code for &lt;code&gt;_initBubble&lt;/code&gt; will look like the following:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-dart&quot;&gt;void _initBubble(Bubble bubble) {
  bubble.position = Offset(
    random.nextDouble() * size.width,
    random.nextDouble() * size.height,
  );
  bubble.radius = 0.0;
  bubble.targetRadius = random.nextDouble() * (maxTargetRadius - minTargetRadius) + minTargetRadius;
  bubble.color = Colors.red.shade300;
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;By now you are probably tired and just want to see the bubbles on the screen of your device... but hang on, we are almost there. We just need to update the bubbles to make them grow and then paint them on the screen.&lt;/p&gt;
&lt;p&gt;Since we are working on the logic side of things, lets make the bubbles grow. For this we need to implement the &lt;code&gt;tick&lt;/code&gt; method. This method is called every tick of the ticker provider passed to the background. Before we create a loop to iterate over the bubbles to update them, we need to check if the behaviour was initialized. The reason for this check is to make sure we do not iterate over the &lt;code&gt;null&lt;/code&gt; container, since the &lt;code&gt;tick&lt;/code&gt; is called even if the behaviour is not initialized yet. (This will probably change in the future, so do not rely on this to initialize or do anything when the behaviour is ticking but not initialized...)&lt;/p&gt;
&lt;p&gt;Now we are ready to create the loop that iterates over our bubbles list. For each bubble we will need to increase its radius towards the target radius. This can be done using the &lt;code&gt;elapsed&lt;/code&gt; argument passed on the &lt;code&gt;tick&lt;/code&gt; method. This argument has the elapsed time (in seconds) since the last tick. This value is usually much less than 1 second. For example, if your app is running at normal speed (60 frames per second) it should be around 0.016667 seconds (1s / 60 frames = 0.016667 seconds per frame). We multiply this value, by a new constant that will be our growth rate, so call it &lt;code&gt;growthRate&lt;/code&gt;, and add the resulting value to the &lt;code&gt;radius&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;After growing the radius, we check if it is greater or equals to the target radius and in the case this is true, we call &lt;code&gt;_initBubble&lt;/code&gt; with the bubble. Remember this function is the one we created to initialize the bubble. This will reinitialize the bubble in a new position with a radius of &lt;code&gt;0.0&lt;/code&gt; and a new target radius, making it disappear. A custom effect for the bubble popping could be created but we will keep this simple. In the end of the function, return &lt;code&gt;true&lt;/code&gt; to specify that you want the background to repaint. The code for this function is like the following:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-dart&quot;&gt;@override
bool tick(double delta, Duration elapsed) {
  if (!isInitialized)
    return false;
  for (var bubble in _bubbles) {
    bubble.radius += growthRate * delta;

    if (bubble.radius &amp;gt;= bubble.targetRadius)
      _initBubble(bubble);
  }
  return true;
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now comes the part you were waiting for, drawing of the bubble, which is done in the &lt;code&gt;paint&lt;/code&gt; method. To get started drawing our bubbles we need to have access to the canvas, this is done through the &lt;code&gt;context&lt;/code&gt; argument. Simply define a &lt;code&gt;canvas&lt;/code&gt; variable from the &lt;code&gt;context.canvas&lt;/code&gt;. After this, we need to create an instance of &lt;code&gt;Paint&lt;/code&gt;, which is the object that defines a style to use when drawing on a canvas. In this paint object we want to change to fields that will be similar in all bubbles we draw. The first one is &lt;code&gt;strokeWidth&lt;/code&gt; which defines how wide the edges are drawn for our bubbles, and the second field is &lt;code&gt;style&lt;/code&gt; which we set to &lt;code&gt;PaintingStyle.stroke&lt;/code&gt; which specifies that we only want to paint the edges.&lt;/p&gt;
&lt;p&gt;We now have the canvas that we will draw the particle in and the paint that will be used to style our bubbles so its time to draw them. Create a loop to iterate the list of bubbles, and with the &lt;code&gt;color&lt;/code&gt; field of the bubble update the &lt;code&gt;color&lt;/code&gt; field of the paint instance. This will set the color for our next bubble that will be drawn. After that, use the &lt;code&gt;drawCircle&lt;/code&gt; method of the canvas to draw the bubble. Pass in  the position as the first parameter, the radius as the second, and finally the paint object to be used to draw. And that&apos;s it! Finally we are done! If you run the application the bubbles should render on the screen. The code for this method should look as the following:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-dart&quot;&gt;@override
void paint(PaintingContext context, Offset offset) {
  var canvas = context.canvas;
  Paint paint = Paint()
    ..strokeWidth = 3.0
    ..style = PaintingStyle.stroke;
  for (var bubble in _bubbles) {
    paint.color = bubble.color;
    canvas.drawCircle(bubble.position, bubble.radius, paint);
  }
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The result is what I showed at the start, but without interaction:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;./modules/blog/resources/e53b_cdef.gif&quot; alt=&quot;Bubbles&quot; /&gt;&lt;/p&gt;
&lt;p&gt;This is cool, but we can take it a little further and make this interactive, where we can &amp;quot;pop&amp;quot; the bubbles before they reach the target radius. Follow me to the next section where I will show you how to do that.&lt;/p&gt;
&lt;h2&gt;4. Adding interactivity&lt;/h2&gt;
&lt;p&gt;As you are probably familiar, in order to make a Flutter app, we use widgets for almost everything. Gesture detection is no exception. To make our behaviour detect gestures we make use of the &lt;code&gt;GestureDetector&lt;/code&gt; widget. The &lt;code&gt;onTapDown&lt;/code&gt; callback contains the necessary details to know which bubbles we need to pop. Next we add the widget to the tree. This is done by overriding the &lt;code&gt;builder&lt;/code&gt; method of the behaviour, and specify the widget normally, except for the &lt;code&gt;child&lt;/code&gt;, which must be a call to the &lt;code&gt;builder&lt;/code&gt; of the super class. It is also important to define the behaviour of the gesture detector to either &lt;code&gt;HitTestBehavior.translucent&lt;/code&gt; or &lt;code&gt;HitTestBehavior.opaque&lt;/code&gt; to be able to get the gestures. The only difference between them is that one allows taps to go through the detector to elements behind and the other does not.&lt;/p&gt;
&lt;p&gt;We still need to implement the logic for our tap down method. As I said previously, we receive the tap details in this callback, and we will use it to pop the bubbles. Set the callback of the tap as &lt;code&gt;(details) =&amp;gt; _onTapDown(context, details.globalPosition)&lt;/code&gt; this will forward our call to other method with the necessary arguments. In the implementation of the method, we start by finding the render box in the context, using &lt;code&gt;RenderBox renderBox = context.findRenderObject();&lt;/code&gt;. This render box allows us to convert the global position of the gesture to a local position using &lt;code&gt;renderBox.globalToLocal(globalPosition);&lt;/code&gt; which then can be used to know which bubbles should be affected by our tap. That&apos;s what we implement next.&lt;/p&gt;
&lt;p&gt;Create a loop for the bubbles, and subtract the position of the bubble from the local position of the tap that we just calculated. The resulting value should be of the type &lt;code&gt;Offset&lt;/code&gt;. With this you can get the square of the distance between the two positions with the &lt;code&gt;distanceSquared&lt;/code&gt; getter. Getting the square is faster than the actual distance between them because we don&apos;t need to perform a square root operation. You are probably thinking this is irrelevant but calculating the square root for many numbers, in our case, one for each bubble, can be quite expensive on the CPU.&lt;/p&gt;
&lt;p&gt;Finally we can compare this distance with the radius of the bubble, but since the distance is squared we need to have &lt;code&gt;bubble.radius * bubble.radius&lt;/code&gt; and you can also multiply this value by a small constant (eg. &lt;code&gt;1.2&lt;/code&gt;) to give the bubble a larger radius that we can press to pop it. If squared distance is smaller than the squared radius, we call &lt;code&gt;_initBubble&lt;/code&gt; to re-initialize the bubble. It should now be interactive. The full code for this section should be similar to:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-dart&quot;&gt;@override
Widget builder(BuildContext context, BoxConstraints constraints, Widget child) {
  return GestureDetector(
    behavior: HitTestBehavior.translucent,
    onTapDown: (details) =&amp;gt; _onTap(context, details.globalPosition),
    child: super.builder(context, constraints, child),
  );
}

void _onTap(BuildContext context, Offset globalPosition) {
  RenderBox renderBox = context.findRenderObject();
  var localPosition = renderBox.globalToLocal(globalPosition);
  for (var bubble in _bubbles) {
    if ((bubble.position - localPosition).distanceSquared &amp;lt; bubble.radius * bubble.radius * 1.2) {
      _initBubble(bubble);
    }
  }
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This concludes the creation of the interactivity and this example.&lt;/p&gt;
&lt;h2&gt;5. Conclusion&lt;/h2&gt;
&lt;p&gt;Finally you have a simple background working with interactivity. It can be easily extended to make a popping animation, implement the randomization of the color (which we setup the variable, but did not create code to change it) and some other tweaks. I leave it to you as an exercise.&lt;/p&gt;
&lt;p&gt;I understand that this post is extensive, probably contains some errors and not everyone will read it until the end, but if you did, thank you! If you have any question regarding this or suggestions on how to improve it, please tweet me &lt;a href=&quot;https://twitter.com/AndreBaltazar&quot;&gt;@AndreBaltazar&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The full code is available on my GitHub at:&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/AndreBaltazar8/animated_background_example&quot;&gt;&lt;a href=&quot;https://github.com/AndreBaltazar8/animated_background_example&quot;&gt;https://github.com/AndreBaltazar8/animated_background_example&lt;/a&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Hope you enjoyed! Have a nice day.&lt;/p&gt;</content>
</entry>
<entry>
    <id>https://andrebaltazar.com/blog/5e7d/20180106-project-and-ideas-lab</id>
    <title>New place for projects and ideas!</title>
    <link rel="alternate" href="https://andrebaltazar.com/blog/5e7d/20180106-project-and-ideas-lab"/>
    <updated>2018-01-06T17:20:00+00:00</updated>
    <content type="html">&lt;p&gt;It&apos;s been a while since my last post... I&apos;ve been doing some random stuff and playing more games, but I wanted to post an update on the site. A few days ago, I created a new place to share my projects and ideas, with the world. It&apos;s called &amp;quot;The Lab&amp;quot; and has just two ideas, a project, and a prototype of something I&apos;ve been working on. You can find it on &lt;a href=&quot;https://lab.andrebaltazar.com/&quot;&gt;&lt;a href=&quot;https://lab.andrebaltazar.com/&quot;&gt;https://lab.andrebaltazar.com/&lt;/a&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I would like to update it with a few more projects and ideas, but don&apos;t know when that is going to happen... (probably in another year?) There isn&apos;t much more to say. Thanks for reading, hope you find something interesting there.&lt;/p&gt;</content>
</entry>
<entry>
    <id>https://andrebaltazar.com/blog/9581/20170502-csgo-chicken-defusal-toaup</id>
    <title>CS:GO Chicken Defusal - Tales Of An Unfinished Project</title>
    <link rel="alternate" href="https://andrebaltazar.com/blog/9581/20170502-csgo-chicken-defusal-toaup"/>
    <updated>2017-05-02T19:00:00+00:00</updated>
    <content type="html">&lt;p&gt;Most of the times when I&apos;m not programming, I&apos;m playing games. I have been playing Counter-Strike (CS) for a long time, and Counter-Strike: Source (CS:S) is my most played game on Steam, with a total of 1866 hours on record. When Counter-Strike: Global Offensive (CS:GO) came out, I naturally transitioned to it. I have been playing for a long time with &lt;a href=&quot;https://twitter.com/THEREALUNREAL&quot;&gt;Ricardo &amp;quot;UNREAL&amp;quot; Sousa&lt;/a&gt;, who is a Level Designer/Game Dev/3D Modeler/Source Engine Expert (his words, not mine — more like Source Engine Mapping Expert). He has done lots of maps for the different versions of CS.&lt;/p&gt;
&lt;p&gt;Before CS:GO came out (early 2012), Ricardo watched a video on YouTube (included below), from Flashdeck Animations, which is kind of a joke about the game. However in this video they joke about having a bomb strapped to the chicken, and have the Counter-Terrorists chasing the chicken to try to defuse the bomb.&lt;/p&gt;
&lt;iframe width=&quot;560&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/NnZ8uj0kuXI?start=44&quot; frameborder=&quot;0&quot; allowfullscreen style=&quot;margin: 0 auto; display: block;&quot;&gt;&lt;/iframe&gt;
&lt;p&gt;He tried to implement this idea in a map, here is a video of the initial test map:&lt;/p&gt;
&lt;iframe width=&quot;560&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/QPzuCKYzF0M&quot; frameborder=&quot;0&quot; allowfullscreen style=&quot;margin: 0 auto; display: block&quot;&gt;&lt;/iframe&gt;
&lt;p&gt;This was the first implementation of the map, but the Flashdeck Animations guy &lt;a href=&quot;https://www.facebook.com/flashdeck/posts/112592598891673&quot;&gt;shared&lt;/a&gt; the video, which was awesome. When he told me that idea, he wanted me to turn this into a mod to actually be able to play any map as chicken defusal map, which we did. Well, at least we started... It gained some traction, and rechyyy (a popular YouTuber) made a video about it.&lt;/p&gt;
&lt;iframe width=&quot;560&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/lCic_CnHLew&quot; frameborder=&quot;0&quot; allowfullscreen style=&quot;margin: 0 auto; display: block&quot;&gt;&lt;/iframe&gt;
&lt;p&gt;This test, was a very early test of the mod, which allowed to spawn chickens with the bomb strapped in their backs, and played some effects when the bomb was supposed to explode. However, it was the foundation for the mod, which gained some attention from the community. I don&apos;t know exactly why the project did not go forwards as intended, because it was some years ago, but Ricardo told me it was related with the AI of the chicken, which would not allow the chickens to run uphill. The chickens were really dumb. And still are. They run into the corners of the map/into each other, and get stuck really easy.&lt;/p&gt;
&lt;p&gt;I suspect I was the one that did not want to move forward with the project, because Ricardo published a &lt;a href=&quot;https://steamcommunity.com/sharedfiles/filedetails/?id=130926160&quot;&gt;chicken defuse example map&lt;/a&gt;, in 2013, and states that &amp;quot;I made it into a map for the lack of scripters interested&amp;quot;. This map was visited by nearly 30 thousand people, and has 15 thousand subscribers, which is great! Again, this map was &lt;a href=&quot;https://www.facebook.com/flashdeck/posts/304471263014313&quot;&gt;shared&lt;/a&gt; by Flashdeck Animations. Sadly, it no longer works correctly.&lt;/p&gt;
&lt;p&gt;While researching for links to do this post, I found an implementation of the mod for CS:S (which I haven&apos;t tried), which was also inspired by the Flashdeck Animations video, and supposedly allows a dead terrorist player to control the chicken. I don&apos;t know how well that works. I also found some other YouTube videos about the topic (I will not link these because they were re-uploads from other YouTube channels, and I did not find the original videos).&lt;/p&gt;
&lt;p&gt;Everything considered, it was a great project with some traction behind it, however, in the end it is just another project that was not finished. It could have been something played by a lot of people, even though it is not really very competitive and more of a fun game mode. Maybe someone, someday will make a good chicken defusal mode. I will certainly give it a try (play the mod, not implementing it!).&lt;/p&gt;
&lt;p&gt;——&lt;/p&gt;
&lt;p&gt;I am thinking about doing some more posts like this one, so if you enjoyed this one, or have any question, hit me up on twitter @&lt;a id=&quot;twitter-name&quot; href=&quot;http://twitter.com/AndreBaltazar&quot; target=&quot;_blank&quot;&gt;AndreBaltazar&lt;/a&gt;.&lt;/p&gt;</content>
</entry>
<entry>
    <id>https://andrebaltazar.com/blog/cf79/20170413-react-native-some-thoughts-2</id>
    <title>React Native: Some Thoughts - Part 2</title>
    <link rel="alternate" href="https://andrebaltazar.com/blog/cf79/20170413-react-native-some-thoughts-2"/>
    <updated>2017-04-13T23:00:00+00:00</updated>
    <content type="html">&lt;p&gt;In my &lt;a href=&quot;/blog/ef51/20170210-react-native-some-thoughts&quot;&gt;last post&lt;/a&gt;, I talked a little bit about React Native. Today, I&apos;m here for a little rant about what I don&apos;t like about RN (or the reasons I will probably not use it again). &lt;strong&gt;These reasons may be somewhat biased towards how HTML and CSS work on the Web, but it reflects my opinion.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Let&apos;s get right into it:&lt;/p&gt;
&lt;p&gt;Styling is a mess in React. This is the main problem I have with React. I love how it allows to create dynamic styles (using code to modify the styles) for the different components, however, I think it should be easier to apply the styles. For example, if there is two images in a view, it is required to go to both images and create a &lt;code&gt;style&lt;/code&gt; property with the style we want for the image. This is were in my opinion, React&apos;s styles could be better, something like CSS where you can reference multiple elements/components with a single rule-set, and specifying the affected elements much easier. I know that CSS can get messy really fast, however, if done smart and modular, it offers an easier way to style the elements, compared to RN, even though it does not allow those &amp;quot;dynamic styles&amp;quot;.&lt;/p&gt;
&lt;p&gt;One other problem was, as I mentioned in the other post, that I structured my project following a guide on how to organize a RN project. This is made sense in the beginning, because I wanted to have the app organized, for future development, but it made me waste too much time organizing files, instead of actually programming the app. The way it is organized, separates everything into different files, and for someone getting into RN, I think its a daunting task to organize it all. I understand that this allows to have kind of MVC style app, but for a first app is not good. Managing all the callbacks from the different components, gets confusing really fast.&lt;/p&gt;
&lt;p&gt;Finally, I lost some interest in the app I was going to create. I wanted to create it using RN, to have a standalone app, with the bonus of having it be cross-platform. However, the idea required me to create a custom list-like component, with a group of priority items locked on top of the list. I managed to create half of the component, allowing the user to drag the list items, but it&apos;s missing the drop part. One of the reasons I found very difficult to create this was because the items were lagging behind the drag, due to having Developer Mode active on the app.&lt;/p&gt;
&lt;h1&gt;Conclusion&lt;/h1&gt;
&lt;p&gt;Even though I have these problems, I recognize that React has some good features, like the Hot Reloading that I discussed in the other post, which is super fast. However, this is not enough keep me using React. Maybe in the future, the styling will change, and I can take it for another spin.&lt;/p&gt;
&lt;p&gt;Thanks for wasting your time (seriously, it was for sure a waste of time) reading my post, and if you liked this post or have any question, please hit me up on twitter @&lt;a id=&quot;twitter-name&quot; href=&quot;http://twitter.com/AndreBaltazar&quot; target=&quot;_blank&quot;&gt;AndreBaltazar&lt;/a&gt;.&lt;/p&gt;</content>
</entry>
<entry>
    <id>https://andrebaltazar.com/blog/ef51/20170210-react-native-some-thoughts</id>
    <title>React Native: Some Thoughts</title>
    <link rel="alternate" href="https://andrebaltazar.com/blog/ef51/20170210-react-native-some-thoughts"/>
    <updated>2017-02-10T18:32:00+00:00</updated>
    <content type="html">&lt;p&gt;A few days ago, I started using &lt;a href=&quot;https://facebook.github.io/react-native/&quot;&gt;Facebook&apos;s React Native&lt;/a&gt;. I had an idea for an app, and decided to give RN a try. I installed it, and tried to run the &amp;quot;example application&amp;quot;, and could not figure out how to open the Developer&apos;s Menu in the Android Emulator to reload the code. Looked it up, and couldn&apos;t still open the menu. (BTW: I was on the right page, but didn&apos;t read it properly) So I immediately quit the emulator, uninstall everything, and go back to the Android Studio. Spent an hour creating some layouts, and an adapter for a list view, and went to bed. Next day, I wake up, and decide to give React Native another shot, because the layout that I made was bad, and it took me an hour to make it... Install everything again, and here we go, let&apos;s test the example application, change some code and try to open the menu, I glance at the same page, that I saw the day before and voilà, there it is the shortcut to open the damn menu... Great, let&apos;s see how fast I will be able to create something.&lt;/p&gt;
&lt;h1&gt;First Steps&lt;/h1&gt;
&lt;p&gt;I fire up Atom, and start changing some code to see how everything works. Since RN is programmed mostly in JavaScript, it&apos;s not difficult to get started. I create a simple component, import it, and it works great. The hot reloading is very fast. &lt;/p&gt;
&lt;p&gt;I decided I needed some way to organise the code for the app, because it will have many different views and components. With a quick search I found &lt;a href=&quot;https://medium.com/the-react-native-log/organizing-a-react-native-project-9514dfadaa0&quot;&gt;this guide by [Spencer Carli]&lt;/a&gt;, on the structure of a RN &amp;amp; Meteor project, I reproduced the structure, and went to work. In a few hours, I had the application, with a list view, running great with a much nicer layout. The project is now stopped for a few days, because I went trough two different sortable list view components that did not work as well as I wanted them to, and I needed to reevaluate how to do the layout properly.&lt;/p&gt;
&lt;h1&gt;Getting More Advanced&lt;/h1&gt;
&lt;p&gt;In the mean time, I started working on another idea, for a more connected app. It uses web sockets to communicate with a server and fetches some data. It works really great. Except the part where it spawns a connection every time the component hot reloads, and it doesn&apos;t close the previous one, that is something that needs some work from my part. I even added text-to-speech to see how it worked, and it is great! I am now ready to try and create my own sortable list, with some special features that I need for the other app to work correctly.&lt;/p&gt;
&lt;p&gt;Overall, the experience has been great so far, even though I think I waste so much time, looking at the application, because I save some edit, go check how it looks, change 1 or 2 lines of code, save, and repeat... Another thing I found, is that I don&apos;t like the separation between the logic and the view that the guide mention above does for the routes, it&apos;s much easier to write everything in the same file, in my opinion. Other than that, I think React Native, is great to develop applications easily, and offers the possibility of not having to right different code for different platforms (except if you want something that requires native functionality), which is great.&lt;/p&gt;
&lt;p&gt;These are some of my thoughts about React Native right now. I will keep using it for the time being, and see where it leads. If you liked this post or have any question, please hit me up on twitter @&lt;a id=&quot;twitter-name&quot; href=&quot;http://twitter.com/AndreBaltazar&quot; target=&quot;_blank&quot;&gt;AndreBaltazar&lt;/a&gt;.&lt;/p&gt;</content>
</entry>
<entry>
    <id>https://andrebaltazar.com/blog/6ffa/20170203-blog-pagination</id>
    <title>Blog Pagination is weird. Here&#039;s why.</title>
    <link rel="alternate" href="https://andrebaltazar.com/blog/6ffa/20170203-blog-pagination"/>
    <updated>2017-02-03T18:00:00+00:00</updated>
    <content type="html">&lt;p&gt;This week I had to implement a pagination system for the blog. Because, as I write more posts, the blog needs these kind of features. I started looking around at the blogs I read frequently, and ended up more confused on how to implement these pages than when I started.&lt;/p&gt;
&lt;p&gt;Typically a blog presents in the first page, the most recent posts, with the most recent on top, which gives more visibility to the new content in the blog. This makes sense, to hook the reader with the most recent content, instead of old, an sometimes outdated content. However, this is here things get interesting. This first page is typically the page number 1 (one) of the blog, and they offer different types of mechanisms to navigate to older content. There is usually an archive by date of the posts, on a side bar, or the page offers pagination after the last post. We are going to focus on this pagination mechanism.&lt;/p&gt;
&lt;p&gt;Let&apos;s start with this, blog pagination is weird, here&apos;s why. The first page of a blog, is usually numbered with number 1, and contains the most recent content on the blog, page number 2 contains content that is a little older, and so on.. This is contradictory to other things we do, for example, if you keep a diary, the most recent page is not the number 1, unless you are just starting your diary. What makes it even weirder, is that some blogs offer a link to navigate to the older posts, on the left side of the page, and to newer posts on the right side, implying that the older pages are to the left of the current one. Here is a image:&lt;/p&gt;
&lt;img src=&quot;./modules/blog/resources/6ffa_bc27.png&quot; style=&quot;max-width: 100%&quot;&gt;
&lt;p&gt;This is ridiculous when you think about it. The pages are numbered in the reverse order compared to a book, and when we insert a new blog post, every post is post is pushed &amp;quot;down&amp;quot;, which can generate new pages with a higher number, that contains the older post. This example is way different from the diary. Here is an image that illustrates the insertion of a new post: &lt;/p&gt;
&lt;img src=&quot;./modules/blog/resources/6ffa_8195.png&quot; style=&quot;max-width: 100%&quot;&gt;
&lt;p&gt;Notice how the oldest post here (the one with an &amp;quot;a&amp;quot;), is pushed to the the new page. However, there are other ways to do this pagination. Some other blogs use a pagination system where the pages seem to increase to the right, like in the next image.&lt;/p&gt;
&lt;img src=&quot;./modules/blog/resources/6ffa_a2dc.png&quot; style=&quot;max-width: 100%&quot;&gt;
&lt;p&gt;Of course, this still has the same problem has the previous pagination system, because the newest posts need to be pushed down, and never stay in the same page. Why is it important for the posts to stay in the same page, you may ask? Well, if you bookmark the page for example, it would be nice to have the same posts has it had before, specially in the case of indexation by a Search Engine. Sometimes the results of a search return a post in one of these dynamic pages, but when we visit the page, the post is no longer there, and that is annoying.&lt;/p&gt;
&lt;p&gt;One way to solve this problem of indexation, would be to have it organized like a book, and present only the last page, as in the following example:&lt;/p&gt;
&lt;img src=&quot;./modules/blog/resources/6ff1_f0bb.png&quot; style=&quot;max-width: 100%&quot;&gt;
&lt;p&gt;As we can see here, this causes a few problem, while in the other systems we control the number of posts we display (3 posts per page, in the examples), this can lead to a page with only one post. Another issue, is that the latest post, is not always at the top when presented to the viewer. This would cause way too much confusion, so I settled implementing the &amp;quot;next/previous&amp;quot; system.&lt;/p&gt;
&lt;p&gt;It is the system that is implemented at the moment, even though I don&apos;t like it that much. In the future, I will implement an Archive system, that indexes the posts, by year, that way everything is ordered chronologically, with a more understandable system, and which allows to be indexed and bookmarked. Meanwhile, everyone has to suffer with this system... If you have some comment about this topic, hit me up on twitter @&lt;a id=&quot;twitter-name&quot; href=&quot;http://twitter.com/AndreBaltazar&quot; target=&quot;_blank&quot;&gt;AndreBaltazar&lt;/a&gt;. (while I don&apos;t implement the comment section)&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;EDIT (2017/02/03 18:20)&lt;/strong&gt; - Fix title&lt;/p&gt;</content>
</entry>
<entry>
    <id>https://andrebaltazar.com/blog/517f/20170127-php-null-cast-type</id>
    <title>The PHP type cast that always returns NULL</title>
    <link rel="alternate" href="https://andrebaltazar.com/blog/517f/20170127-php-null-cast-type"/>
    <updated>2017-01-27T18:00:00+00:00</updated>
    <content type="html">&lt;p&gt;A few days ago I was going through the a &lt;span class=&quot;tag&quot; style=&quot;background-color: hsl(316, 92%, 77%)&quot;&gt;PHP&lt;/span&gt; RFC page when I found a &lt;a href=&quot;https://wiki.php.net/rfc/deprecations_php_7_2#unset_cast&quot;&gt;vote for deprecation&lt;/a&gt; of a cast I had never used before, a cast to &lt;code&gt;NULL&lt;/code&gt;. The keyword &lt;code&gt;unset&lt;/code&gt; is used for this cast, for example, &lt;code&gt;$b = (unset) $a&lt;/code&gt;, which results in &lt;code&gt;$b&lt;/code&gt; being assigned with the value &lt;code&gt;NULL&lt;/code&gt;, and nothing else. This should not be confused with the function &lt;a href=&quot;http://php.net/manual/en/function.unset.php&quot;&gt;unset&lt;/a&gt;, which really unsets the value.&lt;/p&gt;
&lt;p&gt;I could not find any actual usage of this casting type on GitHub, except for some tests, and other useless stuff. A Google search also falls short of anything interesting, except for a &lt;a href=&quot;http://stackoverflow.com/questions/7081896/anyone-ever-used-phps-unset-casting&quot;&gt;question on StackOverflow&lt;/a&gt;, related with this type cast, asking for what is the point of it. Only the latest answer, by [Mihailoff], has a plausible use for this type casting. Take a look at this example:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;$someBool = false;
$result = $someBool ? &apos;foo&apos; : (unset) fallback();&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This allows the variable &lt;code&gt;$result&lt;/code&gt; to be either &lt;code&gt;&apos;foo&apos;&lt;/code&gt; or &lt;code&gt;NULL&lt;/code&gt;, but in the latter, we still run a function to do something, and ignore its value. However this could be done in way which is easier to read:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;$someBool = false;
if ($someBool)
    $result = &apos;foo&apos;;
else {
    fallback();
    $result = NULL;
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Of course that I see the trade-off there, but either way, I don&apos;t think I have ever seen the use of this cast before. In &lt;span class=&quot;tag&quot; style=&quot;background-color: hsl(104, 77%, 75%)&quot;&gt;C&lt;/span&gt; and &lt;span class=&quot;tag&quot; style=&quot;background-color: hsl(152, 78%, 85%)&quot;&gt;C++&lt;/span&gt; it is somewhat common to cast things to &lt;code&gt;void*&lt;/code&gt;, but note that it is a pointer to something without a type. This is used for example in &lt;span class=&quot;tag&quot; style=&quot;background-color: hsl(145, 75%, 84%)&quot;&gt;OpenGL&lt;/span&gt;, to pass arbitrary type buffers to the GPU.&lt;/p&gt;
&lt;p&gt;In the same question mentioned above, there is an answer which contains a &lt;a href=&quot;https://bugs.php.net/bug.php?id=55164&quot;&gt;bug report&lt;/a&gt; related with this cast, because even the manual was not clear to how it worked. In this bug report, &lt;span class=&quot;tag&quot; style=&quot;background-color: hsl(316, 92%, 77%)&quot;&gt;PHP&lt;/span&gt; maintainer [frozenfire] states that &amp;quot;That casting type
exists purely for completeness, and you may as well just use NULL.&amp;quot;. However, I decided to dig up when this feature was implemented, and turns out it &lt;a href=&quot;https://github.com/php/php-src/commit/f2d703e916e767e86c2d6434e809f29f6906f5fc&quot;&gt;was implemented 17 years ago&lt;/a&gt;, on 31 Dec 1999. It is a very old feature that persisted through time without any apparent usage.&lt;/p&gt;
&lt;p&gt;If you liked this post or have any question, feel free to hit me up on twitter @&lt;a id=&quot;twitter-name&quot; href=&quot;http://twitter.com/AndreBaltazar&quot; target=&quot;_blank&quot;&gt;AndreBaltazar&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Links:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://wiki.php.net/rfc/deprecations_php_7_2#unset_cast&quot;&gt;https://wiki.php.net/rfc/deprecations_php_7_2#unset_cast&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://stackoverflow.com/questions/7081896/anyone-ever-used-phps-unset-casting&quot;&gt;http://stackoverflow.com/questions/7081896/anyone-ever-used-phps-unset-casting&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://bugs.php.net/bug.php?id=55164&quot;&gt;https://bugs.php.net/bug.php?id=55164&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/php/php-src/commit/f2d703e916e767e86c2d6434e809f29f6906f5fc&quot;&gt;https://github.com/php/php-src/commit/f2d703e916e767e86c2d6434e809f29f6906f5fc&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</content>
</entry>
<entry>
    <id>https://andrebaltazar.com/blog/92d0/20170121-implementing-tag-system</id>
    <title>Implementing a simple tag system</title>
    <link rel="alternate" href="https://andrebaltazar.com/blog/92d0/20170121-implementing-tag-system"/>
    <updated>2017-01-21T22:11:46+00:00</updated>
    <content type="html">&lt;p&gt;In the process of implementing this blog, I thought of having tags associated with the posts. This allows me to categorize the posts. However, I did not want to implement a very complex system that allows to manage the color, define which tags exist, etc, but wanted to have a color associated with each tag.&lt;/p&gt;
&lt;p&gt;The tags of the post are stored with each post, and no color is save in the database. The focus here is how to get the color for the tags. The implementation I came up with was to hash the tag, and use the value to define the color. The following piece of code is what is used by this blog to create the color of tags like &lt;span class=&quot;tag&quot; style=&quot;background-color: hsl(270, 76%, 79%)&quot;&gt;Code&lt;/span&gt; and &lt;span class=&quot;tag&quot; style=&quot;background-color: hsl(158, 74%, 90%)&quot;&gt;Color&lt;/span&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-php&quot;&gt;function tagColor($tag) {
    $m = md5(strtolower($tag));

    $h = floor(hexdec(substr($m, 0, 4)) / 65535 * 359);
    $s = (hexdec(substr($m, 4, 2)) % 32) + 69;
    $l = (hexdec(substr($m, 6, 2)) % 16) + 75;
    return &apos;hsl(&apos; . $h . &apos;, &apos; . $s .&apos;%, &apos; . $l . &apos;%)&apos;;
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In order to have more control of how the final look of the tag looks like the HSL color model was used, because the lightness needs to be high to have a good contrast with the tag text color. Since the hue is a value between 0 and 359, a single byte from the hash is not enough to get the full range, so I use 2 bytes to get the hue, and scale it from [0, 65535] to [0, 359]. For the saturation and lightness, we sample 1 byte for each of them, and do some more math to get a good value. The saturation, uses 32 modulo to get a value from [0, 31] plus a the predefined value in this case 69, which makes for a good range [69, 100] in the saturation. In the case of the lightness the modulo 16 is used to have a lower range [75, 90] of lightness values when the predefined value of 75 is added.&lt;/p&gt;
&lt;p&gt;A few optimizations could be done here, to get the values faster, but the code is about simplicity, and understanding how the color for the tags can be created from the tag itself.&lt;/p&gt;
&lt;p&gt;This creates a simple, yet effective system of tags, which have the same color across the posts, even though the color is not stored anywhere. If you liked this post or have any question, feel free to hit me up on twitter @&lt;a id=&quot;twitter-name&quot; href=&quot;http://twitter.com/AndreBaltazar&quot; target=&quot;_blank&quot;&gt;AndreBaltazar&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Thanks for reading!&lt;/p&gt;</content>
</entry>
<entry>
    <id>https://andrebaltazar.com/blog/b51f/20170121-welcome</id>
    <title>Welcome!</title>
    <link rel="alternate" href="https://andrebaltazar.com/blog/b51f/20170121-welcome"/>
    <updated>2017-01-21T21:19:25+00:00</updated>
    <content type="html">&lt;p&gt;Hello there. This is the first blog post I have ever written. Like &lt;strong&gt;EVER&lt;/strong&gt;!&lt;/p&gt;
&lt;p&gt;First of all, welcome to my website. It is still work-in-progress but it&apos;s evolving fast. This will be a place were I discuss ideas related to projects I&apos;m working on and interesting things I find around the web. Occasionally, a post with more in-depth information relating to some specific problem may also show up.&lt;/p&gt;
&lt;p&gt;Stay tuned. Cheers!&lt;/p&gt;</content>
</entry>
</feed>
