Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // A simple caleidoscope by Stefan Petrick
- #include <FastLED.h>
- #define WIDTH 16
- #define HEIGHT 16
- #define NUM_LEDS ((WIDTH) * (HEIGHT))
- CRGB leds[256];
- float rnd;
- void setup() {
- Serial.begin(115200);
- FastLED.addLeds<APA102, 11, 13, GBR, DATA_RATE_MHZ(12)>(leds, 256);
- randomSeed(analogRead(10));
- rnd = random(1000000); // just a different starting point for each program start
- }
- void loop() {
- for (int y = 0; y < 16; y++) {
- for (int x = 0; x < 16; x++) {
- uint32_t time = millis();
- time = time * 10.5; // adjust global speed here
- time = time + rnd;
- uint16_t a = inoise16((x * 22000) + (time * 23), (y * 22000) + (time * 21), 1);
- uint16_t b = inoise16((a * 4) + (x * 15000) + (time * 25), (y * 15000) + (time * 25), 1);
- uint16_t c = inoise16((b * 4) + (x * 6000) + (time * 24), (a * 4) + (y * 6000) + (time * 27), 7);
- a = map(a, 20000, 65535 , 0, 250);
- if (a > 250) a = 0;
- b = map(b, 20000, 65535 , 0, 250);
- if (b > 250) b = 0;
- c = map(c, 20000, 65535 , 0, 250);
- if (c > 250) c = 0;
- //CRGB col1 = CRGB(a,abs(b-a)/3,a/5);
- //CRGB col2 = CRGB(abs(a-b)/2,0,b/4);
- //CRGB col1 = CRGB(abs(a ), a / 4, c);
- //CRGB col2 = CRGB(abs(b - a), b / 4, 0);
- CRGB col3 = CRGB(a, b/2, c/2);
- leds[XY(x, y)] = col3;
- // filter mask based on 3d noise layer
- //leds[XY(x, y)].fadeLightBy(a);
- // linear filter to fade out upwards
- //leds[XY(x, y)].fadeLightBy((y * 12));
- }
- }
- // make a caleidoscope by copying one quadrant into the 2nd
- for (int y = 0; y < 9; y++) {
- for (int x = 0; x < 9; x++) {
- leds[XY(16 - x, y)] = leds[XY(x, y)]; //left to right
- }
- }
- // copy upper half into lower half
- for (int y = 0; y < 9; y++) {
- for (int x = 0; x < 16; x++) {
- leds[XY(x, 16 - y)] = leds[XY(x, y)];
- }
- }
- /*
- // linear filter
- for (int y = 0; y < 16; y++) {
- for (int x = 0; x < 16; x++) {
- leds[XY(x, y)].fadeLightBy(230 - (y * 12)); // geil!!
- }
- }
- */
- // send current brightness to serial plotter
- uint32_t bright = 0;
- for (uint16_t i = 0; i < NUM_LEDS; i++) {
- bright += leds[i].r;
- bright += leds[i].g;
- bright += leds[i].b;
- }
- EVERY_N_MILLIS(200) Serial.println(bright);
- adjust_gamma();
- FastLED.show();
- //EVERY_N_MILLIS(100) Serial.println(FastLED.getFPS());
- }
- uint16_t XY(uint8_t x, uint8_t y) {
- if (x >= WIDTH) return NUM_LEDS;
- if (y >= HEIGHT) return NUM_LEDS;
- if (y & 1)
- return (y + 1) * WIDTH - 1 - x;
- else
- return y * WIDTH + x;
- }
- void adjust_gamma()
- {
- uint8_t min = 0;
- for (uint16_t i = 0; i < NUM_LEDS; i++)
- {
- leds[i].r = dim8_video(leds[i].r);
- leds[i].g = dim8_video(leds[i].g);
- leds[i].b = dim8_video(leds[i].b);
- if (leds[i].r < min) leds[i].r = min;
- if (leds[i].g < min) leds[i].g = min;
- if (leds[i].b < min) leds[i].b = min;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement