ldirko

simple rotosumer

Jul 14th, 2020 (edited)
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //simle rotozoomer procedure
  2. //fast led rgb matrix 16x16 demo
  3. //Yaroslaw Turbin, 03.11.2020
  4. //https://vk.com/ldirko
  5. //https://www.reddit.com/user/ldirko/
  6.  
  7. //how it's look in emulator: https://wokwi.com/arduino/projects/281176629596652040
  8. //                           https://editor.soulmatelights.com/gallery/457
  9.  
  10. #include "FastLED.h"
  11.  
  12. // Matrix size
  13. #define NUM_ROWS 16
  14. #define NUM_COLS 16
  15. #define NUM_LEDS NUM_ROWS * NUM_COLS
  16.  
  17. // LEDs pin
  18. #define DATA_PIN 3
  19.  
  20. // LED brightness
  21. #define BRIGHTNESS 255
  22.  
  23. // Define the array of leds
  24. CRGB leds[NUM_LEDS];
  25. byte ledsbuff[NUM_LEDS];
  26.  
  27. DEFINE_GRADIENT_PALETTE( temperature_gp ) {
  28.     0,   1, 27,105,
  29.    14,   1, 40,127,
  30.    28,   1, 70,168,
  31.    42,   1, 92,197,
  32.    56,   1,119,221,
  33.    70,   3,130,151,
  34.    84,  23,156,149,
  35.    99,  67,182,112,
  36.   113, 121,201, 52,
  37.   127, 142,203, 11,
  38.   141, 224,223,  1,
  39.   155, 252,187,  2,
  40.   170, 247,147,  1,
  41.   184, 237, 87,  1,
  42.   212, 229, 43,  1,
  43.   226, 220, 15,  1,
  44.   240, 171,  2,  2,
  45.  // 255,  80,  3,  3};
  46.  255,  1,  27,  105};
  47.  
  48. void setup() {
  49.   FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
  50.   FastLED.setBrightness(BRIGHTNESS);
  51. }
  52.  
  53. void loop() {
  54.  plasma ();
  55.  rotozum ();
  56.  FastLED.show();
  57. }
  58.  
  59. void rotozum (){
  60. CRGBPalette16 myPal = temperature_gp;
  61.  
  62. static float a =0;
  63.  
  64. float f= (sin(a/2)+1.1)/1.5;
  65. float kosinus = cos(a)*f;
  66. float sinos= sin(a)*f;
  67.  
  68.   for (int i = 0; i < NUM_COLS; i++) {
  69.     float u1 =i*kosinus;
  70.     float v1 =i*sinos;
  71.   for (int j = 0; j < NUM_ROWS; j++) {
  72.       byte u = abs8(u1-j*sinos)&(NUM_COLS-1); // NUM_COLS and NUM_ROWS must been 2,4,8,16,32,64 resolution only, use and mask for out of bounds
  73.       byte v = abs8(v1+j*kosinus)&(NUM_ROWS-1);   // NUM_COLS and NUM_ROWS must been 2,4,8,16,32,64 resolution only, use and mask for out of bounds
  74.       leds[XY(i,j)] = ColorFromPalette (myPal, ledsbuff[v*NUM_COLS+u], BRIGHTNESS );
  75.      
  76. }                                                              
  77. }
  78. a+=0.1;
  79. }
  80.  
  81. void plasma (){
  82.  
  83. uint16_t ms = millis()/3;  
  84.  
  85.  for (int j = 0; j < NUM_ROWS; j++) {
  86.  int horindexbuff = j*NUM_COLS;
  87.  for (int i = 0; i < NUM_COLS; i++) {
  88.  byte noises =  inoise8 (i * 40, j * 40, ms);  
  89.  ledsbuff[horindexbuff+i] =noises;
  90.    }                                                              
  91.    }
  92. }
  93.  
  94. uint16_t XY (uint8_t x, uint8_t y) { return (y * NUM_COLS + x);}        //simple function to find led number in led matrix,
  95.                                                                     //change this to your routine
  96.                                                                     //or generate XY function for your matrix there:
  97.                                                                     //https://macetech.github.io/FastLED-XY-Map-Generator/
  98.  
Add Comment
Please, Sign In to add comment