ldirko

16x16 metaballs with pallette

Sep 2nd, 2020 (edited)
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. //Metaballs
  2. //16x16 rgb led matrix demo
  3. //Yaroslaw Turbin 02.09.2020
  4. //https://vk.com/ldirko
  5. //https://www.reddit.com/user/ldirko/
  6.  
  7. // update for https://pastebin.com/DdKyN5s2
  8. // with HeatColors_p pallete looks pretty good now
  9.  
  10. #include "FastLED.h"
  11.  
  12. // Matrix size
  13. #define NUM_ROWS 16
  14. #define NUM_COLS 16
  15. // LEDs pin
  16. #define DATA_PIN 3
  17. // LED brightness
  18. #define BRIGHTNESS 255
  19. #define NUM_LEDS NUM_ROWS * NUM_COLS
  20. // Define the array of leds
  21. CRGB leds[NUM_LEDS];
  22.  
  23. void setup() {
  24. FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
  25. FastLED.setBrightness(BRIGHTNESS);
  26. }
  27.  
  28. void loop() {
  29.  
  30. uint8_t bx1 = beatsin8(15, 0, NUM_COLS - 1, 0, 0);
  31. uint8_t by1 = beatsin8(18, 0, NUM_ROWS - 1, 0, 0);
  32. uint8_t bx2 = beatsin8(28, 0, NUM_COLS - 1, 0, 32);
  33. uint8_t by2 = beatsin8(23, 0, NUM_ROWS - 1, 0, 32);
  34. uint8_t bx3 = beatsin8(30, 0, NUM_COLS - 1, 0, 64);
  35. uint8_t by3 = beatsin8(24, 0, NUM_ROWS - 1, 0, 64);
  36. uint8_t bx4 = beatsin8(17, 0, NUM_COLS - 1, 0, 128);
  37. uint8_t by4 = beatsin8(25, 0, NUM_ROWS - 1, 0, 128);
  38. uint8_t bx5 = beatsin8(19, 0, NUM_COLS - 1, 0, 170);
  39. uint8_t by5 = beatsin8(21, 0, NUM_ROWS - 1, 0, 170);
  40.  
  41. for (int i = 0; i < NUM_COLS; i++) {
  42. for (int j = 0; j < NUM_ROWS; j++) {
  43.  
  44. byte sum = dist(i, j, bx1, by1);
  45. sum = qadd8(sum, dist(i, j, bx2, by2));
  46. sum = qadd8(sum, dist(i, j, bx3, by3));
  47. sum = qadd8(sum, dist(i, j, bx4, by4));
  48. sum = qadd8(sum, dist(i, j, bx5, by5));
  49.  
  50. leds[XY (i, j)] = ColorFromPalette(HeatColors_p , sum+220, BRIGHTNESS);
  51. }}
  52.  
  53. blur2d(leds,NUM_COLS, NUM_ROWS, 32 );
  54. FastLED.show();
  55.  
  56. } //loop
  57.  
  58. byte dist (uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2) {
  59. int a = y2-y1;
  60. int b = x2-x1;
  61. a *= a;
  62. b *= b;
  63. byte dist = 220/ sqrt16(a+b);
  64. return dist;
  65. }
  66.  
  67. uint16_t XY (uint8_t x, uint8_t y) {return (y * NUM_COLS + x);}
Add Comment
Please, Sign In to add comment