-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDotMatrix.pde
92 lines (68 loc) · 1.97 KB
/
DotMatrix.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
import processing.core.*;
public class DotMatrix extends VizBase {
// visualization-dependent variables
color background = #FFFFFF;
int matrixWidth = 30;
int matrixHeight = 6;
LinkedList dotMatrix = new LinkedList();
public DotMatrix(PApplet parentApplet) {
super(parentApplet);
name = "Dot Matrix";
}
@Override
public void init() {
for (int i = 0; i < matrixWidth * matrixHeight; i++) {
dotMatrix.offer(new CellDotData(0, null));
}
// cf = new ControlFrame(this, cfWidth, cfHeight, "Controls");
// TODO: find some other way to slow down the animation speed
// frameRate(10);
}
void keyPressed() {
if (key == ' ') {
dotMatrix.clear();
for (int i = 0; i < matrixWidth * matrixHeight; i++) {
dotMatrix.offer(new CellDotData(0, null));
}
}
}
@Override
void display(float[] signals) {
background(background);
// add new signal to matrix
int numDots = round(map(signals[0], 0, 100, 1, 6));
dotMatrix.poll();
dotMatrix.offer(new CellDotData(numDots, null));
// draw the matrix
int padding = 100;
float cellWidth = (width - (padding * 2)) / matrixWidth;
float cellHeight = (height - (padding * 2)) / matrixHeight;
for (int j = 0; j < matrixHeight; j++) {
for (int i = 0; i < matrixWidth; i++) {
pushMatrix();
translate(padding + cellWidth * i + (cellWidth), padding + cellHeight * (j + 1));
CellDotData dotData = (CellDotData)dotMatrix.get(j * matrixWidth + i);
noStroke();
for (int k = 0; k < dotData.numDots; k++) {
if (k == 5) {
fill(255, 0, 0);
}
else {
fill(0);
}
ellipse(0, -8 * k, 5 ,5);
}
popMatrix();
}
}
}
// POJO
class CellDotData {
int numDots;
byte[] colorings;
public CellDotData(int _numDots, byte[] _colorings) {
numDots = _numDots;
colorings = _colorings;
}
}
}