-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathui.js
99 lines (88 loc) · 2.15 KB
/
ui.js
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
let button, record, clr;
let path, sizeSlider, densitySlider, angleSlider, noiseControl;
function setupUI() {
// Normal Buttons
button = select('#toggleLoop');
button.mousePressed(toggleLoop);
record = select('#record');
record.mousePressed(toggleRecord);
snap = select('#saveFrame');
snap.mousePressed(saveImage);
fps = select('#fps');
// Radio Buttons
path = document.getElementsByName('path');
coloring = document.getElementsByName('coloring');
display = document.getElementsByName('display');
// Sliders
numParticles = select('#numParticles');
numParticles.changed(initSketch);
sizeSlider = select('#size');
sizeSlider.changed(initSketch);
speedSlider = select('#speed');
speedSlider.changed(initSketch);
noiseScale = select('#noiseScale');
noiseScale.changed(initSketch);
noiseStrength = select('#noiseStrength');
noiseStrength.changed(initSketch);
}
function toggleLoop() {
if (isLoop) {
noLoop();
isLoop = false;
} else {
loop();
isLoop = true;
}
}
function toggleRecord() {
if (isRecording) {
isRecording = false;
save = true;
} else {
isRecording = true;
save = false;
}
}
function clearCanvas() {
clear();
background(51);
}
function numOfParticles() {
let diff;
if (points.length > numParticles.value()) {
diff = points.length - numParticles.value();
points.splice(0, diff);
} else if (points.length < numParticles.value()) {
diff = numParticles.value() - points.length;
for (let i = 0; i < diff; i++) {
var x = random(width);
var y = random(height);
var color = coloringMethod(x, y);
points.push(new Particle(x, y, color));
}
}
}
function saveImage() {
if (!isLoop) {
toggleLoop();
captureFrame();
toggleLoop();
} else {
captureFrame();
}
}
function captureFrame() {
filename =
'flowField_' + str(year()) + str(month() + day() + hour() + minute() + second());
saveCanvas(filename, 'PNG');
}
function display_static() {
loop();
record.addClass('invisible');
fps.addClass('invisible');
}
function display_animate() {
loop();
record.removeClass('invisible');
fps.removeClass('invisible');
}