-
Notifications
You must be signed in to change notification settings - Fork 0
/
sketch.js
356 lines (241 loc) · 6.83 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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
/*
----------------------------------------------------------------
by p1xelfool
----------------------------------------------------------------
*/
let t = 0.0;
let pgMask;
let pgMaskArray;
let recording = true;
let pgW, pgH;
//PALETTE
let finalCol;
let palette = [
['#9d9e96', '#fe361f', '#00ff6c'],
['#9d9e96', '#fe361f', '#00ff6c', '#0000ff'],
['#9f9a93', '#7f776b', '#151112', '#c6ff00'],
['#767d72', '#fe0000', '#fd6d03', '#ff320b'],
['#000000', '#fe0000', '#EDF7F6', '#0000ff'],
['#767676', '#0000ff', '#e2e6ec', '#00FF00'],
['#b3b3b3', '#d7ff00', '#ff320b', '#aa0050'],
['#000000', '#d1fe39', '#e3ddd1', '#1dec57'],
['#000000', '#bec544', '#2b2d00', '#ff1500'],
['#000000', '#d1ff00', '#e2e6ec', '#00d8ff'],
['#000000', '#002d97', '#e2e6ec', '#d1ff00'],
['#767676', '#aa0050', '#01867b', '#c6ff00', '#1b2548'],
['#575757', '#0f0f0f', '#ff77f3', '#c6ff00', '#fe5d05', '#005bda'],
];
let paletteName = [
':3 x00',
':4 x0:',
':4 x0;',
':4 x0[',
':4 x0*',
':4 x0#',
':4 x0+',
':4 x0!',
':4 x0~',
':4 x0>',
':4 x0/',
':5 xx',
':6 xx%',
];
let palette1;
let palettePicker;
let colorPicker;
let numSystems;
/////RESOLUTION
let r1 = 10;
let tempR = 5;
let canvas;
////PAUSE PLAY
let running = true;
//////PARTICLE SYSTEM
var maskRunner;
let bornMargin;
///GIF
let saveGif = false;
let gif;
let framesToSkip = 2;
let makeGif = false;
let isGifExported = false;
///////PAINT
let bornAtX = 0;
let bornAtY = 0;
//////RANDOM POSITION VS CONCENTRATED
let randomPos;
////CIRCLE PERCENTAGE
let circlePercentage;
//////MAX TIME
let maxTime;
let maxTimeArray = [1000, 1200, 1600];
/////////RANDOM SEED
let randomSeedHash;
function setup() {
canvas = createCanvas(windowWidth, windowHeight);
frameRate(30);
////random seed
randomSeedHash = hl.random(0,9999999999);//random(hl.random(0, 999999999999));
console.log(randomSeedHash);
noiseSeed(4);
randomSeed(randomSeedHash);
///RES
if(windowWidth > windowHeight){
r1=tempR;
}else{
r1=tempR;
}
////PALETTE
palettePicker = floor(random(0, palette.length));
///NUM SYSTEMS
numSystems = floor(random(3, 7.99));
//BORN
bornMargin = -40;//random(5, 15);
//////RANDOM POSITION VS CONCENTRATED /// IF HIGHER MORE CONCENTRATED
randomPos = random(0.4, 0.7);
////CIRCLE
circlePercentage = random(0.7, 0.9);
////maxTime
let maxTimePicker = floor(random(0, maxTimeArray.length));
maxTime = maxTimeArray[maxTimePicker];
hl.token.setTraits({
Palette: paletteName[palettePicker],
Colors: palette[palettePicker].length,
TimeGen: maxTime,
});
console.log(hl.token.getTraits());
begin();
setupGif();
}
function draw() {
////IF NOT PAUSED
if (running == true) {
t++;
if(frameCount%100==0){
bornAtX = random(bornMargin, pgMask.width-bornMargin);
bornAtY = random(bornMargin, pgMask.height-bornMargin);
}
if(frameCount==1){
pgMask.background(color(palette[palettePicker][0]));
}
// console.log(frameRate());
////////////////////////
////////////// PARTICLE SYSTEM MASK
//////1000, 1500
if(frameCount%10==0 && frameCount<maxTime){
for(let i=0; i<1; i++){
maskRunner.push(new particleSystemMask);
}
}
/////////////////////////
////////////////PARTICLE SYSTEM MASK
pgMask.loadPixels();
//RUN SYSTEM
let len = maskRunner.length;
for (let i = len - 1; i >= 0; i--) {
let p = this.maskRunner[i];
p.add();
p.run();
//CHECK IF DEAD
if (p.isDead()) {
this.maskRunner.splice(i, 1);
}
}
pgMask.updatePixels();
imageMode(CENTER);
image(pgMask, windowWidth / 2, windowHeight / 2, windowWidth, windowHeight);
} /////IF RUNNING
// GIF: Add frame
if (makeGif &&
!isGifExported &&
((frameCount - 1) % framesToSkip == 0 || frameCount == 1)
) {
console.log(`Added frame.`)
gif.addFrame(canvas.elt, {
delay: 30,
copy: true
});
}
// GIF: Render when done
if (makeGif &&
!isGifExported &&
frameCount>maxTime+160
) {
print('Exporting GIF...');
gif.render();
isGifExported = true;
}
}
function windowResized() {
resizeCanvas(windowWidth, windowHeight);
t=0;
frameCount=0;
begin();
}
function begin() {
randomSeed(randomSeedHash);
////GENERATE SYSTEM
////PARTICLE SYSYTEM
maskRunner = [];
t = 0.0;
frameCount = 0;
noCursor();
strokeWeight(1.01);
//DEFINE PROPORTIONS
let ww, hh;
// ww = 2560;
// hh = 2560 / (innerWidth / innerHeight);
// let pgX = int(ww / r1 + 1);
// let pgY = int(hh / r1 + 1);
if(innerWidth>innerHeight){
ww = 2560;
hh = 2560 / (innerWidth / innerHeight);
pgX = int(ww / r1 + 1);
pgY = int(hh / r1 + 1);
}else{
ww = 2560 / (innerHeight / innerWidth);
hh = 2560;
pgX = int(ww / r1 + 1);
pgY = int(hh / r1 + 1);
}
///PGMASK
pgMask = createGraphics(pgX, pgY);
pgMask.pixelDensity(1);
pgMask.noSmooth();
pgMask.colorMode(HSB, 360, 100, 100, 100);
pgMaskArray = [];
/////RANDOM POSITION
bornAtX = random(bornMargin, pgMask.width-bornMargin);
bornAtY = random(bornMargin, pgMask.height-bornMargin);
canvas.imageSmoothingEnabled = false;
p5.disableFriendlyErrors = true;
noSmooth();
pixelDensity(1);
}
/////COMMANDS
function keyTyped() {
////PAUSE
if (key === 'p') {
running = !running;
} else if (key === 's') {
saveCanvas('image' + '.png');
} else if (key === 'g') {
makeGif = true;
}
}
function setupGif() {
recordedFrames = 0;
gif = new GIF({
workers: 2,
quality: 40,
framerate: 25,
workerScript: './gif.worker.js'
});
gif.on('finished', function(blob) {
print('your GIF is ready ///')
rendering = false;
window.open(URL.createObjectURL(blob));
setupGif();
recordedFrames = 0;
});
}