FastLED 3.9.15
Loading...
Searching...
No Matches
corkscrew.h
Go to the documentation of this file.
1#pragma once
2
34
35#include "fl/allocator.h"
36#include "fl/geometry.h"
37#include "fl/math_macros.h"
38#include "fl/tile2x2.h"
39#include "fl/vector.h"
40
41namespace fl {
42
49 float totalHeight = 23.25; // Total height of the corkscrew in centimeters
50 // for 144 densly wrapped up over 19 turns
51 float totalAngle = 19.f * 2 * PI; // Default to 19 turns
52 float offsetCircumference = 0; // Optional offset for gap accounting
53 uint16_t numLeds = 144; // Default to dense 144 leds.
54 bool invert = false; // If true, reverse the mapping order
55 CorkscrewInput() = default;
56 CorkscrewInput(float height, float total_angle, float offset = 0,
57 uint16_t leds = 144, bool invertMapping = false)
58 : totalHeight(height), totalAngle(total_angle),
59 offsetCircumference(offset), numLeds(leds), invert(invertMapping) {}
60};
61
63 uint16_t width = 0; // Width of cylindrical map (circumference of one turn)
64 uint16_t height = 0; // Height of cylindrical map (total vertical segments)
66 mapping; // Full precision mapping from corkscrew to cylindrical
67 CorkscrewOutput() = default;
68
69 class iterator {
70 public:
72 using difference_type = int32_t;
73 using pointer = vec2f*;
74 using reference = vec2f&;
75
76 iterator(CorkscrewOutput* owner, size_t position)
77 : owner_(owner), position_(position) {}
78
79 vec2f& operator*() const {
80 return owner_->mapping[position_];
81 }
82
84 ++position_;
85 return *this;
86 }
87
89 iterator temp = *this;
90 ++position_;
91 return temp;
92 }
93
94 bool operator==(const iterator& other) const {
95 return position_ == other.position_;
96 }
97
98 bool operator!=(const iterator& other) const {
99 return position_ != other.position_;
100 }
101
102 private:
104 size_t position_;
105 };
106
108 return iterator(this, 0);
109 }
110
112 return iterator(this, mapping.size());
113 }
114 fl::Tile2x2_u8 at(int16_t x, int16_t y) const;
115};
116
118 public:
122
123 Corkscrew(const Input &input);
124 Corkscrew(const Corkscrew &) = default;
125
126 vec2f at(uint16_t i) const;
127 // This is a splatted pixel. This is will look way better than
128 // using at(), because it uses 2x2 neighboor sampling.
129 Tile2x2_u8 at_splat(uint16_t i) const;
130 size_t size() const;
131
133 return mOutput.begin();
134 }
135
137 return mOutput.end();
138 }
139
141
142 static CorkscrewOutput generateMap(const Input &input);
143
145 return mOutput;
146 }
147
148 const Output& access() const {
149 return mOutput;
150 }
151
152 private:
153 Input mInput; // The input parameters defining the corkscrew
154 CorkscrewOutput mOutput; // The resulting cylindrical mapping
155};
156
157} // namespace fl
CRGB leds[NUM_LEDS]
Definition Apa102.ino:11
int y
Definition Audio.ino:72
int x
Definition Audio.ino:71
Corkscrew(const Corkscrew &)=default
size_t size() const
iterator end()
Definition corkscrew.h:136
iterator begin()
Definition corkscrew.h:132
CorkscrewOutput mOutput
Definition corkscrew.h:154
CorkscrewOutput::iterator iterator
Definition corkscrew.h:121
vec2f at(uint16_t i) const
CorkscrewOutput Output
Definition corkscrew.h:120
Tile2x2_u8 at_splat(uint16_t i) const
CorkscrewInput Input
Definition corkscrew.h:119
static CorkscrewOutput generateMap(const Input &input)
For testing.
Corkscrew(const Input &input)
const Output & access() const
Definition corkscrew.h:148
Output & access()
Definition corkscrew.h:144
bool operator!=(const iterator &other) const
Definition corkscrew.h:98
bool operator==(const iterator &other) const
Definition corkscrew.h:94
vec2f & operator*() const
Definition corkscrew.h:79
CorkscrewOutput * owner_
Definition corkscrew.h:103
iterator(CorkscrewOutput *owner, size_t position)
Definition corkscrew.h:76
UISlider offset("Offset", 0.0f, 0.0f, 1.0f, 0.01f)
#define PI
Definition math_macros.h:63
vec2< float > vec2f
Definition geometry.h:318
HeapVector< T, Allocator > vector
Definition vector.h:1074
Implements a simple red square effect for 2D LED grids.
Definition crgb.h:16
CorkscrewInput()=default
float offsetCircumference
Definition corkscrew.h:52
CorkscrewInput(float height, float total_angle, float offset=0, uint16_t leds=144, bool invertMapping=false)
Definition corkscrew.h:56
Generates a mapping from corkscrew to cylindrical coordinates.
Definition corkscrew.h:48
fl::vector< fl::vec2f, fl::allocator_psram< fl::vec2f > > mapping
Definition corkscrew.h:66
fl::Tile2x2_u8 at(int16_t x, int16_t y) const
CorkscrewOutput()=default