-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsketch.js
246 lines (205 loc) · 6.51 KB
/
sketch.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
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
let field;
let w, h;
let canvas;
let canvasContainer;
let guiContainer;
let upperPortals, lowerPortals;
let yellowPortalAdd;
let purplePortalAdd;
let greenPortalAdd;
let warmWhitePortalAdd;
let yellowPortalRemove;
let purplePortalRemove;
let greenPortalRemove;
let warmWhitePortalRemove;
let switchScaleButton;
let scaleState = 0;
let mucoBanner;
let mucoHeader;
let mucoText;
let infoBox;
let audioContextHint;
function setup() {
guiContainer = createElement('div').addClass('gui-container');
canvasContainer = createElement('div').addClass('canvas-container');
w = map(windowWidth, 50, 1000, 300, 400);
h = map(windowHeight, 50, 800, 400, 500);
canvas = createCanvas(w, h);
canvas.parent(canvasContainer);
// Prompt for action if the audio context is suspended
if (Tone.context.state !== 'running') {
infoBox = createElement('div')
.position(w/2, h/2)
.addClass('info-box');
audioContextHint = createElement('p', "Click me to enable sound.")
.addClass('info-text')
.parent(infoBox);
infoBox.mouseClicked(enableAudioContext);
}
// Create upper portals
upperPortals = createElement('div').addClass('upper-portals');
yellowPortalAdd = createElement('div').addClass('upper-yellow-portal');
yellowPortalAdd.mousePressed(addYellowParticle);
yellowPortalAdd.parent(upperPortals);
purplePortalAdd = createElement('div').addClass('upper-purple-portal');
purplePortalAdd.mousePressed(addPurpleParticle);
purplePortalAdd.parent(upperPortals);
greenPortalAdd = createElement('div').addClass('upper-green-portal');
greenPortalAdd.mousePressed(addGreenParticle);
greenPortalAdd.parent(upperPortals);
warmWhitePortalAdd = createElement('div').addClass('upper-warmWhite-portal');
warmWhitePortalAdd.mousePressed(addWarmWhiteParticle);
warmWhitePortalAdd.parent(upperPortals);
// Create lower portals
lowerPortals = createElement('div').addClass('lower-portals');
lowerPortals.position(w-100, h+50);
yellowPortalRemove = createElement('div').addClass('lower-yellow-portal');
yellowPortalRemove.mousePressed(removeYellowParticle);
yellowPortalRemove.parent(lowerPortals);
purplePortalRemove = createElement('div').addClass('lower-purple-portal');
purplePortalRemove.mousePressed(removePurpleParticle);
purplePortalRemove.parent(lowerPortals);
greenPortalRemove = createElement('div').addClass('lower-green-portal');
greenPortalRemove.mousePressed(removeGreenParticle);
greenPortalRemove.parent(lowerPortals);
warmWhitePortalRemove = createElement('div').addClass('lower-warmWhite-portal');
warmWhitePortalRemove.mousePressed(removeWarmWhiteParticle);
warmWhitePortalRemove.parent(lowerPortals);
// Add button to switch scale
switchScaleButton = createElement('div').addClass('switch-scale-button');
switchScaleButton.mousePressed(changeScale);
switchScaleButton.mouseOver(glow);
switchScaleButton.mouseOut(setColor);
switchScaleButton.position(w+30, 60);
setColor();
// Add Banner with text
mucoBanner = createElement('div').addClass('muco-banner');
mucoBanner.position(w + 30, h - 114);
mucoHeader = createElement('div').addClass('muco-header');
mucoHeader.parent(mucoBanner);
mucoHeader.html('Muco').addClass('muco-header');
mucoText = createElement('div').addClass('muco-text');
mucoText.html('A Music generating particle system. ', true);
mucoText.html('Made by Navaneeth K M', true);
mucoText.parent(mucoBanner);
guiContainer.child(canvasContainer);
guiContainer.child(upperPortals);
guiContainer.child(lowerPortals);
guiContainer.child(switchScaleButton);
guiContainer.child(mucoBanner);
// Create Particle Field
field = new Field(10, 10, w-30, h-20);
}
function draw() {
background(255);
field.run();
}
function addYellowParticle() {
field.addParticle("yellow");
}
function addPurpleParticle() {
field.addParticle("purple");
}
function addGreenParticle() {
field.addParticle("green");
}
function addWarmWhiteParticle() {
field.addParticle("warmwhite");
}
function removeYellowParticle() {
field.removeParticle("yellow");
}
function removePurpleParticle() {
field.removeParticle("purple");
}
function removeGreenParticle() {
field.removeParticle("green");
}
function removeWarmWhiteParticle() {
field.removeParticle("warmwhite");
}
function changeScale() {
if (scaleState < 3) {
scaleState += 1;
} else {
scaleState = 0;
}
switch (scaleState) {
case 0: {
field.particleSystem.ensemble.fillNewPools(a4PentMin);
break;
}
case 1: {
field.particleSystem.ensemble.fillNewPools(d3PentMin);
break;
}
case 2: {
field.particleSystem.ensemble.fillNewPools(c4PentMaj);
break;
}
default: {
field.particleSystem.ensemble.fillNewPools(f3PentMaj);
break;
}
}
setColor();
}
function setColor() {
switch (scaleState) {
case 0: {
const col = color(243, 165, 183);
switchScaleButton.style('border-color', col);
switchScaleButton.style('color', col);
switchScaleButton.html('1');
break;
}
case 1: {
const col = color(133, 131, 255);
switchScaleButton.style('border-color', col);
switchScaleButton.style('color', col);
switchScaleButton.html('2');
break;
}
case 2: {
const col = color(192, 172, 165);
switchScaleButton.style('border-color', col);
switchScaleButton.style('color', col);
switchScaleButton.html('3');
break;
}
default: {
const col = color(163, 120, 212);
switchScaleButton.style('border-color', col);
switchScaleButton.style('color', col);
switchScaleButton.html('4');
}
}
}
function glow() {
switch (scaleState) {
case 0: {
const col = color(238, 124, 150);
switchScaleButton.style('border-color', col);
break;
}
case 1: {
const col = color(79, 77, 255);
switchScaleButton.style('border-color', col);
break;
}
case 2: {
const col = color(171, 144, 135);
switchScaleButton.style('border-color', col);
break;
}
default: {
const col = color(123, 61, 194);
switchScaleButton.style('border-color', col);
}
}
}
function enableAudioContext() {
audioContextHint.remove();
infoBox.remove();
Tone.context.resume();
}