-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKeyboardVisualizer.pde
More file actions
120 lines (107 loc) · 2.02 KB
/
Copy pathKeyboardVisualizer.pde
File metadata and controls
120 lines (107 loc) · 2.02 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
//TODO: Add sound.
final int size = 1700;
ArrayList<VisualizePoint> vps = new ArrayList<VisualizePoint>();
void settings()
{
size(size, size);
}
void setup()
{
background(0);
noStroke();
frameRate(120);
}
void draw()
{
//if (keyPressed && key != CODED) {
// if (mode == RANDOM)
// {
// animateCircle(x, y, 50);
// }
// if (mode == FIXED)
// {
// int val = int(key);
// int x = xLoc(val);
// int y = yLoc(val);
// fill(createColor(val));
// circle(x, y, 150);
// }
//}
background(0);
// Iterate backwards to ensure indexing stays the same.
for (int i = vps.size() - 1; i >= 0; i--)
{
// Update returns false, indicating element must be removed.
if (!vps.get(i).update())
{
vps.remove(i);
}
}
}
void keyPressed()
{
if (key != CODED)
{
int val = int(key);
VisualizePoint vp = new VisualizePoint(val);
vps.add(vp);
int amount = int(random(6)) + 3
;
for (int i = 0; i < amount; i++)
{
VisualizePoint smallVp = new VisualizePoint(val);
int x = int(random(100)) - 50;
int y = int(random(50)) - 90;
smallVp.x = x + vp.x;
smallVp.y = y + vp.y;
smallVp.rad = int(random(30)) + 30;
vps.add(smallVp);
}
}
}
void animateCircle(int x, int y, int size)
{
// Base case.
if (size < 0)
{
return;
}
// Recursive case.
background(0);
circle(x, y, size);
println(x + " " + y + " " + size);
delay(100);
animateCircle(x+10, y+10, size - 5);
}
color createColor(int k)
{
color c;
float r, g, b;
r = k * 2 % 255.0;
g = k * k % 255.0;
b = k * k * k % 255.0;
c = color(r, g, b, 255.0);
return c;
}
// ASCII range is from 33-126.
// (Essentially gonna be 0-93)
// 94 total values.
// Using 10x10 setup.
int xLoc(int k)
{
int x;
// Zero the ASCII value.
k -= 33;
x = size * (k % 10) / 10;
x += size * 0.05;
return x;
}
int yLoc(int k)
{
int y;
// Zero the ASCII value.
k -= 33;
y = size * (k / 10) / 10;
y += size * 0.05;
return y;
}