forked from mhenstell/acw
-
Notifications
You must be signed in to change notification settings - Fork 4
/
domeTransmitter.pde
200 lines (170 loc) · 5.17 KB
/
domeTransmitter.pde
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
import processing.opengl.*;
import java.lang.reflect.Method;
import hypermedia.net.*;
import java.io.*;
// Most standard configuration stuff moved to Config class.
// TODO Move Routine configuraiton to Config class. Not straightfoward because static restrictions.
public Routine[] enabledRoutines = new Routine[] {
//new Configulate(),
//new TestPattern(false),
new Waves(),
new WarpSpeedMrSulu(),
new Warp(),
new TrialOfZod(),
new Seizure(),
new RainbowColors(),
new RGBRoutine(),
new Pong(),
//new Greetz(),
//new FFTDemo(),
//new DropTheBomb(),
new ColorDrop(),
new Chase(),
new Bursts(),
new Animator("anim-nyancat",1,.5,0,0,0),
new TestPattern(true)
};
PGraphics draw;
Routine drop = new Seizure();
Routine backupRoutine = null;
int currentColor = 0;
color primaryColor = Config.PALETTE[0];
color secondaryColor = Config.PALETTE[1];
color tertiaryColor = Config.PALETTE[2];
PFont font;
int ZOOM = 1;
long modeFrameStart;
int mode = 0;
//int direction = 1;
//int position = 0;
Routine currentRoutine = null;
LEDDisplay sign;
PGraphics fadeLayer;
int fadeOutFrames = 0;
int fadeInFrames = 0;
WiiController controller;
boolean wasButtonUp = false;
PImage displayBuffer;
boolean switching_mode = false; // if true, we already switched modes, so don't do it again this frame (don't freeze the display if someone holds the b button)
int seizure_count = 0; // Only let seizure mode work for a short time.
void setup() {
println("Display dimensions = " + Config.WIDTH + "x" + Config.HEIGHT);
size(int(Config.WIDTH*Config.ZOOM),int(Config.HEIGHT*Config.ZOOM),P2D);
draw = createGraphics(Config.WIDTH, Config.HEIGHT);
frameRate(Config.FRAMERATE);
// TODO FIX LEDDisplay to work in old send 1 then packets mode..
sign = new LEDDisplay(this, Config.WIDTH, Config.HEIGHT, true, Config.HOST, Config.PORT);
sign.setAddressingMode(Config.ADDRESSING_MODE);
sign.setEnableGammaCorrection(Config.ENABLE_GAMMA);
setMode(0);
controller = new WiiController();
for (Routine r : enabledRoutines) {
r.setup(this);
}
drop.setup(this);
}
void setFadeLayer(int g) {
fadeLayer = createGraphics(Config.WIDTH, Config.HEIGHT);
fadeLayer.beginDraw();
fadeLayer.stroke(g);
fadeLayer.fill(g);
fadeLayer.rect(0, 0, Config.WIDTH, Config.HEIGHT);
fadeLayer.endDraw();
}
void setMode(int newMode) {
currentRoutine = enabledRoutines[newMode];
mode = newMode;
modeFrameStart = frameCount;
println("New mode " + currentRoutine.getClass().getName());
currentRoutine.reset();
}
void newMode() {
int newMode = mode;
String methodName;
fadeOutFrames = int(Config.FRAMERATE);
setFadeLayer(240);
if (enabledRoutines.length > 1) {
while (newMode == mode) {
newMode = int(random(enabledRoutines.length));
}
}
setMode(newMode);
}
void draw() {
draw.beginDraw();
if (!controller.buttonB) {
switching_mode = false;
}
if (controller.buttonA) {
seizure_count += 1;
}
else {
seizure_count = 0;
}
// Jump into seizure mode
if ((controller.buttonA || (keyPressed && key == 'a')) && currentRoutine != drop && seizure_count == 1) {
//drop.draw();
backupRoutine = currentRoutine;
currentRoutine = drop;
drop.reset();
}
// Drop out of seizure mode
else if (!controller.buttonA && currentRoutine == drop) {
currentRoutine = backupRoutine;
}
else if (seizure_count > 10 && currentRoutine == drop) {
currentRoutine = backupRoutine;
}
else if ((controller.buttonB || (keyPressed && key == 'c')) && !switching_mode) {
newMode();
switching_mode = true;
}
else {
if (fadeOutFrames > 0) {
fadeOutFrames--;
draw.blend(fadeLayer, 0, 0, Config.WIDTH, Config.HEIGHT, 0, 0, Config.WIDTH, Config.HEIGHT, MULTIPLY);
if (fadeOutFrames == 0) {
fadeInFrames = int(Config.FRAMERATE);
}
}
else if (currentRoutine != null) {
currentRoutine.draw();
}
else {
println("Current method is null");
}
if (controller.buttonUp && !wasButtonUp) {
wasButtonUp = true;
println("New color");
cycleColors();
}
else if (!controller.buttonUp && wasButtonUp) {
wasButtonUp = false;
}
if (fadeInFrames > 0) {
setFadeLayer(240 - fadeInFrames * (240 / int(Config.FRAMERATE)));
draw.blend(fadeLayer, 0, 0, Config.WIDTH, Config.HEIGHT, 0, 0, Config.WIDTH, Config.HEIGHT, MULTIPLY);
fadeInFrames--;
}
if (currentRoutine.isDone) {
currentRoutine.isDone = false;
newMode();
}
}
displayBuffer = draw.get(0,0,Config.WIDTH,Config.HEIGHT);
displayBuffer.loadPixels();
sign.sendData(displayBuffer.pixels);
draw.endDraw();
image(draw,0,0,width,height);
}
color randomColor() {
return Config.PALETTE[int(random(Config.PALETTE.length))];
}
void cycleColors() {
currentColor++;
if (currentColor >= Config.PALETTE.length)
currentColor = 0;
primaryColor = Config.PALETTE[currentColor];
secondaryColor = Config.PALETTE[currentColor+1 < Config.PALETTE.length ? currentColor+1 : currentColor-Config.PALETTE.length+1];
tertiaryColor = Config.PALETTE[currentColor+2 < Config.PALETTE.length ? currentColor+2 : currentColor-Config.PALETTE.length+2];
}