Most programming these days seems to consist of banging other people’s code together until it all behaves. This wasn’t much different.
I’ve been playing around with some algorithms for the Mitochondrion, Mark 4.1. For one mode, I want smoothly flowing and random patterns. There’s a kind of noise that suits called Perlin noise, invented by Ken Perlin and used to generate natural patterns like clouds in possibly every movie ever.
So, I found an implementation for Arduinos by some guy on a forum, tried it, horribly slow. Like a couple of hundred times too slow to give me a smoothly changing pattern on the hardware I’m using. There’s another kind of noise called simplex noise, also by Ken Perlin and faster. Found someone’s implementation in Java, ported it, tried it, faster, but still not fast enough. Scratched my head for a while, slept on it, had a shower and in the shower came up with the only original idea here, which is to just run the simplex noise for a few of the LEDs spaced out along the LED strip and just interpolate to fill in the gaps. Tried it, total speed up of around three hundred and now I’ve a hundred LEDs all doing what I want.
So cubic interpolation makes me happy, although to be honest, I wouldn’t have thought of doing it like this if I hadn’t asked Ranty Dave an entirely different answer a few months back and received the answer that “Catmull–Rom splines, mate, see you right”. And it’s not exactly a new idea to say “slow algorithm is slow, so only do slow algorithm occasionally and use fast algorithm to fill in the gaps”.
Anyway, here’s a vid of the Perlin, simplex, and interpolated modes. (On anything less than 720p it’s a little jerky, but that’s Youtube’s compression, not my code.)
Question for people who actually know about this stuff: Perlin and simplex noise produce noise with a (roughly) normal distribution, i.e. across the interval from -1 to 1, but mostly clustered about zero. What if I want smooth noise with a flat distribution, i.e. with equal probability of occuring in the interval from 0 to 1? I ask as I’m changing the above code from RGB to HSV so that I can control the saturation (coz max saturation FTW) and I’d like to pick hues with an equal chance of getting any hue.
Is there an algorithm that does smooth noise with a flat probability? I haven’t found one, but I don’t know where to look. Right now I’m just expanding, scaling, and clipping the simplex noise, which isn’t really very flat at all.