59 lines
1.6 KiB
C
59 lines
1.6 KiB
C
const int numDrops = 8; // Number of raindrops
|
|
|
|
// Structure to store raindrop positions
|
|
struct Raindrop {
|
|
int x;
|
|
int y;
|
|
};
|
|
|
|
// Array to store raindrops
|
|
Raindrop drops[numDrops];
|
|
|
|
// Function to initialize raindrops within the specified area
|
|
void initRaindrops(int w, int h) {
|
|
for (int i = 0; i < numDrops; i++) {
|
|
//mod for like waterfall from right side
|
|
drops[i].x = random(0, w);
|
|
drops[i].y = random(0, h);
|
|
if ((drops[i].y<(w/2)) && (drops[i].x<(w/2)) ){
|
|
drops[i].x = random(w/2, w);
|
|
drops[i].y = random(w/2, w);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Function to update raindrop positions within the specified area
|
|
void updateRaindrops(int w, int h) {
|
|
for (int i = 0; i < numDrops; i++) {
|
|
//drops[i].y += random(1, 4); // Update y position
|
|
drops[i].y += random(1, 3); // Update y position. 2 more looks like water from pipe
|
|
if (drops[i].y >= h) { // Reset position if it goes out of bounds
|
|
drops[i].x = random(0, w);
|
|
drops[i].y = 0;
|
|
if ((drops[i].y<(w/2)) && (drops[i].x<(w/2)) ){
|
|
drops[i].x = random(w/2, w);
|
|
drops[i].y = random(w/2, w);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Function to draw raindrops within the specified area
|
|
void drawRaindrops(int x, int y) {
|
|
for (int i = 0; i < numDrops; i++) {
|
|
u8g2.drawPixel(drops[i].x+x, drops[i].y+y);
|
|
}
|
|
}
|
|
|
|
// Function to animate rain with keyframes, position, and size
|
|
void animateRain(int keyframes, int x, int y, int w, int h) {
|
|
for (int frame = 0; frame < keyframes; frame++) {
|
|
//u8g2.clearBuffer();
|
|
drawRaindrops(x, y);
|
|
//u8g2.sendBuffer();
|
|
updateRaindrops(w, h);
|
|
//delay(100); // Adjust delay for animation speed
|
|
}
|
|
}
|
|
|