FastLED 3.9.15
Loading...
Searching...
No Matches
xypath_renderer.cpp
Go to the documentation of this file.
1
2
3#include <math.h>
4
5#include "fl/assert.h"
6#include "fl/warn.h"
7#include "fl/xypath.h"
9
10namespace fl {
11
12namespace {
13uint8_t to_uint8(float f) {
14 // convert to [0..255] range
15 uint8_t i = static_cast<uint8_t>(f * 255.0f + .5f);
16 return MIN(i, 255);
17}
18} // namespace
19
23
25 vec2f xy = mPath->compute(alpha);
26 vec2f out = tx.transform(xy);
27 out = mGridTransform.transform(out);
28 return out;
29}
30
32 // 1) continuous point, in “pixel‐centers” coordinates [0.5 … W–0.5]
33 if (!mDrawBoundsSet) {
34 FASTLED_WARN("XYPathRenderer::at_subpixel: draw bounds not set");
35 return Tile2x2_u8();
36 }
37 vec2f xy = at(alpha);
38
39 // 2) shift back so whole‐pixels go 0…W–1, 0…H–1
40 float x = xy.x - 0.5f;
41 float y = xy.y - 0.5f;
42
43 // 3) integer cell indices
44 int cx = static_cast<int>(floorf(x));
45 int cy = static_cast<int>(floorf(y));
46
47 // 4) fractional offsets in [0..1)
48 float fx = x - cx;
49 float fy = y - cy;
50
51 // 5) bilinear weights
52 float w_ll = (1 - fx) * (1 - fy); // lower‑left
53 float w_lr = fx * (1 - fy); // lower‑right
54 float w_ul = (1 - fx) * fy; // upper‑left
55 float w_ur = fx * fy; // upper‑right
56
57 // 6) build Tile2x2_u8 anchored at (cx,cy)
58 Tile2x2_u8 out(vec2<int>(cx, cy));
59 out.lower_left() = to_uint8(w_ll);
60 out.lower_right() = to_uint8(w_lr);
61 out.upper_left() = to_uint8(w_ul);
62 out.upper_right() = to_uint8(w_ur);
63
64 return out;
65}
66
67} // namespace fl
uint32_t x[NUM_LAYERS]
Definition Fire2023.ino:82
uint32_t y[NUM_LAYERS]
Definition Fire2023.ino:83
unsigned int xy(unsigned int x, unsigned int y)
uint8_t & lower_right()
Definition tile2x2.h:40
uint8_t & upper_left()
Definition tile2x2.h:39
uint8_t & upper_right()
Definition tile2x2.h:41
uint8_t & lower_left()
Definition tile2x2.h:38
TransformFloat & transform()
Definition xypath.cpp:110
Tile2x2_u8 at_subpixel(float alpha)
XYPathGeneratorPtr mPath
TransformFloat mTransform
XYPathRenderer(XYPathGeneratorPtr path, TransformFloat transform=TransformFloat())
TransformFloat mGridTransform
vec2f compute_float(float alpha, const TransformFloat &tx)
vec2f at(float alpha)
Definition xypath.cpp:123
#define MIN(a, b)
Definition math_macros.h:15
vec2< float > vec2f
Definition geometry.h:151
Implements a simple red square effect for 2D LED grids.
Definition crgb.h:16
vec2f transform(const vec2f &xy) const
Definition transform.h:107
#define FASTLED_WARN
Definition warn.h:7