22 float cm_led_diameter,
float completion) {
26 float circumference = numLeds * cm_between_leds;
27 float radius = circumference / (2 *
PI);
30 float totalAngle = completion * 2 *
PI;
31 float gapAngle = 2 *
PI - totalAngle;
34 float startAngle = -
PI / 2 + gapAngle / 2.0f;
38 (completion < 1.0f && numLeds > 1) ? (numLeds - 1) : numLeds;
40 for (
int i = 0; i < numLeds; ++i) {
41 float angle = startAngle + (i * totalAngle) / divisor;
42 float x = radius * cos(angle) * 2;
43 float y = radius * sin(angle) * 2;
53#if !FASTLED_ENABLE_JSON
55 *err =
"JSON not enabled";
65 bool ok =
parseJson(jsonStrScreenMap, &doc, err);
70 auto map = doc[
"map"];
71 for (
auto kv : map.as<FLArduinoJson::JsonObject>()) {
72 auto segment = kv.value();
73 auto x = segment[
"x"];
74 auto y = segment[
"y"];
75 auto obj = segment[
"diameter"];
76 float diameter = -1.0f;
77 if (obj.is<
float>()) {
78 float d = obj.as<
float>();
85 for (uint16_t j = 0; j < n; j++) {
88 segmentMaps->
insert(kv.key().c_str(), segment_map);
95 const char *screenMapName,
ScreenMap *screenmap,
97#if !FASTLED_ENABLE_JSON
99 *err =
"JSON not enabled";
104 bool ok =
ParseJson(jsonStrScreenMap, &segmentMaps, err);
108 if (segmentMaps.
size() == 0) {
111 if (segmentMaps.
has(screenMapName)) {
112 *screenmap = segmentMaps[screenMapName];
115 Str _err =
"ScreenMap not found: ";
116 _err.
append(screenMapName);
128#if !FASTLED_ENABLE_JSON
132 auto map = doc[
"map"].to<FLArduinoJson::JsonObject>();
133 for (
auto kv : segmentMaps) {
134 auto segment = map[kv.first].to<FLArduinoJson::JsonObject>();
135 auto x_array = segment[
"x"].to<FLArduinoJson::JsonArray>();
136 auto y_array = segment[
"y"].to<FLArduinoJson::JsonArray>();
137 for (uint16_t i = 0; i < kv.second.getLength(); i++) {
138 const vec2f &
xy = kv.second[i];
142 float diameter = kv.second.getDiameter();
143 if (diameter < 0.0f) {
146 if (diameter > 0.0f) {
147 segment[
"diameter"] = diameter;
155#if !FASTLED_ENABLE_JSON
159 toJson(segmentMaps, &doc);
205 vec2f screen_coords = lut[
x];
206 return screen_coords;
226 float minX = data[0].
x;
227 float maxX = data[0].
x;
228 float minY = data[0].
y;
229 float maxY = data[0].
y;
231 for (uint32_t i = 1; i <
length; i++) {
233 minX =
MIN(minX,
p.x);
234 maxX =
MAX(maxX,
p.x);
235 minY =
MIN(minY,
p.y);
236 maxY =
MAX(maxY,
p.y);
239 return {maxX - minX, maxY - minY};
265 if (
this != &other) {
275 for (uint32_t i = 0; i <
length; i++) {
276 vec2f &curr = data[i];
unsigned int xy(unsigned int x, unsigned int y)
Pair< bool, iterator > insert(const Key &key, const Value &value, InsertResult *result=nullptr)
bool has(const Key &it) const
constexpr size_t size() const
static void toJsonStr(const FixedMap< Str, ScreenMap, 16 > &, Str *jsonBuffer)
ScreenMap & operator=(const ScreenMap &other)
void setDiameter(float diameter)
void set(uint16_t index, const vec2f &p)
vec2f mapToIndex(uint32_t x) const
static ScreenMap Circle(int numLeds, float cm_between_leds=1.5f, float cm_led_diameter=0.5f, float completion=1.0f)
uint32_t getLength() const
static void toJson(const FixedMap< Str, ScreenMap, 16 > &, JsonDocument *doc)
void addOffset(const vec2f &p)
static const vec2f & empty()
LUTXYFLOATPtr mLookUpTable
const vec2f & operator[](uint32_t x) const
static bool ParseJson(const char *jsonStrScreenMap, FixedMap< Str, ScreenMap, 16 > *segmentMaps, Str *err=nullptr)
float getDiameter() const
Str & append(const T &val)
const char * c_str() const
Implements the FastLED namespace macros.
bool parseJson(const char *json, fl::JsonDocument *doc, Str *_error)
void toJson(const fl::JsonDocument &doc, Str *jsonBuffer)
Implements a simple red square effect for 2D LED grids.
static FASTLED_NAMESPACE_BEGIN uint8_t const p[]