Created
June 21, 2017 15:17
-
-
Save StefanPetrick/c8adc84c92be703a52367090dba56b2b to your computer and use it in GitHub Desktop.
noise_audio2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// as showed on youtube | |
void noise_audio2() { | |
read_audio(); | |
CRGBPalette16 Pal( pit3 ); // the red one | |
y[0] += (bands[4] - 10) * 4; | |
scale_x[0] = 10000 - (bands[0] * 40); | |
scale_y[0] = scale_x[0]; | |
byte layer = 0; | |
for (uint8_t i = 0; i < Width; i++) { | |
uint32_t ioffset = scale_x[layer] * (i - CentreX); | |
for (uint8_t j = 0; j < Height; j++) { | |
uint32_t joffset = scale_y[layer] * (j - CentreY); | |
uint16_t data = inoise16(x[layer] + ioffset, y[layer] + joffset, z[layer]); | |
// results in the range of 11k - 51k | |
// limit results: | |
if (data < 11000) data = 11000; | |
if (data > 51000) data = 51000; | |
// normalize data to a range of 0 - 40000 | |
data = data - 11000; | |
// scale down | |
data = data / 161; | |
noise[layer][i][j] = data; | |
} | |
} | |
// map 1st layer | |
for (uint8_t y = 0; y < Height; y++) { | |
for (uint8_t x = 0; x < Width; x++) { | |
leds[XY(x, y)] = ColorFromPalette( Pal, (millis() / 130) + noise[0][x][y]); | |
} | |
} | |
//2nd layer | |
CRGBPalette16 Pal2( pit4 ); // the blue one | |
y[1] -= (bands[7] - 10) * 4; | |
//z[1] += 9; | |
scale_x[1] = 10000 - (bands[1] * 40); | |
scale_y[1] = scale_x[1]; | |
layer = 1; | |
for (uint8_t i = 0; i < Width; i++) { | |
uint32_t ioffset = scale_x[layer] * (i - CentreX); | |
for (uint8_t j = 0; j < Height; j++) { | |
uint32_t joffset = scale_y[layer] * (j - CentreY); | |
uint16_t data = inoise16(x[layer] + ioffset, y[layer] + joffset, z[layer]); | |
// results in the range of 11k - 51k | |
// limit results: | |
if (data < 11000) data = 11000; | |
if (data > 51000) data = 51000; | |
// normalize data to a range of 0 - 40000 | |
data = data - 11000; | |
// scale down | |
data = data / 161; | |
noise[layer][i][j] = data; | |
} | |
} | |
for (uint8_t y = 0; y < Height; y++) { | |
for (uint8_t x = 0; x < Width; x++) { | |
// map 2nd layer | |
buffer[XY(x, y)] = ColorFromPalette( Pal2, (bands[0] / 4) + noise[1][x][y]); | |
// add both layers | |
leds[XY(x, y)] = buffer[XY(x, y)] + leds[XY(x, y)]; | |
} | |
} | |
adjust_gamma(); | |
FastLED.show(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment