FastLED 3.9.15
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
54 Engine(Context *ctx) : mCtx(ctx) {}
56
57 void setTime(fl::u32 t) { currentTime = t; }
58 fl::u32 getTime() { return currentTime.has_value() ? currentTime.value() : fl::millis(); }
59
60 void init(int w, int h) {
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) { this->speed_factor = speed; }
80
81 // Method wrappers that delegate to standalone functions
85
86 void run_default_oscillators(float master_speed = 0.005) {
88 }
89
93
97
98 void get_ready() {
100 }
101
102 void logOutput() {
104 }
105
106 void logFrame() {
108 }
109
110 // Color blend wrappers
111 float subtract(float &x, float &y) { return fl::subtract(x, y); }
112 float multiply(float &x, float &y) { return fl::multiply(x, y); }
113 float add(float &x, float &y) { return fl::add(x, y); }
114 float screen(float &x, float &y) { return fl::screen(x, y); }
115 float colordodge(float &x, float &y) { return fl::colordodge(x, y); }
116 float colorburn(float &x, float &y) { 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) {
124 return mCtx->xyMapFn(x, y, mCtx->xyMapUserData);
125 }
126};
127
128inline Engine::~Engine() FL_NOEXCEPT = default;
129
130inline Context::~Context() FL_NOEXCEPT = default;
131
132// Initialize context with grid dimensions
133inline void init(Context &ctx, int w, int h) {
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) {
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:66
void get_ready(unsigned long &a, unsigned long &b)
FL_DISABLE_WARNING_PUSH U constexpr common_type_t< T, U > min(T a, U b) FL_NOEXCEPT
Definition math.h:71
FASTLED_FORCE_INLINE float render_value(render_parameters &animation)
fl::CRGB CRGB
Definition video.h:15
void init(Context &ctx, int w, int h)
Definition engine.h:133
float colorburn(float &a, float &b)
fl::u32 millis()
Universal millisecond timer - returns milliseconds since system startup.
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)
Definition engine_core.h:27
void setTime(Context &ctx, fl::u32 t)
Definition engine.h:143
void logOutput(unsigned long &b)
void calculate_oscillators(oscillators &timings, modulators &move, fl::u32 current_time, float speed_factor)
Definition engine_core.h:46
Optional< T > optional
Definition optional.h:16
float screen(float &a, float &b)
void run_default_oscillators(oscillators &timings, modulators &move, fl::u32 current_time, float speed_factor, float master_speed=0.005)
Definition engine_core.h:59
FASTLED_FORCE_INLINE rgb rgb_sanity_check(rgb &pixel)
float subtract(float &a, float &b)
void logFrame(unsigned long &c)
float add(float &a, float &b)
float colordodge(float &a, float &b)
float multiply(float &a, float &b)
Base definition for an LED controller.
Definition crgb.hpp:179
#define FASTLED_FORCE_INLINE
#define FL_NOEXCEPT
fl::optional< fl::u32 > currentTime
Definition context.h:35
fl::unique_ptr< Engine > mEngine
Definition context.h:38
float multiply(float &x, float &y)
Definition engine.h:112
float colordodge(float &x, float &y)
Definition engine.h:115
void calculate_oscillators(oscillators &t)
Definition engine.h:82
modulators move
Definition engine.h:31
int num_y
Definition engine.h:24
Engine(Context *ctx)
Definition engine.h:54
void logOutput()
Definition engine.h:102
float add(float &x, float &y)
Definition engine.h:113
FASTLED_FORCE_INLINE rgb rgb_sanity_check(rgb &p)
Definition engine.h:94
render_parameters animation
Definition engine.h:29
FASTLED_FORCE_INLINE void setPixelColorInternal(int x, int y, rgb pixel)
Definition engine.h:118
float colorburn(float &x, float &y)
Definition engine.h:116
float show7
Definition engine.h:47
float subtract(float &x, float &y)
Definition engine.h:111
float screen(float &x, float &y)
Definition engine.h:114
float show1
Definition engine.h:41
void setSpeedFactor(float speed)
Definition engine.h:79
rgb pixel
Definition engine.h:32
bool serpentine
Definition engine.h:27
float show8
Definition engine.h:48
~Engine() FL_NOEXCEPT
fl::vector< fl::vector< float > > distance
Definition engine.h:35
unsigned long c
Definition engine.h:39
float show0
Definition engine.h:50
float show6
Definition engine.h:46
fl::optional< fl::u32 > currentTime
Definition engine.h:52
void get_ready()
Definition engine.h:98
unsigned long a
Definition engine.h:37
fl::vector< fl::vector< float > > polar_theta
Definition engine.h:34
float show3
Definition engine.h:43
float show9
Definition engine.h:49
Context * mCtx
Definition engine.h:20
void setTime(fl::u32 t)
Definition engine.h:57
oscillators timings
Definition engine.h:30
void logFrame()
Definition engine.h:106
float show2
Definition engine.h:42
float radial_filter_radius
Definition engine.h:26
unsigned long b
Definition engine.h:38
void run_default_oscillators(float master_speed=0.005)
Definition engine.h:86
FASTLED_FORCE_INLINE float render_value(render_parameters &anim)
Definition engine.h:90
fl::u32 getTime()
Definition engine.h:58
float speed_factor
Definition engine.h:25
int num_x
Definition engine.h:23
float show4
Definition engine.h:44
void init(int w, int h)
Definition engine.h:60
float show5
Definition engine.h:45
FASTLED_FORCE_INLINE fl::u16 xyMap(fl::u16 x, fl::u16 y)
Definition engine.h:123