diff options
-rw-r--r-- | FastLED.h | 2 | ||||
-rw-r--r-- | examples/NoisePlayground/NoisePlayground.ino | 36 | ||||
-rw-r--r-- | noise.cpp | 33 |
3 files changed, 47 insertions, 24 deletions
@@ -199,7 +199,7 @@ public: // for debugging, will keep track of time between calls to countFPS, and every // nFrames calls, it will print a summary of FPS info out to the serial port. // If the serial port isn't opened, this function does nothing. - void countFPS(int nFrames=100); + void countFPS(int nFrames=25); CLEDController & operator[](int x); diff --git a/examples/NoisePlayground/NoisePlayground.ino b/examples/NoisePlayground/NoisePlayground.ino index 4327adb9..f3cd7f9e 100644 --- a/examples/NoisePlayground/NoisePlayground.ino +++ b/examples/NoisePlayground/NoisePlayground.ino @@ -1,11 +1,11 @@ #include <FastLED.h> -#define kMatrixWidth 16 -#define kMatrixHeight 16 +#define kMatrixWidth 8 +#define kMatrixHeight 5 #define NUM_LEDS (kMatrixWidth * kMatrixHeight) // Param for different pixel layouts -#define kMatrixSerpentineLayout true +#define kMatrixSerpentineLayout false // led array CRGB leds[kMatrixWidth * kMatrixHeight]; @@ -17,29 +17,33 @@ uint32_t x,y,v_time,hue_time; // have! More octaves will make things slower. // how many octaves to use for the brightness and hue functions -uint8_t octaves=2; -uint8_t hue_octaves=2; +uint8_t octaves=3; +uint8_t hue_octaves=3; // the 'distance' between points on the x and y axis -int xscale=301; -int yscale=301; +int xscale=3311; +int yscale=3311; // the 'distance' between x/y points for the hue noise -int hue_scale=11; +int hue_scale=1; // how fast we move through time & hue noise -int time_speed=101; -int hue_speed=3; +int time_speed=5101; +int hue_speed=1; // adjust these values to move along the x or y axis between frames int x_speed=0; -int y_speed=1; +int y_speed=0; void loop() { // fill the led array 2/16-bit noise values fill_2dnoise16(LEDS.leds(), kMatrixWidth, kMatrixHeight, kMatrixSerpentineLayout, octaves,x,xscale,y,yscale,v_time, hue_octaves,x,hue_scale,y,hue_scale,hue_time, false); + static byte beacon = 0; + beacon++; + leds[0] = CHSV( beacon, 255, 255); + LEDS.show(); LEDS.countFPS(); @@ -48,6 +52,7 @@ void loop() { y += y_speed; v_time += time_speed; hue_time += hue_speed; + // delay(50); } @@ -63,9 +68,12 @@ void setup() { LEDS.addLeds<WS2811,6,GRB>(leds,NUM_LEDS); LEDS.setBrightness(96); - x = (uint32_t)((uint32_t)random16() << 16) | random16(); - y = (uint32_t)((uint32_t)random16() << 16) | random16(); - v_time = (uint32_t)((uint32_t)random16() << 16) | random16(); + // x = (uint32_t)((uint32_t)random16() << 16) | random16(); + // y = (uint32_t)((uint32_t)random16() << 16) | random16(); + // v_time = (uint32_t)((uint32_t)random16() << 16) | random16(); + x = 1; + y = 1; + v_time = 1; hue_time = (uint32_t)((uint32_t)random16() << 16) | random16(); } @@ -191,9 +191,9 @@ static int8_t __attribute__((always_inline)) lerp7by8( int8_t a, int8_t b, fract int16_t inoise16_raw(uint32_t x, uint32_t y, uint32_t z) { // Find the unit cube containing the point - uint8_t X = x>>16; - uint8_t Y = y>>16; - uint8_t Z = z>>16; + uint8_t X = (x>>16)&0xFF; + uint8_t Y = (y>>16)&0xFF; + uint8_t Z = (z>>16)&0xFF; // Hash cube corner coordinates uint8_t A = P(X)+Y; @@ -233,7 +233,12 @@ int16_t inoise16_raw(uint32_t x, uint32_t y, uint32_t z) } uint16_t inoise16(uint32_t x, uint32_t y, uint32_t z) { - return ((inoise16_raw(x,y,z)+19052)*220)>>7; + int32_t ans = inoise16_raw(x,y,z); + ans = ans + 19052L; + uint32_t pan = ans; + return (pan*220L)>>7; + // // return scale16by8(pan,220)<<1; + // return ((inoise16_raw(x,y,z)+19052)*220)>>7; // return scale16by8(inoise16_raw(x,y,z)+19052,220)<<1; } @@ -271,8 +276,12 @@ int16_t inoise16_raw(uint32_t x, uint32_t y) } uint16_t inoise16(uint32_t x, uint32_t y) { - return ((inoise16_raw(x,y)+17308)*242)>>7; - return scale16by8(inoise16_raw(x,y)+17308,242)<<1; + int32_t ans = inoise16_raw(x,y); + ans = ans + 17308L; + uint32_t pan = ans; + return (pan*242L)>>7; + // return (uint32_t)(((int32_t)inoise16_raw(x,y)+(uint32_t)17308)*242)>>7; + // return scale16by8(inoise16_raw(x,y)+17308,242)<<1; } int16_t inoise16_raw(uint32_t x) @@ -301,7 +310,7 @@ int16_t inoise16_raw(uint32_t x) } uint16_t inoise16(uint32_t x) { - return (inoise16_raw(x) + 17308) << 1; + return ((uint32_t)((int32_t)inoise16_raw(x) + 17308L)) << 1; } int8_t inoise8_raw(uint16_t x, uint16_t y, uint16_t z) @@ -565,7 +574,12 @@ void fill_raw_2dnoise16into8(uint8_t *pData, int width, int height, uint8_t octa // for(int i = 0,yy=y; i < height; i++,yy+=scaley) { // uint8_t *pRow = pData + (i * width); // for(int j = 0,xx=x; j < width; j++,xx+=scalex) { - // uint32_t accum = (inoise16(xx,yy,time))>>o; + // // uint32_t accum = (65536/2) + abs(inoise16_raw(xx,yy,time))>>o; + // uint32_t accum = inoise16(xx,yy,time)>>o; + // // if(i==0 && j == 0) { + // // Serial.print(accum); Serial.print("/"); Serial.print(inoise16_raw(xx,yy,time)); Serial.print(" "); + // // } + // // accum += (pRow[j]<<8); // if(accum > 65535) { accum = 65535; } // pRow[j] = accum>>8; @@ -656,10 +670,11 @@ void fill_2dnoise16(CRGB *leds, int width, int height, bool serpentine, memset(V,0,height*width); memset(H,0,height*width); - fill_raw_2dnoise16into8((uint8_t*)V,width,height,octaves,q44(2,0),171,1,x,xscale,y,yscale,time); + fill_raw_2dnoise16into8((uint8_t*)V,width,height,octaves,q44(2,0),128,1,x,xscale,y,yscale,time); // fill_raw_2dnoise8((uint8_t*)V,width,height,hue_octaves,x,xscale,y,yscale,time); fill_raw_2dnoise8((uint8_t*)H,width,height,hue_octaves,hue_x,hue_xscale,hue_y,hue_yscale,hue_time); + int w1 = width-1; int h1 = height-1; for(int i = 0; i < height; i++) { |