FastLED 3.10.8
Loading...
Searching...
No Matches
engine.h
Go to the documentation of this file.
1#pragma once
2
3// Engine: Standalone implementation for Animartrix2 animations.
4// Extracted from animartrix_detail.hpp so it can be forward-declared
5// and included independently by chasing_spirals implementations.
6
11#include "fl/math/math.h"
12#include "fl/stl/optional.h"
13#include "fl/stl/stdint.h"
14#include "fl/stl/vector.h"
15#include "fl/stl/noexcept.h"
16
17namespace fl {
18
19struct Engine {
21
22 // Core ANIMartRIX state (extracted from animartrix_detail::ANIMartRIX)
23 int num_x = 0;
24 int num_y = 0;
25 float speed_factor = 1;
27 bool serpentine = false;
28
33
36
37 unsigned long a = 0;
38 unsigned long b = 0;
39 unsigned long c = 0;
40
41 float show1 = 0.0f;
42 float show2 = 0.0f;
43 float show3 = 0.0f;
44 float show4 = 0.0f;
45 float show5 = 0.0f;
46 float show6 = 0.0f;
47 float show7 = 0.0f;
48 float show8 = 0.0f;
49 float show9 = 0.0f;
50 float show0 = 0.0f;
51
53
56
58 fl::u32 getTime() FL_NO_EXCEPT { return currentTime.has_value() ? currentTime.value() : fl::millis(); }
59
60 void init(int w, int h) FL_NO_EXCEPT {
63 move = modulators();
64 pixel = rgb();
65
66 this->num_x = w;
67 this->num_y = h;
68 this->radial_filter_radius = fl::min(w, h) * 0.65;
70 (num_x / 2) - 0.5,
71 (num_y / 2) - 0.5,
74 num_x,
75 num_y);
76 timings.master_speed = 0.01;
77 }
78
79 void setSpeedFactor(float speed) FL_NO_EXCEPT { this->speed_factor = speed; }
80
81 // Method wrappers that delegate to standalone functions
85
86 void run_default_oscillators(float master_speed = 0.005) FL_NO_EXCEPT {
88 }
89
93
97
100 }
101
104 }
105
108 }
109
110 // Color blend wrappers
111 float subtract(float &x, float &y) FL_NO_EXCEPT { return fl::subtract(x, y); }
112 float multiply(float &x, float &y) FL_NO_EXCEPT { return fl::multiply(x, y); }
113 float add(float &x, float &y) FL_NO_EXCEPT { return fl::add(x, y); }
114 float screen(float &x, float &y) FL_NO_EXCEPT { return fl::screen(x, y); }
115 float colordodge(float &x, float &y) FL_NO_EXCEPT { return fl::colordodge(x, y); }
116 float colorburn(float &x, float &y) FL_NO_EXCEPT { return fl::colorburn(x, y); }
117
119 fl::u16 idx = mCtx->xyMapFn(x, y, mCtx->xyMapUserData);
120 mCtx->leds[idx] = CRGB(pixel.red, pixel.green, pixel.blue);
121 }
122
123 FASTLED_FORCE_INLINE fl::u16 xyMap(fl::u16 x, fl::u16 y) FL_NO_EXCEPT {
124 return mCtx->xyMapFn(x, y, mCtx->xyMapUserData);
125 }
126};
127
128inline Engine::~Engine() FL_NO_EXCEPT = default;
129
130inline Context::~Context() FL_NO_EXCEPT = default;
131
132// Initialize context with grid dimensions
133inline void init(Context &ctx, int w, int h) FL_NO_EXCEPT {
134 if (!ctx.mEngine) {
135 ctx.mEngine = fl::make_unique<Engine>(&ctx);
136 }
137 ctx.num_x = w;
138 ctx.num_y = h;
139 ctx.mEngine->init(w, h);
140}
141
142// Set time for deterministic rendering
143inline void setTime(Context &ctx, fl::u32 t) FL_NO_EXCEPT {
144 ctx.currentTime = t;
145 if (ctx.mEngine) {
146 ctx.mEngine->setTime(t);
147 }
148}
149
150} // namespace fl
uint16_t speed
Definition Noise.ino:72
#define FASTLED_FORCE_INLINE
float multiply(float &a, float &b) FL_NO_EXCEPT
fl::CRGB CRGB
Definition video.h:18
u8 u8 fract8 blur_amount FL_NO_EXCEPT
Definition blur.h:186
FL_DISABLE_WARNING_PUSH U constexpr common_type_t< T, U > min(T a, U b) FL_NO_EXCEPT
Definition math.h:71
void logFrame(unsigned long &c) FL_NO_EXCEPT
void get_ready(unsigned long &a, unsigned long &b) FL_NO_EXCEPT
fl::u32 millis() FL_NO_EXCEPT
Universal millisecond timer - returns milliseconds since system startup.
float colorburn(float &a, float &b) FL_NO_EXCEPT
Optional< T > optional
Definition optional.h:16
void init(Context &ctx, int w, int h) FL_NO_EXCEPT
Definition engine.h:133
void calculate_oscillators(oscillators &timings, modulators &move, fl::u32 current_time, float speed_factor) FL_NO_EXCEPT
Definition engine_core.h:47
void setTime(Context &ctx, fl::u32 t) FL_NO_EXCEPT
Definition engine.h:143
FASTLED_FORCE_INLINE rgb rgb_sanity_check(rgb &pixel) FL_NO_EXCEPT
void run_default_oscillators(oscillators &timings, modulators &move, fl::u32 current_time, float speed_factor, float master_speed=0.005) FL_NO_EXCEPT
Definition engine_core.h:60
void render_polar_lookup_table(float cx, float cy, fl::vector< fl::vector< float > > &polar_theta, fl::vector< fl::vector< float > > &distance, int num_x, int num_y) FL_NO_EXCEPT
Definition engine_core.h:28
float add(float &a, float &b) FL_NO_EXCEPT
float colordodge(float &a, float &b) FL_NO_EXCEPT
FASTLED_FORCE_INLINE float render_value(render_parameters &animation) FL_NO_EXCEPT
float screen(float &a, float &b) FL_NO_EXCEPT
void logOutput(unsigned long &b) FL_NO_EXCEPT
float subtract(float &a, float &b) FL_NO_EXCEPT
Base definition for an LED controller.
Definition crgb.hpp:179
#define FL_NO_EXCEPT
modulators move
Definition engine.h:31
void setTime(fl::u32 t) FL_NO_EXCEPT
Definition engine.h:57
int num_y
Definition engine.h:24
float colorburn(float &x, float &y) FL_NO_EXCEPT
Definition engine.h:116
float colordodge(float &x, float &y) FL_NO_EXCEPT
Definition engine.h:115
void run_default_oscillators(float master_speed=0.005) FL_NO_EXCEPT
Definition engine.h:86
void calculate_oscillators(oscillators &t) FL_NO_EXCEPT
Definition engine.h:82
void logFrame() FL_NO_EXCEPT
Definition engine.h:106
render_parameters animation
Definition engine.h:29
float add(float &x, float &y) FL_NO_EXCEPT
Definition engine.h:113
float show7
Definition engine.h:47
float screen(float &x, float &y) FL_NO_EXCEPT
Definition engine.h:114
float show1
Definition engine.h:41
rgb pixel
Definition engine.h:32
FASTLED_FORCE_INLINE float render_value(render_parameters &anim) FL_NO_EXCEPT
Definition engine.h:90
bool serpentine
Definition engine.h:27
float show8
Definition engine.h:48
fl::vector< fl::vector< float > > distance
Definition engine.h:35
unsigned long c
Definition engine.h:39
float show0
Definition engine.h:50
void logOutput() FL_NO_EXCEPT
Definition engine.h:102
void init(int w, int h) FL_NO_EXCEPT
Definition engine.h:60
FASTLED_FORCE_INLINE void setPixelColorInternal(int x, int y, rgb pixel) FL_NO_EXCEPT
Definition engine.h:118
float show6
Definition engine.h:46
fl::optional< fl::u32 > currentTime
Definition engine.h:52
unsigned long a
Definition engine.h:37
Engine(Context *ctx) FL_NO_EXCEPT
Definition engine.h:54
float multiply(float &x, float &y) FL_NO_EXCEPT
Definition engine.h:112
fl::vector< fl::vector< float > > polar_theta
Definition engine.h:34
float show3
Definition engine.h:43
float subtract(float &x, float &y) FL_NO_EXCEPT
Definition engine.h:111
fl::u32 getTime() FL_NO_EXCEPT
Definition engine.h:58
float show9
Definition engine.h:49
Context * mCtx
Definition engine.h:20
oscillators timings
Definition engine.h:30
void setSpeedFactor(float speed) FL_NO_EXCEPT
Definition engine.h:79
float show2
Definition engine.h:42
float radial_filter_radius
Definition engine.h:26
FASTLED_FORCE_INLINE fl::u16 xyMap(fl::u16 x, fl::u16 y) FL_NO_EXCEPT
Definition engine.h:123
FASTLED_FORCE_INLINE rgb rgb_sanity_check(rgb &p) FL_NO_EXCEPT
Definition engine.h:94
unsigned long b
Definition engine.h:38
void get_ready() FL_NO_EXCEPT
Definition engine.h:98
float speed_factor
Definition engine.h:25
int num_x
Definition engine.h:23
float show4
Definition engine.h:44
float show5
Definition engine.h:45
~Engine() FL_NO_EXCEPT