// Based on Hugo elias 2d water in c++
// Super Thank: @Sutaburosu (2D water Ripple on reddit)
#include <FastLED.h>
#include "Ripple_Edition.h"
#define NUM_LEDS ((WIDTH) * (HEIGHT))
CRGB leds[NUM_LEDS];
CRGB leds_displayed[324];
// 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, 281, 296, 297, 298, 299, 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 328, 329, 330, 331, 332, 333, 334, 335, 336, 337, 338, 339, 340, 341, 342, 343, 344, 345, 360, 361, 362, 363, 364, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, 392, 393, 394, 395, 396, 397, 398, 399, 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 424, 425, 426, 427, 428, 429, 430, 431, 432, 433, 434, 435, 436, 437, 438, 439, 440, 441, 456, 457, 458, 459, 460, 461, 462, 463, 464, 465, 466, 467, 468, 469, 470, 471, 472, 473, 488, 489, 490, 491, 492, 493, 494, 495, 496, 497, 498, 499, 500, 501, 502, 503, 504, 505, 520, 521, 522, 523, 524, 525, 526, 527, 528, 529, 530, 531, 532, 533, 534, 535, 536, 537, 552, 553, 554, 555, 556, 557, 558, 559, 560, 561, 562, 563, 564, 565, 566, 567, 568, 569, 584, 585, 586, 587, 588, 589, 590, 591, 592, 593, 594, 595, 596, 597, 598, 599, 600, 601, 616, 617, 618, 619, 620, 621, 622, 623, 624, 625, 626, 627, 628, 629, 630, 631, 632, 633, 648, 649, 650, 651, 652, 653, 654, 655, 656, 657, 658, 659, 660, 661, 662, 663, 664, 665, 680, 681, 682, 683, 684, 685, 686, 687, 688, 689, 690, 691, 692, 693, 694, 695, 696, 697, 712, 713, 714, 715, 716, 717, 718, 719, 720, 721, 722, 723, 724, 725, 726, 727, 728, 729, 744, 745, 746, 747, 748, 749, 750, 751, 752, 753, 754, 755, 756, 757, 758, 759, 760, 761,
int DISPLAYED[324] = {231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, 295, 296, 297, 298, 299, 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 327, 328, 329, 330, ' ', 332, 333, 334, 335, 336, 337, 338, 339, 340, 341, 342, ' ', 344, 359, 360, 361, 362, 363, 364, 365, 366, 367, 368, 369, ' ' , 371, ' ' , 373, 374, 375, 376, 391, 392, 393, 394, 395, 396, ' ', 398, 399, ' ', ' ', 402, ' ', ' ', 405, 406, ' ', 408
};
// the water needs 2 arrays each slightly bigger than the screen
uint8_t center_x; // Set the X coordinate for the center
uint8_t center_y; // Set the Y coordinate for the center
int period = 1000;
int period2 = 100;
int period3 = 1200;
unsigned long time_now = 1;
unsigned long time_now2 = 1;
unsigned long time_now3 = 1;
void setup() {
Serial.begin(115200);
// FastLED.addLeds<NEOPIXEL, 2>(leds, NUM_LEDS);
FastLED.addLeds<NEOPIXEL, 2>(leds_displayed, 324);
FastLED.setMaxPowerInVoltsAndMilliamps(5, 1000);
}
void loop() {
// swap the src/dest buffers on each frame
static uint8_t buffer = 0;
uint8_t * const bufA = &water[buffer][0];
buffer = (buffer + 1) % 2;
uint8_t * const bufB = &water[buffer][0];
if (millis() >= time_now2 + period2) {
time_now2 += period2;
center_x = 7; // (25-7)
center_y = 12; //(7-13)
}
if (millis() >= time_now + period) {
time_now += period;
center_y = 0;
center_x = 0;
}
/*
if (millis() >= time_now3 + period3) {
time_now3 += period3;
center_y = random(7, 25);
center_x = random(7, 25);
}
*/
wu_water(bufA, center_x * 257, center_y * 257, beatsin8(170, 64, 255));
process_water(bufA, bufB);
// display the water effect on the LEDs
uint8_t * input = bufB + WATERWIDTH - 1;
static uint16_t pal_offset = 0;
pal_offset += 1;
for (uint8_t y = 0; y < HEIGHT; y++) {
input += 2;
for (uint8_t x = 0; x < WIDTH; x++) {
uint16_t smallIndex = mapToSmallMatrix(x, y);
leds[XY(x, y)] = CHSV(x / 2 * y + 1 / 2 + (*input++ << 1) + pal_offset, 255, *input * 5);
if (smallIndex < SMALL_WIDTH * SMALL_HEIGHT) {
leds_displayed[smallIndex] = leds[DISPLAYED[smallIndex]];
}
}
}
FastLED.show();
}
FPS: 0
Power: 0.00W
Power: 0.00W