-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathInfinityTable.ino
More file actions
146 lines (124 loc) · 4.3 KB
/
InfinityTable.ino
File metadata and controls
146 lines (124 loc) · 4.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#include <OctoWS2811.h>
const int nStrips = 6;
const int ledsPerStrip = 180;
#define led(ROW, COL) (ROW * ledsPerStrip + COL)
#define lastPixel(ROW, COL) leds.getPixel(led(ROW, COL))
#define pixel(ROW, COL, COLOR) leds.setPixel(led(ROW, COL), COLOR)
#define R(COLOR) ((char)(COLOR >> 16))
#define G(COLOR) ((char)(COLOR >> 8))
#define B(COLOR) ((char)(COLOR))
#define RGB(RV, GV, BV) ((((char)RV) << 16) + (((char)GV) << 8) + ((char)BV))
DMAMEM int displayMemory[ledsPerStrip*nStrips];
int drawingMemory[ledsPerStrip*nStrips];
const int config = WS2811_GRB | WS2811_800kHz;
OctoWS2811 leds(ledsPerStrip, displayMemory, drawingMemory, config);
void setup() {
randomSeed(analogRead(A5));
leds.begin();
leds.show();
}
#define BLACK 0x000000
#define RED 0xFF0000
#define GREEN 0x00FF00
#define BLUE 0x0000FF
#define YELLOW 0xFFFF00
#define PINK 0xFF1088
#define ORANGE 0xE05800
#define PURPLE 0xCC00E0
#define LIGHT_BLUE 0x00EBEF
#define BROWN 0x8E3838
#define WHITE 0xFFFFFF
#define DIM_RED 0x160000
#define DIM_GREEN 0x001600
#define DIM_BLUE 0x000016
#define DIM_YELLOW 0x101400
#define DIM_PINK 0x120009
#define DIM_ORANGE 0x100400
#define DIM_WHITE 0x101010
//int colors[] = {RED, GREEN, BLUE, YELLOW, DIM_RED, DIM_GREEN, DIM_BLUE, DIM_YELLOW};
int period = 250;
void loop() {
// conway(period * 16, WHITE);
// rainbow(40, 0.05, period);
// drawText("cabaaa");
// pingpong();
// randomBlocks();
// alternatingCheckerboard();
// roulette(100000);
// dicks(period);
// test();
// rainbow4(0.01, period * 8, 0.3);
// pacman(1);
tunnel();
}
void colorWipe(int color)
{
for (int i=0; i < leds.numPixels(); i++) {
leds.setPixel(i, color);
}
}
int interpolateRGB(int c1, int c2, float w, float nw) {
char r = ((int)(R(c1) * w + R(c2) * nw)) & 255;
char g = ((int)(G(c1) * w + G(c2) * nw)) & 255;
char b = ((int)(B(c1) * w + B(c2) * nw)) & 255;
return RGB(r, g, b);
}
int interpolateRGB(int c1, int c2, float w) {
return interpolateRGB(c1, c2, w, 1 - w);
}
void colorFade(int color, float w) {
for (int i=0; i < leds.numPixels(); i++) {
leds.setPixel(i, interpolateRGB(leds.getPixel(i), color, w));
}
}
// Add and saturate
void addPixel(int pixel, int color) {
leds.setPixel(pixel, interpolateRGB(color, leds.getPixel(pixel), 1, 1));
}
void addPixel(int row, int col, int color) {
addPixel(led(row, col), color);
}
// Linear speed bounce from 0 to width-1
int bounce(int x, int width) {
x = x % ((width - 1) * 2);
if (x >= width) return (width * 2 - 2 - x);
else return x;
}
// like mod but if x is negative always produces number bewteen x and m
int wrap(int x, int m) {
return ((x % m) + m) % m;
}
// Set a periodic pattern (where period should divide ledsPerStrip)
void periodic(int period, int row, int col, int color) {
for(int stride = 0; stride < ledsPerStrip; stride += period) {
pixel(row, col + stride, color);
}
}
// Set a periodic horizontally symmetric pattern (where period should divide ledsPerStrip/2).
// If period = 6, makes a 4-fold symmetric pattern.
void reflected(int period, int offset, int row, int col, int color) {
for(int stride = 0; stride < ledsPerStrip; stride += period*2) {
pixel(row, (col + stride + offset) % ledsPerStrip, color);
pixel(row, (period*2 - 1 - col + stride + offset) % ledsPerStrip, color);
}
}
// Set a periodic pattern with 8-fold symmetry.
// should only be called for col = {1, 2, 3, 3, 2, 1}
void reflected8(int row, int col, int color) {
int period = 6;
for(int stride = 0; stride < ledsPerStrip; stride += period) {
leds.setPixel(row * ledsPerStrip + stride + col, color);
leds.setPixel((5 - row) * ledsPerStrip + stride + period - 1 - col, color);
leds.setPixel((5 - col) * ledsPerStrip + stride + row, color);
leds.setPixel(col * ledsPerStrip + stride + period - 1 - row, color);
leds.setPixel((5 - row) * ledsPerStrip + stride + col, color);
leds.setPixel(row * ledsPerStrip + stride + period - 1 - col, color);
leds.setPixel(col * ledsPerStrip + stride + row, color);
leds.setPixel((5 - col) * ledsPerStrip + stride + period - 1 - row, color);
// TODO: why do macros suck?
// pixel(row, stride + col, color);
// pixel(period - 1 - row, stride + period - 1 - col, color);
// pixel(col, stride + period - 1 - row, color);
// pixel(period - 1 - col, stride + row, color);
}
}