-
Notifications
You must be signed in to change notification settings - Fork 0
/
D15AsterixTransmitter.pde
136 lines (110 loc) · 3.59 KB
/
D15AsterixTransmitter.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
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(true),
new Life()
};
PGraphics draw;
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;
Routine currentRoutine = null;
LEDDisplay sign;
PGraphics fadeLayer;
int fadeOutFrames = 0;
int fadeInFrames = 0;
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)
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);
for (Routine r : enabledRoutines) {
r.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 (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 (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];
}