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/pair.h"
39#include "fl/tile2x2.h"
40#include "fl/vector.h"
41
42namespace fl {
43
50 float totalLength = 100; // Total length of the corkscrew in centimeters,
51 // set to dense 144 strips.
52 float totalHeight = 23.25; // Total height of the corkscrew in centimeters
53 // for 144 densly wrapped up over 19 turns
54 float totalTurns = 19.f; // Default to 19 turns
55 float offsetCircumference = 0; // Optional offset for gap accounting
56 uint16_t numLeds = 144; // Default to dense 144 leds.
57 bool invert = false; // If true, reverse the mapping order
58 CorkscrewInput() = default;
59 CorkscrewInput(float total_length, float height, float total_turns,
60 uint16_t leds, float offset = 0,
61 bool invertMapping = false)
62 : totalLength(total_length), totalHeight(height),
64 invert(invertMapping) {}
65};
66
68 uint16_t width = 0; // Width of cylindrical map (circumference of one turn)
69 uint16_t height = 0; // Height of cylindrical map (total vertical segments)
71 mapping; // Full precision mapping from corkscrew to cylindrical
72 CorkscrewState() = default;
73
74 class iterator {
75 public:
77 using difference_type = int32_t;
78 using pointer = vec2f *;
79 using reference = vec2f &;
80
81 iterator(CorkscrewState *owner, size_t position)
82 : owner_(owner), position_(position) {}
83
84 vec2f &operator*() const { return owner_->mapping[position_]; }
85
87 ++position_;
88 return *this;
89 }
90
92 iterator temp = *this;
93 ++position_;
94 return temp;
95 }
96
98 --position_;
99 return *this;
100 }
101
103 iterator temp = *this;
104 --position_;
105 return temp;
106 }
107
108 bool operator==(const iterator &other) const {
109 return position_ == other.position_;
110 }
111
112 bool operator!=(const iterator &other) const {
113 return position_ != other.position_;
114 }
115
116 difference_type operator-(const iterator &other) const {
117 return static_cast<difference_type>(position_) -
118 static_cast<difference_type>(other.position_);
119 }
120
121 private:
123 size_t position_;
124 };
125
126 iterator begin() { return iterator(this, 0); }
127
128 iterator end() { return iterator(this, mapping.size()); }
129};
130
131// Maps a Corkscrew defined by the input to a cylindrical mapping for rendering
132// a densly wrapped LED corkscrew.
134 public:
138
139 Corkscrew(const Input &input);
140 Corkscrew(const Corkscrew &) = default;
141 Corkscrew(Corkscrew &&) = default;
142
143 vec2f at_exact(uint16_t i) const;
144
145 // This is the future api.
146 Tile2x2_u8_wrap at_wrap(float i) const;
147
148 size_t size() const;
149
150 iterator begin() { return mState.begin(); }
151
152 iterator end() { return mState.end(); }
153
155
156 static State generateState(const Input &input);
157
158 State &access() { return mState; }
159
160 const State &access() const { return mState; }
161
162 int16_t cylinder_width() const { return mState.width; }
163 int16_t cylinder_height() const { return mState.height; }
164
165 private:
166 // For internal use. Splats the pixel on the surface which
167 // extends past the width. This extended Tile2x2 is designed
168 // to be wrapped around with a Tile2x2_u8_wrap.
169 Tile2x2_u8 at_splat_extrapolate(float i) const;
170
171 Input mInput; // The input parameters defining the corkscrew
172 State mState; // The resulting cylindrical mapping
173};
174
175} // namespace fl
CRGB leds[NUM_LEDS]
Definition Apa102.ino:11
const State & access() const
Definition corkscrew.h:160
Corkscrew(const Corkscrew &)=default
size_t size() const
CorkscrewState State
Definition corkscrew.h:136
int16_t cylinder_width() const
Definition corkscrew.h:162
Tile2x2_u8 at_splat_extrapolate(float i) const
Definition corkscrew.cpp:85
iterator end()
Definition corkscrew.h:152
iterator begin()
Definition corkscrew.h:150
int16_t cylinder_height() const
Definition corkscrew.h:163
State & access()
Definition corkscrew.h:158
CorkscrewState::iterator iterator
Definition corkscrew.h:137
vec2f at_exact(uint16_t i) const
Definition corkscrew.cpp:74
Corkscrew(Corkscrew &&)=default
Tile2x2_u8_wrap at_wrap(float i) const
CorkscrewInput Input
Definition corkscrew.h:135
Corkscrew(const Input &input)
Definition corkscrew.cpp:70
static State generateState(const Input &input)
For testing.
CorkscrewState * owner_
Definition corkscrew.h:122
difference_type operator-(const iterator &other) const
Definition corkscrew.h:116
bool operator!=(const iterator &other) const
Definition corkscrew.h:112
iterator(CorkscrewState *owner, size_t position)
Definition corkscrew.h:81
bool operator==(const iterator &other) const
Definition corkscrew.h:108
vec2f & operator*() const
Definition corkscrew.h:84
UISlider offset("Offset", 0.0f, 0.0f, 1.0f, 0.01f)
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
CorkscrewInput(float total_length, float height, float total_turns, uint16_t leds, float offset=0, bool invertMapping=false)
Definition corkscrew.h:59
float offsetCircumference
Definition corkscrew.h:55
Generates a mapping from corkscrew to cylindrical coordinates.
Definition corkscrew.h:49
iterator begin()
Definition corkscrew.h:126
CorkscrewState()=default
fl::vector< fl::vec2f, fl::allocator_psram< fl::vec2f > > mapping
Definition corkscrew.h:71