Friday was one of these days that I just seemed completely unable to focus on the thing I was supposed to do, which is making a new level. It’s not that making levels isn’t fun, because it is. Just didn’t seem to happen that day… The funny thing is, on those days a lot of other things do happen.
Since the level I was supposed to be working is set at night, I figured it would be nice to have some lights flicker when switching on.
But how exactly do lights flicker? Deciding that this situation called for some experiments, I started my code editor and dragged out the Caromble! toolbox. First thing that came out was a simple formula: x*x. Plugging that in the function that controls the intensity of the light, we get a light that gets brighter at an increasingly quick rate. Nice, but not quite what I was after…
Then I thought of an old friend: Perlin Noise! Perlin noise is nice, because it gives you a random number that varies over time, but in a coherent way. For the light this means that it will be on for a while, then off for another, but not switching every frame. This already gave a nice flickering effect.
The disadvantage of this method is the rate of flickering is constant throughout the whole period. I want the rate of flickering to be high at start, and then gradually decrease. I achieved this effect by taking the square root of the time parameter, before plugging it into the Perlin noise function.
And here is how that looks: