Mark_Kriegsman
Thu, 17 Dec 2015 17:15:20 +0000
FastLED Archive

TwinkleFOX: new Color Twinkles for 2015
Video: https://www.youtube.com/watch?v=CqCaF1bD4Uk
Code: https://gist.github.com/kriegsman/756ea6dcae8e30845b5a

A year ago, I offered up ‘twinkle lights’ for the holidays, and I’ve been thinking about them in the back of my mind ever since. I now humbly offer up “TwinkleFOX” : new, improved, and internally MUCH weirder!, color twinkle code.

As before:

use at many (or as few) color palettes as you like

several ‘holiday’ color palettes are included

palette cross-fades
And now, new/improved:

Much easier control over twinkle speed and density

Smoother fading in and out; truer, smoother color fades

Optional “background color” (other than black)

Lower memory usage: zero(!) bytes per-pixel overhead

Weird new internal design, which led to the new name: TwinkleFOX

Why is it called TwinkleFOX? Because the entire state of every LED in the array can be generated as a Function Of X, where X is a clock. There’s no need for storing the ‘state’ of each light: everything is a function of time. Much longer comments are in the code itself, here https://gist.github.com/kriegsman/756ea6dcae8e30845b5a But the basic idea is this: if you had only ONE pixel, and you wanted it to fade in and out, you could say something like:

pixelbrightness = sine( time )

And then given a particular point in time you could easily tell what brightness the pixel should be, right? (In a sense, this is how the ‘noise’ functions work, too.)

Well, so that’s more or less what’s going on here, too, except (1) each pixel has its own time clock, (2) each time clock moves at a slightly different speed, (3) each time clock has a slightly different zero-offset, and (4) none of this data has to be stored in precious RAM… it’s all “stored” in a random number generator. Yeah. Like I said: much weirder internals this time!

Feel free to just run the sketch and look at the pretty lights, or dig in and ponder the code. It took me months and months of background-thinking about this before I implemented it, so if it seems hopelessly abstract, you might be right about that.

Oh, and aesthetically, if you run it on an LED strip, instead of a pixel string, I recommend dropping the TWINKLE_SPEED and TWINKLE_DENSITY both down from “5” (the default) to “4” – but that’s a parameter you can play with yourself! See code for details.

Enjoy, and may your holidays be happy and filled with light!
-M
﻿
UPDATE: of course, I’ve found minor typos and things in the code, which I’ve fixed in the posted code now. If it’s not doing quite what you expect, just try re-downloading the latest version.

56 posts - 1 participant