/
sketch_2019_01_28.js
380 lines (315 loc) · 11.4 KB
/
sketch_2019_01_28.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
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
/*
aids in figuring this out are as follows:
this was used to help me make the animation and save frames
https://funprogramming.org/114-How-to-create-movies-using-Processing.html
this discussion and code from user JR were used to figure out the fading
this method is not recommended b/c call to createGraphics inside draw() is hard on memory
https://processing.org/discourse/beta/num_1265045578.html, not recommended
maybe one of these methods from StackOverflow could be used
https://stackoverflow.com/questions/9215231/making-a-fading-trail-in-processing
and of course the documenttation for the language
https://www.processing.org/reference/
credit to https://p5js.org and https://github.com/processing/p5.js/wiki/Processing-transition
*/
//TODO, make more functions for patterned moving shapes, not just random
//establishing a few variables necessary for the functions
var angle, speed, line_y,line_x; //variables necessary to control the movement of shapes
var r, g, b; //variables for control of color
var the_cc; //variable for color change
var el_center_x, el_center_y,el_sep_up, el_sep_x,el_sep_y, move_el_x,move_el_y; //movingRandomFlower variables
var my_name; //variable to make namign files easier and more informative
//variables to make naming files easier, https://stackoverflow.com/questions/1531093/how-do-i-get-the-current-date-in-javascript
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth() + 1; //January is 0!
var yyyy = today.getFullYear();
if (dd < 10) {
dd = '0' + dd;
}
if (mm < 10) {
mm = '0' + mm;
}
today = yyyy + '_' + mm + '_' + dd;
//setting up the drawing background and parameters
function setup(){
createCanvas(2560, 1440); //changing the size and dimension so it displays better in YouTube
background(0,0,0); //starting with a black background
frameRate(30);
noStroke();
ellipseMode(CENTER);
rectMode(CENTER);
angle=0;
speed=0.04; //establishing how fast everythign will move in drawMovingRectangle
r=255; //all three RGB to 255 so it all begins as white
g=255; //used in drawMovingRectangle
b=255; //used in drawMovingRectangle
the_cc=0; //variable for color changes in drawMovingRectangle
line_y=height/2; //used in drawMovingLine function
line_x=width/2; //used in movingParallelLines function
el_center_x=width/2; //movingRandomFlower variables
el_center_y=height/2;
el_sep_x=100;
el_sep_y=100;
move_el_x= -width/100;
move_el_y= -height/110;
}
//loop to make drawings
function draw(){
makeBackground();
drawMovingRectangle();
drawMovingLine();
randomShapeSelector();
movingParallelLines();
movingRandomFlower();
if(frameCount<10){
my_name=today+'_'+'frame_'+'000'+String(frameCount);
} else if(frameCount<100){
my_name=today+'_'+'frame_'+'00'+String(frameCount);
} else if(frameCount<1000){
my_name=today+'_'+'frame_'+'0'+String(frameCount);
} else{
my_name=today+'_'+'frame_'+String(frameCount);
}
saveCanvas(my_name,'jpg');
if(frameCount > 600){
noLoop(); //this breaks us out of the drawing loop
}
}
//capturer.stop();
//capturer.save();
//creating functions that can be reused
//function for the background
function makeBackground(){
noStroke();
fill(random(255),random(255),random(255),100); //the covering up the background, 255 all is white, 0 is black
rect(width/2,height/2,width,height); //we just draw a rectangle over the screen
}
//function for a swirlign rectangle
function drawMovingRectangle(){
angle+=speed;
var x=width/2+sin(angle)*width/3;
var y=height/2+cos(angle)*height/4;
//making a rectangle
fill(r,g,b);
noStroke();
rect(x,y,width/8,height/8);
//changing colors
the_cc=int(random(0,6));
if(the_cc==0){
r-=5;
} else if(the_cc==1){
r+=5;
} else if(the_cc==2){
g-=5;
} else if(the_cc==3){
g+=5;
} else if(the_cc==4){
b-=5;
} else if(the_cc==5){
b+=5;
}
//resetting colors
if(b<10){
b=255;
}
if(r<10){
r=255;
}
if(g<10){
g=255;
}
}
//function to create a line that moves up and down
function drawMovingLine(){
//drawing a line
stroke(255,255,255);
strokeWeight(4);
line(0,line_y,width,line_y);
line_y=line_y-2;
if(line_y<0){
line_y=height;
}
}
//first function necessary to make complex random shapes
function randomVertices(level){ //making a function to generate random vertices to be used in makign random shapes
vertex(random(width), random(height));
if (level>1){
level = level -1;
randomVertices(level);
}
}
//second function necessary to make complex random shapes
function randomCurveVertices(level){ //making a function to generate random curve vertices to be used in makign random shapes
curveVertex(random(width), random(height));
if (level>1){
level = level -1;
randomCurveVertices(level);
}
}
//third function necessary to make complex random shapes
function randomBezierVertices(level){ //making a function to generate random curve vertices to be used in makign random shapes
bezierVertex(random(width), random(height),random(width),random(height),random(width),random(height));
if (level>1){
level = level -1;
randomBezierVertices(level);
}
}
//a whole bunch of shape functions
function randomBezierShape(){
stroke(random(255), random(255), random(255)); //this accidentally changed the parameters in the other shapes, but it is kind of cool
strokeWeight(random(width/width,width/100));
fill(random(255), random(255), random(255));
beginShape();
vertex(random(width),random(height));
randomBezierVertices(int(random(4,25))); //curves must have at least 4 points
endShape(CLOSE);
}
function randomCurvyShape(){
//make a random curvy shape
stroke(random(255), random(255), random(255)); //this accidentally changed the parameters in the other shapes, but it is kind of cool
strokeWeight(random(width/width,width/100));
fill(random(255), random(255), random(255));
beginShape();
randomCurveVertices(int(random(4,25))); //curves must have at least 4 points
endShape(CLOSE);
}
function randomShape(){
//make a random shape
stroke(random(255), random(255), random(255)); //this accidentally changed the parameters in the other shapes, but it is kind of cool
strokeWeight(random(width/width,width/100));
fill(random(255), random(255), random(255));
beginShape();
randomVertices(int(random(3,25)));
endShape(CLOSE);
}
function randomCurveLine(){
//make a random curvy line
stroke(random(255), random(255), random(255)); //this accidentally changed the parameters in the other shapes, but it is kind of cool
strokeWeight(random(width/width,width/100));
curve(random(width), random(height), random(width), random(height), random(width), random(height),random(width), random(height));
}
function randomBezierLine(){
//make a random bezier line
stroke(random(255), random(255), random(255)); //this accidentally changed the parameters in the other shapes, but it is kind of cool
strokeWeight(random(width/width,width/100));
bezier(random(width), random(height), random(width), random(height), random(width), random(height),random(width), random(height));
}
function randomStraightLine(){
//make a random straight line
stroke(random(255), random(255), random(255)); //this accidentally changed the parameters in the other shapes, but it is kind of cool
strokeWeight(random(width/width,width/100));
line(random(width), random(height), random(width), random(height));
}
function randomArc(){
fill(random(255), random(255), random(255)); //makes a random RGB color
//random dimensions for the arc
var x_1 = random(width);
var y_1 = random(height);
var w_1 = random(width);
var h_1 = random(height);
//making a random arc
arc(x_1, y_1, x_1, h_1, random(6.283185), random(6.283185), PIE);
}
function randomQuad(){
noStroke();
fill(random(255), random(255), random(255)); //makes a random RGB color
//random dimensions for the quad
var x_1 = random(width);
var y_1 = random(height);
var x_2 = random(width);
var y_2 = random(height);
var x_3 = random(width);
var y_3 = random(height);
var x_4 = random(width);
var y_4 = random(height);
//making a random quad
quad(x_1, y_1, x_2, y_2, x_3, y_3, x_4, y_4);
}
function randomEllipse(){
//making and placing a random ellipse
fill(random(255), random(255), random(255)); //makes a random RGB color
var sz_1 = random(width); //making a variable for the rectangle size
var sz_2 = random(height); //another variable for rectangle dimensions
//width and height are system variables, and we can use them to randomly place an ellipse
ellipse(random(width), random(height), sz_1, sz_2);
}
function randomRectangle(){
//making and placing a random rectangle
fill(random(255), random(255), random(255)); //makes a random RGB color
var sz_1 = random(width); //making a variable for the rectangle size
var sz_2 = random(height); //another variable for rectangle dimensions
//width and height are system variables, and we can use them to randomly place a rect
rect(random(width), random(height), sz_1, sz_2);
}
function randomShapeSelector(){
//a function that randomly generates a shape
var choice = int(random(1,10)); //we have three options
if(choice==0){
randomRectangle();
} else if(choice==1){
randomEllipse();
} else if(choice==2){
randomQuad();
} else if(choice==3){
randomArc();
} else if(choice==4){
randomStraightLine();
} else if(choice==5){
randomBezierLine();
} else if(choice==6){
randomCurveLine();
} else if(choice==7){
randomShape();
} else if(choice==8){
randomCurvyShape();
} else if(choice==9){
randomBezierShape();
}
}
function movingParallelLines(){
//line colors
stroke(255,200,200);
strokeWeight(5);
line(line_x+10,0,line_x+10,height);
line(line_x-10,0,line_x-10,height);
line_x=line_x-10;
if(line_x<10){
line_x=width;
}
}
function movingRandomFlower(){
fill(random(255),random(255),random(255)); //center circle color
ellipse(el_center_x,el_center_y,100,100); //center cirle
fill(random(255),random(255),random(255));
ellipse(el_center_x,el_center_y+el_sep_y,100,100); //up
fill(random(255),random(255),random(255));
ellipse(el_center_x,el_center_y-el_sep_y,100,100); //down
fill(random(255),random(255),random(255));
ellipse(el_center_x+el_sep_x,el_center_y,100,100); //left
fill(random(255),random(255),random(255));
ellipse(el_center_x-el_sep_x,el_center_y,100,100); //right
el_center_x=el_center_x+move_el_x;
el_center_y=el_center_y+move_el_y;
el_sep_y-=10; //make the flower petals move inwards
el_sep_x-=10;
if(el_sep_x<10){ //reset the petals to outwards
el_sep_x=200;
}
if(el_sep_y<10){
el_sep_y=200;
}
//idea thanks to https://funprogramming.org/15-Ball-bouncing-at-the-window-borders.html
if(el_center_x<0){
move_el_x= -move_el_x;
}
if(el_center_x>width){
move_el_x= -move_el_x;
}
if(el_center_y<0){
move_el_y= -move_el_y;
}
if(el_center_y>height){
move_el_y= -move_el_y;
}
}
//TODO, make more functions for moving patterns, like flowers and trees