Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- uint16_t getSinValue()
- {
- uint16_t w16 = (millis() * 5) % 65536 ;
- return sin16(w16) + 32768 ;
- }
- void testAntiAliasedSinus()
- {
- fillAll(getBackgroundColor(4)) ;
- antiAliasedSinusHelper(ledsExt, NUM_LEDS_EXT) ;
- antiAliasedSinusHelper(ledsMil, NUM_LEDS_MIL) ;
- antiAliasedSinusHelper(ledsInt, NUM_LEDS_INT) ;
- FastLED.show() ;
- }
- void antiAliasedSinusHelper(CRGB* heart, int nbPixels)
- {
- int width = nbPixels / 14 ;
- int pixelGauche = get16PixelPosition(nbPixels / 2, width) ;
- int pixelDroit = nbPixels * 16 - pixelGauche - 16 * width;
- drawFractionalBar(heart, pixelGauche, width) ;
- drawFractionalBar(heart, pixelDroit, width) ;
- }
- int get16PixelPosition(int nbPixels, int width)
- {
- return getSinValue() * (nbPixels * 16 - 16 * width) / 65536;
- }
- void drawFractionalBar(CRGB* heart, int pos16, int width )
- {
- int i = pos16 / 16;
- uint8_t frac = pos16 & 0x0F;
- uint8_t firstpixelbrightness = 255 - (frac * 16);
- uint8_t lastpixelbrightness = 255 - firstpixelbrightness;
- uint8_t bright;
- for( int n = 0; n <= width; n++) {
- if( n == 0 ) {
- // first pixel in the bar
- bright = firstpixelbrightness;
- } else if( n == width ) {
- // last pixel in the bar
- bright = lastpixelbrightness;
- } else {
- // middle pixels
- bright = 255;
- }
- heart[i] += CHSV( 0, 0, bright);
- i++;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement