Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
FastLED simplex noise and colormapping fully modulated by itself
void noise_noise1() {
CRGBPalette16 Pal( pit );
/* here is how the palette looks like:
DEFINE_GRADIENT_PALETTE( pit ) {
0, 3, 3, 3,
64, 13, 13, 255, // blue
128, 3, 3, 3,
192, 255, 130, 3, // orange
255, 3, 3, 3
};
*/
//modulate the position so that it increases/decreases x
//(here based on the top left pixel - it could be any position else)
x[0] = x[0] + (2 * noise[0][0][0]) - 255;
//modulate the position so that it increases/decreases y
//(here based on the top right pixel - it could be any position else)
y[0] = y[0] + (2 * noise[0][15][0]) - 255;
//z just in one direction but with the additional "1" to make sure to never get stuck
//(here based on the down left pixel - it could be any position else)
z[0] += 1 + ((noise[0][0][15]) / 4);
//set the scaling based on left and right pixel of the middle line
scale_x[0] = 8000 + (noise[0][0][7] * 16);
scale_y[0] = 8000 + (noise[0][15][7] * 16);
//calculate new noise data
uint8_t 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]);
if (data < 11000) data = 11000;
if (data > 51000) data = 51000;
data = data - 11000;
data = data / 161;
noise[layer][i][j] = data;
}
}
//map the colors
for (uint8_t y = 0; y < Height; y++) {
for (uint8_t x = 0; x < Width; x++) {
//I will add this overlay CRGB later for more colors
//it´s basically a rainbow mapping with an inverted brightness mask
CRGB overlay = CHSV(noise[0][y][x], 255, noise[0][x][y]);
//here the actual colormapping happens - notice the additional colorshift caused by the down right pixel noise[0][15][15]
leds[XY(x, y)] = ColorFromPalette( Pal, noise[0][15][15] + noise[0][x][y]) + overlay;
}
}
//make it looking nice
adjust_gamma();
//and show it
FastLED.show();
}
// cheap correction with gamma 2.0
void adjust_gamma()
{
for (uint16_t i = 0; i < NUM_LEDS; i++)
{
leds[i].r = dim8_video(leds[i].r);
leds[i].g = dim8_video(leds[i].g);
leds[i].b = dim8_video(leds[i].b);
}
}
//find the right led index within a serpentine matrix
uint16_t XY( uint8_t x, uint8_t y) {
uint16_t i;
if ( y & 0x01) {
uint8_t reverseX = (Width - 1) - x;
i = (y * Width) + reverseX;
} else {
i = (y * Width) + x;
}
return i;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.