Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- float getSinValue()
- {
- //return ((sin(2 * 3.14 * 0.1 * millis() / 1000) + 1.0 ) / 2.0 );
- //float w = (0.1 * millis() / 1000 ) % 1 ;
- float w = fmod (0.1 * millis() / 1000, 1) ;
- uint16_t w8 = (uint16_t)(w * 65536) ;
- //return ((quadwave8(w8) + 1.0 ) / 2.0 );
- return ( (sin16(w8) + 32768) / 65536.0 );
- }
- int getPixelPosition(int nbPixels, int ledsAround)
- {
- return getSinValue() * (nbPixels - ledsAround) + ledsAround / 2;
- }
- 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);
- }
- 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