Animated rainbow wave effect (Pride2015), with matrix divided into three segments to compare: - Normal colors (top) - Colors optimized using colorBoost() (middle) - Colors adjusted using gamma correction (bottom)
| 91 | // - Colors optimized using colorBoost() (middle) |
| 92 | // - Colors adjusted using gamma correction (bottom) |
| 93 | void rainbowWave() { |
| 94 | // Use millis() for consistent timing across different devices |
| 95 | // Scale down millis() to get appropriate animation speed |
| 96 | uint16_t time = fl::millis() / 16; // Adjust divisor to control wave speed |
| 97 | uint8_t hueOffset = fl::millis() / 32; // Adjust divisor to control hue rotation speed |
| 98 | |
| 99 | // Iterate through the entire matrix |
| 100 | for (uint16_t y = 0; y < HEIGHT; y++) { |
| 101 | for (uint16_t x = 0; x < WIDTH; x++) { |
| 102 | // Create a wave pattern using sine function based on position and time |
| 103 | uint8_t wave = sin8(time + (x * 8)); |
| 104 | |
| 105 | // Calculate hue based on position and time for rainbow effect |
| 106 | uint8_t hue = hueOffset + (x * 255 / WIDTH); |
| 107 | |
| 108 | // Use wave for both saturation and brightness variation |
| 109 | // uint8_t sat = 255 - (wave / 4); // Subtle saturation variation |
| 110 | uint8_t bri = 128 + (wave / 2); // Brightness wave from 128 to 255 |
| 111 | |
| 112 | // Create the original color using HSV |
| 113 | fl::CRGB original_color = CHSV(hue, satSlider.value(), bri); |
| 114 | |
| 115 | if (y > HEIGHT / 3 * 2) { |
| 116 | // Upper third - original colors |
| 117 | leds[xyMap(x, y)] = original_color; |
| 118 | } else if (y > HEIGHT / 3) { |
| 119 | // Middle third - colors transformed with colorBoost() |
| 120 | fl::EaseType sat_ease = getEaseType(saturationFunction.as_int()); |
| 121 | fl::EaseType lum_ease = getEaseType(luminanceFunction.as_int()); |
| 122 | leds[xyMap(x, y)] = original_color.colorBoost(sat_ease, lum_ease); |
| 123 | } else { |
| 124 | // Lower third - colors transformed using gamma correction |
| 125 | float r = original_color.r / 255.f; |
| 126 | float g = original_color.g / 255.f; |
| 127 | float b = original_color.b / 255.f; |
| 128 | |
| 129 | r = fl::pow(r, 2.0f); |
| 130 | g = fl::pow(g, 2.0f); |
| 131 | b = fl::pow(b, 2.0f); |
| 132 | |
| 133 | r = r * 255.f; |
| 134 | g = g * 255.f; |
| 135 | b = b * 255.f; |
| 136 | |
| 137 | leds[xyMap(x, y)] = fl::CRGB(r, g, b); |
| 138 | } |
| 139 | } |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | void loop() { |
| 144 | rainbowWave(); |
no test coverage detected