Advertisement
Guest User

testSinus

a guest
Oct 21st, 2014
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.70 KB | None | 0 0
  1.  
  2. float getSinValue()
  3. {
  4.   //return ((sin(2 * 3.14 * 0.1 * millis() / 1000) + 1.0 ) / 2.0 );
  5.   //float w = (0.1 * millis() / 1000 ) % 1 ;
  6.   float w = fmod (0.1 * millis() / 1000, 1) ;
  7.   uint16_t w8 = (uint16_t)(w * 65536) ;
  8.   //return ((quadwave8(w8) + 1.0 ) / 2.0 );
  9.   return ( (sin16(w8) + 32768) / 65536.0 );
  10. }
  11.  
  12. int getPixelPosition(int nbPixels, int ledsAround)
  13. {
  14.   return getSinValue() * (nbPixels - ledsAround) + ledsAround / 2;
  15. }
  16.  
  17. void testAntiAliasedSinus()
  18. {
  19.   fillAll(getBackgroundColor(4)) ;
  20.   antiAliasedSinusHelper(ledsExt, NUM_LEDS_EXT) ;
  21.   antiAliasedSinusHelper(ledsMil, NUM_LEDS_MIL) ;
  22.   antiAliasedSinusHelper(ledsInt, NUM_LEDS_INT) ;
  23.   FastLED.show() ;
  24. }
  25.  
  26. void antiAliasedSinusHelper(CRGB* heart, int nbPixels)
  27. {
  28.   int width = nbPixels / 14 ;
  29.   int pixelGauche = get16PixelPosition(nbPixels / 2, width) ;
  30.   int pixelDroit = nbPixels * 16 - pixelGauche - 16 * width;
  31.   drawFractionalBar(heart, pixelGauche, width) ;
  32.   drawFractionalBar(heart, pixelDroit, width) ;
  33. }
  34.  
  35. int get16PixelPosition(int nbPixels, int width)
  36. {
  37.   return getSinValue() * (nbPixels * 16 - 16 * width);
  38. }
  39.  
  40. void drawFractionalBar(CRGB* heart, int pos16, int width )
  41. {
  42.   int i = pos16 / 16;
  43.   uint8_t frac = pos16 & 0x0F;
  44.   uint8_t firstpixelbrightness = 255 - (frac * 16);
  45.   uint8_t lastpixelbrightness  = 255 - firstpixelbrightness;
  46.   uint8_t bright;
  47.   for( int n = 0; n <= width; n++) {
  48.     if( n == 0 ) {
  49.       // first pixel in the bar
  50.       bright = firstpixelbrightness;
  51.     } else if( n == width ) {
  52.       // last pixel in the bar
  53.       bright = lastpixelbrightness;
  54.     } else {
  55.       // middle pixels
  56.       bright = 255;
  57.     }
  58.    
  59.     heart[i] += CHSV( 0, 0, bright);
  60.     i++;
  61.   }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement