ldirko

fast led plasma with perlin noise

Jun 10th, 2020 (edited)
754
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Perlin noise plasma procedure
  2. //16x16 rgb led matrix demo
  3. //Yaroslaw Turbin
  4. //https://vk.com/ldirko
  5. //https://www.reddit.com/user/ldirko/
  6. //https://www.reddit.com/r/FastLED/comments/h09406/simple_plasma_effect/
  7.  
  8. #include "FastLED.h"
  9.  
  10. // Matrix size
  11. #define NUM_ROWS 16
  12. #define NUM_COLS 16
  13. #define NUM_LEDS NUM_ROWS * NUM_COLS
  14.  
  15. // LEDs pin
  16. #define DATA_PIN 3
  17.  
  18. // LED brightness
  19. #define BRIGHTNESS 255
  20.  
  21.  
  22. // Define the array of leds
  23. CRGB leds[NUM_LEDS];
  24.  
  25. void setup() {
  26.   FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
  27.   FastLED.setBrightness(BRIGHTNESS);
  28. }
  29.  
  30.  
  31. void loop() {
  32.    uint16_t ms = millis();
  33.   for (int i = 0; i < NUM_COLS; i++) {
  34.     for (int j = 0; j < NUM_ROWS; j++) {
  35.       uint8_t index = inoise8(i * 41, j * 41, ms / 4);  // x and y not change, only change z value with time increment for nice plasma looking noise
  36.    leds[XY (i, j)] = CHSV((index + ms / 200) % 255, 255, BRIGHTNESS); // within palette
  37.      // leds[XY (i, j)] = ColorFromPalette (RainbowColors_p, (index + ms / 200) % 255, BRIGHTNESS ); // with palette
  38.  
  39.     }
  40.   }
  41.  
  42. FastLED.delay(1);
  43.   }
  44.  
  45. uint8_t XY (uint8_t x, uint8_t y) { return (y * NUM_COLS + x);}     //simple function to find led number in led matrix,
  46.                                                                     //change this to your routine
  47.                                                                     //or generate XY function for your matrix there:
  48.                                                                     //https://macetech.github.io/FastLED-XY-Map-Generator/
Add Comment
Please, Sign In to add comment