-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGraphics.pde
173 lines (149 loc) · 4.67 KB
/
Graphics.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
import hypermedia.net.*;
// provide upward any interfaces required by Star and Mote.
// it will combine their stimuli into signals for lower-level graphics interfaces,
// such as for the screen, LEDs, strobes, ...
final int SIZE = 640;
final int FRAMERATE = 30;
final int SUNSIZE = 200;
final String BBB_ip = "10.0.1.101"; // ip address of BBB, determined by random coin
final String PWM_ip1 = "10.0.1.110";
final String PWM_ip2 = "10.0.1.111";
final int PWM_port = 6038;
public void settings() {
size(SIZE, SIZE, P3D);
fullScreen();
}
public class Graphics {
long time;
color starColor;
float starSize, glare;
private int numberOfMotes;
private class MoteData {
public float x, y, z_theta;
int bright;
}
private MoteData[] moteData;
private LittleStar[] starField;
PImage sprite;
PShape mote;
private final float moteSize = 0.02;
private final float stretch_z = 0.06;
private PixelOutput pixoutput;
private UDP udp;
public Graphics() {
// frameRate(FRAMERATE);
colorMode(HSB, 1.0);
rectMode(CENTER);
camera(SIZE * 1.5, SIZE/2, -SIZE/2, SIZE/2, SIZE/2, 0.0, 0.0, 0.0, 1.0);
sprite = loadImage("sprite2.png");
mote = createShape();
mote.beginShape(QUAD);
mote.noStroke();
mote.texture(sprite);
//mote.fill(color(280.0 / 360.0, 0.75, 1.0));
mote.normal(2.0 / sqrt(5), 0.0, -1 / sqrt(5));
mote.vertex(-SIZE * moteSize / 2.0, -SIZE * moteSize / 2.0, 0, 0);
mote.vertex(SIZE * moteSize / 2.0, -SIZE * moteSize / 2.0, sprite.width, 0);
mote.vertex(SIZE * moteSize / 2.0, SIZE * moteSize / 2.0, sprite.width,
sprite.height);
mote.vertex(-SIZE * moteSize / 2.0, SIZE * moteSize / 2.0, 0,
sprite.height);
mote.endShape();
pixoutput = new PixelOutput(rootSketch, BBB_ip);
udp = new UDP(this, PWM_port);
}
public void setStar(long time_, color starColor_, float starSize_,
float glare_) {
time = time_;
starColor = starColor_;
starSize = starSize_;
glare = glare_;
pixoutput.setPixelColors(starColor);
pixoutput.update();
}
public void setNumberOfMotes(int numberOfMotes_) {
numberOfMotes = numberOfMotes_;
moteData = new MoteData[numberOfMotes];
for (int i = 0; i < numberOfMotes; ++i) {
moteData[i] = new MoteData();
}
}
public void setMote(int id, float x, float y, float z_theta, int bright) {
moteData[id].x = x;
moteData[id].y = y;
moteData[id].z_theta = z_theta;
moteData[id].bright = bright;
}
public void setStarField(LittleStar[] starField_) {
starField = starField_;
}
public void setFlash(float flash) {
byte[] bytes = new byte[2];
bytes[0] = byte(int(flash * 255.9));
bytes[1] = byte(int(flash * 65535.5 - int(flash * 255.9) * 256));
udp.send(bytes, PWM_ip1, PWM_port);
udp.send(bytes, PWM_ip2, PWM_port);
}
public void assembleAndPush() {
background(0);
noStroke();
pushMatrix();
rotateY(-0.4*PI);
translate(-SIZE, 0.0, -SIZE);
// fill(0.75, 0.5);
for (int i = 0; i < starField.length; ++i) {
ellipse(starField[i].x(), starField[i].y(), starField[i].size(),
starField[i].size());
}
fill(1.0, 1.0);
popMatrix();
translate(SIZE/2, SIZE/2, 0);
PImage starImg = createImage(SUNSIZE, SUNSIZE, ARGB);
starImg.loadPixels();
long curTime = millis();
for (int x = 0; x < SUNSIZE; ++x) {
for (int y = 0; y < SUNSIZE; ++y) {
starImg.pixels[x + SUNSIZE * y] = color(hue(starColor), saturation(starColor),
(1.0 + noise(x, y, curTime / 1000.0)) / 2.0);
}
}
starImg.updatePixels();
PShape star = createShape(SPHERE, starSize * SIZE / 2);
star.setTexture(starImg);
pushMatrix();
rotateY(HALF_PI);
shape(star);
popMatrix();
stroke(starColor, 0.6);
beginShape(LINES);
for (int i = 0; i < 400; ++i) {
PVector v = PVector.random3D();
float x = v.x, y = v.y, z = v.z;
float x1 = 1.03 * v.x * starSize * SIZE / 2, x2 = 1.05 * x1;
float y1 = 1.03 * v.y * starSize * SIZE / 2, y2 = 1.05 * y1;
float z1 = 1.03 * v.z * starSize * SIZE / 2, z2 = 1.05 * z1;
vertex(x1, y1, z1);
vertex(x2, y2, z2);
}
endShape();
for (int i = 0; i < numberOfMotes; ++i) {
pushMatrix();
float z = sin(moteData[i].z_theta) * stretch_z;
translate(moteData[i].x * SIZE / 2, moteData[i].y * SIZE / 2, z * SIZE);
rotateY(-0.4*PI);
shape(mote);
popMatrix();
}
if (glare != 0.0) {
hint(DISABLE_DEPTH_TEST);
pushMatrix();
rotateY(-0.35*PI);
fill(1.0, glare);
rect(0, 0, 2.5*SIZE, 2.5*SIZE);
popMatrix();
hint(ENABLE_DEPTH_TEST);
setFlash(glare);
}
fill(1.0);
}
}