FastLED
3.9.15
Loading...
Searching...
No Matches
splat.cpp
Go to the documentation of this file.
1
2
#include "
fl/tile2x2.h
"
3
#include "
fl/splat.h
"
4
#include "
fl/math.h
"
5
6
namespace
fl
{
7
8
static
uint8_t
to_uint8
(
float
f) {
9
// convert to [0..255] range
10
uint8_t i =
static_cast<
uint8_t
>
(f * 255.0f + .5f);
11
return
MIN
(i, 255);
12
}
13
14
Tile2x2_u8
splat
(
vec2f
xy
) {
15
// 1) collect values.
16
float
x
=
xy
.x;
17
float
y
=
xy
.y;
18
19
// 2) integer cell indices
20
int16_t cx =
static_cast<
int16_t
>
(floorf(
x
));
21
int16_t cy =
static_cast<
int16_t
>
(floorf(
y
));
22
23
// 3) fractional offsets in [0..1)
24
float
fx =
x
- cx;
25
float
fy =
y
- cy;
26
27
// 4) bilinear weights
28
float
w_ll = (1 - fx) * (1 - fy);
// lower‑left
29
float
w_lr = fx * (1 - fy);
// lower‑right
30
float
w_ul = (1 - fx) * fy;
// upper‑left
31
float
w_ur = fx * fy;
// upper‑right
32
33
// 5) build Tile2x2_u8 anchored at (cx,cy)
34
Tile2x2_u8
out(
vec2<int16_t>
(cx, cy));
35
out.
lower_left
() =
to_uint8
(w_ll);
36
out.
lower_right
() =
to_uint8
(w_lr);
37
out.
upper_left
() =
to_uint8
(w_ul);
38
out.
upper_right
() =
to_uint8
(w_ur);
39
40
return
out;
41
}
42
43
}
// namespace
y
int y
Definition
Audio.ino:72
x
int x
Definition
Audio.ino:71
xy
unsigned int xy(unsigned int x, unsigned int y)
Definition
PJRCSpectrumAnalyzer.ino:79
fl::Tile2x2_u8::lower_right
uint8_t & lower_right()
Definition
tile2x2.h:40
fl::Tile2x2_u8::upper_left
uint8_t & upper_left()
Definition
tile2x2.h:39
fl::Tile2x2_u8::upper_right
uint8_t & upper_right()
Definition
tile2x2.h:41
fl::Tile2x2_u8::lower_left
uint8_t & lower_left()
Definition
tile2x2.h:38
fl::Tile2x2_u8
Definition
tile2x2.h:20
math.h
MIN
#define MIN(a, b)
Definition
math_macros.h:15
fl::splat
Tile2x2_u8 splat(vec2f xy)
"Splat" as in "splat pixel rendering" takes a pixel value in float x,y coordinates and "splats" it in...
Definition
splat.cpp:14
fl::vec2f
vec2< float > vec2f
Definition
geometry.h:318
fl::to_uint8
static uint8_t to_uint8(float f)
Definition
splat.cpp:8
fl
Implements a simple red square effect for 2D LED grids.
Definition
crgb.h:16
splat.h
fl::vec2
Definition
geometry.h:175
tile2x2.h
fl
splat.cpp
Generated on Thu Jun 5 2025 04:29:38 for FastLED by
1.13.2