Skip to content

Commit

Permalink
use config variable for matrix size
Browse files Browse the repository at this point in the history
  • Loading branch information
Christof Weigl committed Apr 25, 2021
1 parent a35b416 commit ca285d1
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions src/frames/visuals/noise.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ DEFINE_GRADIENT_PALETTE(pit) {
using std::cout; using std::endl;

// matrix size
uint8_t Width = 16;
uint8_t Height = 16;
uint8_t CentreX = (Width / 2) - 1;
uint8_t CentreY = (Height / 2) - 1;
uint8_t CentreX = (MATRIX_TILE_WIDTH / 2) - 1;
uint8_t CentreY = (MATRIX_TILE_HEIGHT / 2) - 1;

#define NUM_LAYERS 1
uint32_t x[NUM_LAYERS];
Expand Down Expand Up @@ -63,21 +61,21 @@ void Noise::make_some_noise()
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][Width-1][0]) - 255;
y[0] = y[0] + (2 * noise[0][MATRIX_TILE_WIDTH-1][0]) - 255;
//z just in one direction but with the additional "1" to make sure to never get stuck
//in case the movement is stopped by a crazy parameter (noise data) combination
//(here based on the down left pixel - it could be any position else)
z[0] += 1 + ((noise[0][0][Height-1]) / 4);
z[0] += 1 + ((noise[0][0][MATRIX_TILE_HEIGHT-1]) / 4);
//set the scaling based on left and right pixel of the middle line
//here you can set the range of the zoom in both dimensions
scale_x[0] = 8000 + (noise[0][0][CentreY] * 16);
scale_y[0] = 8000 + (noise[0][Width-1][CentreY] * 16);
scale_y[0] = 8000 + (noise[0][MATRIX_TILE_WIDTH-1][CentreY] * 16);

//calculate the noise data
uint8_t layer = 0;
for (uint8_t i = 0; i < Width; i++) {
for (uint8_t i = 0; i < MATRIX_TILE_WIDTH; i++) {
uint32_t ioffset = scale_x[layer] * (i - CentreX);
for (uint8_t j = 0; j < Height; j++) {
for (uint8_t j = 0; j < MATRIX_TILE_HEIGHT; j++) {
uint32_t joffset = scale_y[layer] * (j - CentreY);
uint16_t data = inoise16(x[layer] + ioffset, y[layer] + joffset, z[layer]);
// limit the 16 bit results to the interesting range
Expand All @@ -93,13 +91,13 @@ void Noise::make_some_noise()
}

//map the colors
for (uint8_t y = 0; y < Height; y++) {
for (uint8_t x = 0; x < Width; x++) {
for (uint8_t y = 0; y < MATRIX_TILE_HEIGHT; y++) {
for (uint8_t x = 0; x < MATRIX_TILE_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 - note the additional colorshift caused by the down right pixel noise[0][15][15]
matrixleds[XY(x, y)] = ColorFromPalette( Pal, noise[0][Width-1][Height-1] + noise[0][x][y]) + overlay;
matrixleds[XY(x, y)] = ColorFromPalette( Pal, noise[0][MATRIX_TILE_WIDTH-1][MATRIX_TILE_HEIGHT-1] + noise[0][x][y]) + overlay;
}
}

Expand Down

0 comments on commit ca285d1

Please sign in to comment.