tl;dr Just give me the code! Here you go:

(Stefan Petrick) #1

tl;dr Just give me the code! Here you go:

Hi everyone! 2d matrix effects are a nice thing to code - but this requires lots of physical leds and a strong power supply to feed them.

So why not creating a 2d effect with just a very small amout of leds?

Here is the idea: Imagine a virtual 256x256 matrix. And imagine a circle constisting of NUM_LEDS leds. Now place this circle on the virtual matrix. The circle can be mathematically described as 2 overlapping functions - a sinus on x and a cosinus wave on y. The angle position of every single led we know - assuming the circle consists of 256 angle units the absolute x/y position defined by the relative angle of the given led is uint8_t angle = (i * 255) / NUM_LEDS;

So long story short - my code does the following: Calculate one time a look up table which contains the x/y position of any led within the virtual 256x256 matrix. This allows to calculate the noise data only for the few positions we really need = it´s fast while it still has the precision of a high-res matrix.

Based on that it´s easy to move the noise field in any direction(s).

The code contains 3 independent examples: example_1 moves the content up and down while shifting it slowly to the side. example_2 moves just along one axis and example_3 moves along the z axis of the noise space. Of course this simple movements can be combined or described by more complex functions, or they could be controlled by audio or sensor data or anything else you can imagine.

The color mapping could be improved as well - I decided to use a simple HSV mapping in order to keep the code simple and easy readable for the beginning.

The code is meant to inspire you to play with it yourself and create nice animations even for a limited setup. That´s why I kept the code short. It´s about the idea and not so mutch about delivering a plug and play animation.

Questions, suggestions and comments are highly appreciated. Has the code enough comments to get the idea? Is it useful for you?

What will you create based on this mapping?
Looking foreward to seeing it!

(Freddie Olivas) #2

Is your diffuser a pillow? It looks soft and squishy.

(Jon Bruno) #3

Brilliant Stephan, Just brilliant.

(Andrew Tuline) #4

Today was crazy busy and I hope to have a look at your routine(s) over the next few days. . . .

Update: Cool. I’ve now converted that to palette lookup with smooth transitioning to a new one every 5 seconds and trying out mathematical variations of each of the variables.

(Stefan Petrick) #5

@Freddie_Olivas The refelctor is a solid brown clay wall. :slight_smile:

(Kasper Kamperman) #6

Super smart!

(Stefan Petrick) #7

Thanks, everyone! The laste time I played with this idea was already 2 years ago with only 32 leds in the circle. Back then I calculated the whole matrix data and picked afterwards the little data I really needed for the circle. Here the link to the post:

(Jürgen Skrotzky) #8

@Stefan_Petrick ​ what a brilliant idea and code. Like it and will try it next time I’m in the hackerspace

(Andrew Tuline) #9

Between Stefan’s routine and the following one by Mark Kriegsman, we’ve got some very cool possibilities:

(Shawn A) #10

Could this be done inverted with an outer facing and inner facing ring to double the size? granted there would be a thin circle in the middle of the field.

(Michael Holcombe) #11

this is exactly what i needed to kick off the lighting for my halloween mask!! excellent work. as an aside, you can work with specific palettes by using:
CRGB color = ColorFromPalette( paletteVariable, index, bri);

instead of
CRGB color = CHSV(index, 255, bri);

hope that’s helpful to someone!

(Michael Holcombe) #12

here’s v1.2.1 of my halloween mask with the plasma/noise from this example :smiley: thanks for the help!!

(John Hendy) #13

Could you walk me through the gist of this, maybe with a picture of your virtual matrix/functions? So the idea is that from some position on the circle you can re-create the effect of a square matrix? I’m not sure I follow, exactly but it’s interesting!

The idea is to use angular coordinates to create the same complex effects that would be a lot more challenging if using x/y – is that the gist?

(Stefan Petrick) #14

@John_Hendy : Yes, the polar coordinates of the leds are transformed into x/y coordinates.
FastLED noise functions calculate a noise value for a given x/y/z value. So if the precalculated leds x/y coordinates are fed into the noise function the visible effect is basically the same as it would be on a 2 dimensional matrix - just with way less leds. Does that help?

(Stefan Petrick) #15

In pictures: This is the circular function - alpha is defined by the led index.
And with integer math the result is this:

(Ben Camp) #16

Seriously what is that diffuser tho

(Stefan Petrick) #17

@Ben_Camp Brown clay, seriously.

(Brian Lewis) #18

@Stefan_Petrick ​ just loaded this onto my infinity mirror circle clock thing. Looks really awesome. Thanks for sharing the code.

(Cogwun) #19

When I upload I get the error:

no matching function for call to ‘CFastLED::addLeds(CRGB [150], int)’

I’m a beginner and probably missing something obvious, but I’ve played around and Googled and can’t figure it out. Please help!

Wemos D1 Mini and WS2812B strip

(Brian Lewis) #20

@Cogwun Have you installed the FastLED library yet? If so, which version are you using?