handle raindrops as structs

struct-rain
Felix Pankratz 4 days ago
parent 4d22364a89
commit cd601b4bfd

@ -41,15 +41,30 @@ int line_length[PANEL_WIDTH]; // how long a line is for a given x coord
int line_speed[PANEL_WIDTH]; // how fast each line moves int line_speed[PANEL_WIDTH]; // how fast each line moves
unsigned long line_last_moved[PANEL_WIDTH]; unsigned long line_last_moved[PANEL_WIDTH];
typedef struct {
int y;
int length;
int speed;
unsigned long last_moved;
} Raindrop;
Raindrop raindrops[PANEL_WIDTH];
void setup(){ void setup(){
Serial.begin(BAUD_RATE); Serial.begin(BAUD_RATE);
pinMode(ONBOARD_LED, OUTPUT); pinMode(ONBOARD_LED, OUTPUT);
for (int i = 0; i<PANEL_WIDTH; i++) { for (int i = 0; i<PANEL_WIDTH; i++) {
line_pos[i] = 0 - random(24); raindrops[i].y = 0 - random(24);
line_length[i] = random(20, 28); raindrops[i].length = random(20, 28);
line_speed[i] = random(25, 100); raindrops[i].speed = random(25, 100);
line_last_moved[i] = millis(); raindrops[i].last_moved = millis();
//raindrops[i] = rd;
//line_pos[i] = 0 - random(24);
//line_length[i] = random(20, 28);
//line_speed[i] = random(25, 100);
//line_last_moved[i] = millis();
} }
// redefine pins if required // redefine pins if required
HUB75_I2S_CFG::i2s_pins _pins={R1, G1, BL1, R2, G2, BL2, CH_A, CH_B, CH_C, CH_D, CH_E, LAT, OE, CLK}; HUB75_I2S_CFG::i2s_pins _pins={R1, G1, BL1, R2, G2, BL2, CH_A, CH_B, CH_C, CH_D, CH_E, LAT, OE, CLK};
@ -72,36 +87,32 @@ void setup(){
} }
void loop() { void loop() {
matrix ->flipDMABuffer(); matrix ->flipDMABuffer();
matrix->clearScreen(); matrix->clearScreen();
delay(25); delay(25);
//matrix ->drawBitmap(0, 0, overlay, 64, 32, matrix->color565(64, 0, 0)); //matrix ->drawBitmap(0, 0, overlay, 64, 32, matrix->color565(64, 0, 0));
unsigned long timestamp = millis(); unsigned long timestamp = millis();
for (int x = 0; x < PANEL_WIDTH; x++) { for (int x = 0; x < PANEL_WIDTH; x++) {
if ((timestamp - line_last_moved[x]) > line_speed[x]) { if ((timestamp - raindrops[x].last_moved) > raindrops[x].speed) {
// step down a pixel // step down a pixel
line_pos[x]++; raindrops[x].y++;
line_last_moved[x] = timestamp; raindrops[x].last_moved = timestamp;
} }
if (line_pos[x] > PANEL_HEIGHT) { if (raindrops[x].y > PANEL_HEIGHT) {
line_pos[x] = 0; raindrops[x].y = 0;
} }
if (line_pos[x] >= 0) { if (raindrops[x].y >= 0) {
//draw our pixel //draw our pixel
matrix->drawPixel(x, line_pos[x], matrix->color565(128, 255, 128)); matrix->drawPixel(x, raindrops[x].y, matrix->color565(128, 255, 128));
// draw our trail // draw our trail
for (int trail_offset = 1; trail_offset < line_length[x]; trail_offset++) { for (int trail_offset = 1; trail_offset < raindrops[x].length; trail_offset++) {
//if (random(10) > 8) { int trail_y = raindrops[x].y - trail_offset;
// trail_offset++;
//}
int trail_y = line_pos[x] - trail_offset;
if (trail_y >= 0) { if (trail_y >= 0) {
int pixel_num = (trail_y * PANEL_WIDTH) + x; int pixel_num = (trail_y * PANEL_WIDTH) + x;
if (overlay[ pixel_num / 8 ] & (1 << (7 - (pixel_num % 8)) )) { if (overlay[ pixel_num / 8 ] & (1 << (7 - (pixel_num % 8)) )) {
matrix->drawPixel(x, trail_y, matrix->color565(128, 255, 128)); matrix->drawPixel(x, trail_y, matrix->color565(128, 255, 128));
} else { } else {
matrix->drawPixel(x, trail_y, matrix->color565(0, (255 / line_length[x]) * (line_length[x] - trail_offset), 0)); matrix->drawPixel(x, trail_y, matrix->color565(0, (255 / raindrops[x].length) * (raindrops[x].length - trail_offset), 0));
} }
} else { } else {
int pixel_num = ((PANEL_HEIGHT + trail_y) * PANEL_WIDTH) + x; int pixel_num = ((PANEL_HEIGHT + trail_y) * PANEL_WIDTH) + x;
@ -109,7 +120,7 @@ void loop() {
if (overlay[ pixel_num / 8 ] & (1 << (7 - (pixel_num % 8)) )) { if (overlay[ pixel_num / 8 ] & (1 << (7 - (pixel_num % 8)) )) {
matrix->drawPixel(x, PANEL_HEIGHT + trail_y, matrix->color565(128, 255, 128)); matrix->drawPixel(x, PANEL_HEIGHT + trail_y, matrix->color565(128, 255, 128));
} else { } else {
matrix->drawPixel(x, PANEL_HEIGHT + trail_y, matrix->color565(0,(255 / line_length[x]) * (line_length[x] - trail_offset), 0)); matrix->drawPixel(x, PANEL_HEIGHT + trail_y, matrix->color565(0,(255 / raindrops[x].length) * (raindrops[x].length - trail_offset), 0));
} }
} else { } else {
break; break;
@ -118,6 +129,5 @@ void loop() {
} }
} }
} }
//delay(25);
} }

Loading…
Cancel
Save