FastLED 3.9.15
Loading...
Searching...
No Matches
Wave2d.h
Go to the documentation of this file.
1
10
11// Author: Stefan Petrick
12
13/*
14This demo is best viewed using the FastLED compiler.
15
16Windows/MacOS binaries: https://github.com/FastLED/FastLED/releases
17
18Python
19
20Install: pip install fastled
21Run: fastled <this sketch directory>
22This will compile and preview the sketch in the browser, and enable
23all the UI elements you see below.
24*/
25
26#include "fl/ui/ui.h"
27#include "fl/fx/2d/wave.h"
28#include <Arduino.h>
29#include <FastLED.h>
30
31
32#define HEIGHT 100
33#define WIDTH 100
34#define NUM_LEDS ((WIDTH) * (HEIGHT))
35#define IS_SERPINTINE true
36
38
39fl::UITitle title("Wave2D Demo");
40fl::UIDescription description("Shows the use of the Wave2d effect. By default the wave is cyclical on the x-axis and waves will spill over to the other side.");
41
43fl::UICheckbox xCyclical("X Is Cyclical", true); // The wave keeps on propagating across the x-axis, when true.
44
45fl::UICheckbox autoTrigger("Auto Trigger", true);
46fl::UISlider extraFrames("Extra Frames", 0.0f, 0.0f, 8.0f, 1.0f);
47fl::UISlider slider("Speed", 0.18f, 0.0f, 1.0f);
48fl::UISlider dampening("Dampening", 9.0f, 0.0f, 20.0f, 0.1f);
49fl::UICheckbox halfDuplex("Half Duplex", true);
50fl::UISlider superSample("SuperSampleExponent", 1.f, 0.f, 3.f, 1.f);
51fl::UICheckbox isotropicStencil("Isotropic stencil (rounder ripples)", false);
52
53// Group related UI elements using fl::UIGroup template multi-argument constructor
56
58
60
61
62
64 switch (int(superSample)) {
65 case 0:
67 case 1:
69 case 2:
71 case 3:
73 default:
75 }
76}
77
79 int x = random(WIDTH);
80 int y = random(HEIGHT);
81 waveSim.setf(x, y, 1);
82}
83
84void setup() {
85 Serial.begin(115200);
86 FastLED.addLeds<NEOPIXEL, 2>(leds, NUM_LEDS).setScreenMap(xyMap);
87}
88
89void loop() {
90 // Your code here
91 waveSim.setXCylindrical(xCyclical.value());
92 waveSim.setSpeed(slider);
93 waveSim.setDampening(dampening);
94 waveSim.setHalfDuplex(halfDuplex);
95 waveSim.setSuperSample(getSuperSample());
96 // Apply after setSuperSample() so the user's choice survives the
97 // wrapper's multiplier-based auto-select for the stencil.
98 waveSim.setStencil(isotropicStencil
101 if (button) {
103 }
104
105
107 if (autoTrigger) {
109 }
110 }
111
112 waveSim.update();
113 for (int y = 0; y < HEIGHT; y++) {
114 for (int x = 0; x < WIDTH; x++) {
115 uint8_t value8 = waveSim.getu8(x, y);
116 uint32_t idx = xyMap.mapToIndex(x, y);
117 leds[idx] = fl::CRGB(value8, value8, value8);
118 }
119 }
120 FastLED.show();
121}
fl::XYMap xyMap
#define NUM_LEDS
fl::UIDescription description("Demo of the Animatrix effects. @author of fx is StefanPetrick")
fl::UITitle title("Animartrix")
fl::CRGB leds[NUM_LEDS]
int y
Definition simple.h:93
int x
Definition simple.h:92
#define IS_SERPINTINE
Definition simple.h:49
FL_DISABLE_WARNING_PUSH FL_DISABLE_WARNING_GLOBAL_CONSTRUCTORS CFastLED FastLED
Global LED strip management instance.
fl::UICheckbox autoTrigger("Auto Trigger", true)
fl::UISlider slider("Speed", 0.18f, 0.0f, 1.0f)
void setup()
Definition Wave2d.h:84
fl::UICheckbox halfDuplex("Half Duplex", true)
fl::WaveSimulation2D waveSim(WIDTH, HEIGHT, fl::SuperSample::SUPER_SAMPLE_4X)
fl::UISlider dampening("Dampening", 9.0f, 0.0f, 20.0f, 0.1f)
fl::UIButton button("Trigger")
fl::UISlider extraFrames("Extra Frames", 0.0f, 0.0f, 8.0f, 1.0f)
fl::UICheckbox isotropicStencil("Isotropic stencil (rounder ripples)", false)
fl::UIGroup triggerControls("Trigger Controls", button, autoTrigger, extraFrames)
fl::UISlider superSample("SuperSampleExponent", 1.f, 0.f, 3.f, 1.f)
fl::UICheckbox xCyclical("X Is Cyclical", true)
fl::SuperSample getSuperSample()
Definition Wave2d.h:63
fl::UIGroup waveSimControls("Wave Simulation", slider, dampening, halfDuplex, superSample, isotropicStencil, xCyclical)
void triggerRipple(fl::WaveSimulation2D &waveSim)
Definition Wave2d.h:78
void loop()
Definition Wave2d.h:89
#define WIDTH
#define HEIGHT
fl::UICheckbox isotropicStencil("Isotropic stencil (rounder ripples)", false)
fl::UICheckbox halfDuplex("Half Duplex", false)
fl::WaveSimulation1D waveSim(NUM_LEDS, fl::SuperSample::SUPER_SAMPLE_2X)
fl::UISlider slider("Speed", 0.18f, 0.0f, 1.0f)
fl::UISlider superSample("SuperSampleExponent", 0.f, 0.f, 3.f, 1.f)
fl::UISlider extraFrames("Extra Frames", 1.0f, 0.0f, 8.0f, 1.0f)
fl::UISlider dampening("Dampening", 6.0f, 0.0f, 10.0f, 0.1f)
#define EVERY_N_MILLISECONDS(N)
Alias for EVERY_N_MILLIS.
Definition lib8tion.h:1045
fl::CRGB CRGB
Definition video.h:15
SuperSample
Definition supersample.h:4
fl::UIButton button("Button")
2D wave simulation effect for LED matrices
Representation of an 8-bit RGB pixel (Red, Green, Blue)
Definition crgb.h:38
#define Serial
Definition serial.h:304
Aggregator header for the fl/ui/ family of per-element UI types.