ldirko

test subpixel render

Sep 2nd, 2020
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //test subpixel render
  2. //awesome wu_pixel procedure by reddit u/sutaburosu
  3.  
  4. //it was possible to render antialias dot on led matrix
  5. //in this example green have standart move by cells
  6. //but red dot have 256*resolution matrix positions and move very smoother
  7.  
  8. #include "FastLED.h"
  9.  
  10. // Matrix size
  11. #define NUM_ROWS 16
  12. #define NUM_COLS 16
  13. // LEDs pin
  14. #define DATA_PIN 3
  15. // LED brightness
  16. #define BRIGHTNESS 255
  17. #define NUM_LEDS NUM_ROWS * NUM_COLS
  18. // Define the array of leds
  19. CRGB leds[NUM_LEDS];
  20. byte gHue1=0;
  21.  
  22. void setup() {
  23.   FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
  24.   FastLED.setBrightness(BRIGHTNESS);
  25. }
  26.  
  27. void loop() {
  28. EVERY_N_MILLISECONDS(100) {gHue1++;}
  29.  
  30.  
  31. CRGB col = CHSV(0, 255, 255);
  32. uint32_t pos = beatsin16(30, 0, (NUM_COLS-1) * 256);    //x*256
  33. uint32_t pos1 = beatsin16(20, 0, (NUM_ROWS-1) * 256);  //y*256
  34.  
  35. uint32_t pos2 = beatsin8(13, 0, (NUM_COLS-1));    //x*256
  36. uint32_t pos3 = beatsin8(19, 0, (NUM_ROWS-1) );  //y*256
  37.  
  38. wu_pixel(pos, pos1, &col);                           //anialis pixel red
  39.  
  40. leds[XY(pos2, pos3)] = CHSV (100, 255, BRIGHTNESS);  //normal pixel  green
  41.  
  42.            
  43. FastLED.show();
  44. fadeToBlackBy(leds, NUM_LEDS, 5);
  45. blur2d(leds, NUM_COLS, NUM_ROWS, 16);
  46.  
  47. }
  48.  
  49. uint16_t XY (uint8_t x, uint8_t y) {return (y * NUM_COLS + x);}
  50.  
  51. void wu_pixel(uint32_t x, uint32_t y, CRGB * col) {   //x and y have virtual 256 step
  52.   // extract the fractional parts and derive their inverses
  53.   uint8_t xx = x & 0xff, yy = y & 0xff, ix = 255 - xx, iy = 255 - yy;
  54.   // calculate the intensities for each affected pixel
  55.   #define WU_WEIGHT(a,b) ((uint8_t) (((a)*(b)+(a)+(b))>>8))
  56.   uint8_t wu[4] = {WU_WEIGHT(ix, iy), WU_WEIGHT(xx, iy),
  57.                    WU_WEIGHT(ix, yy), WU_WEIGHT(xx, yy)};
  58.   // multiply the intensities by the colour, and saturating-add them to the pixels
  59.   for (uint8_t i = 0; i < 4; i++) {
  60.     uint16_t xy = XY((x >> 8) + (i & 1), (y >> 8) + ((i >> 1) & 1));
  61.     leds[xy].r = qadd8(leds[xy].r, col->r * wu[i] >> 8);
  62.     leds[xy].g = qadd8(leds[xy].g, col->g * wu[i] >> 8);
  63.     leds[xy].b = qadd8(leds[xy].b, col->b * wu[i] >> 8);
  64.   }
  65. }
  66.  
Advertisement
Add Comment
Please, Sign In to add comment