This repository has been archived by the owner on Aug 21, 2019. It is now read-only.
/
Sidewalk.pde
67 lines (60 loc) · 1.61 KB
/
Sidewalk.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
class Sidewalk {
// how many strings to make
int strings = 10;
// start and end x position
int xp0 = 50;
int xp1 = width-50;
// array of lengths
float[] arrLen = new float[strings];
// length range
float len0 = 50; float len1 = height-20;
// timer variables
float t0 = millis();
float t1 = t0;
// timer - minimum seconds of time between reconfiguring
float tChange = 3.0;
// has user plucked a thread since last reconfiguration?
boolean hasPlayed = false;
// -----------------------------------------------------
// Constructor
// -----------------------------------------------------
Sidewalk () {
float len;
float xp = xp0;
float dx = (xp1-xp0)/(strings-2);
float yp = yAxis;
// create threads
for (int i = 0; i < strings; i++) {
// set lengths randomly
len = lerp(len0, len1, random(1));
// draw vertical lines along
addThread(xp, yp-len/2, xp, yp+len/2);
xp += dx;
}
}
// Update function
void upd() {
// how much time elapsed since last reconfigure
t1 = millis();
float elap = (t1-t0)/1000;
// only reconfigure while not currently engaged
if ((elap > tChange) && !isEngaged && !isMouseDown && hasPlayed) {
reconfigure();
}
}
// User played
void userPlayed() {
// stoer the last time the user plucked
t0 = millis();
if (!hasPlayed) hasPlayed = true;
}
// Move strings to
void reconfigure() {
hasPlayed = false;
float len;
for (int i = 0; i < strings; i++) {
len = lerp(len0, len1, random(1));
arrThreads[i].resizeTo(len);
}
}
}