-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathp5_script.js
112 lines (78 loc) · 1.72 KB
/
p5_script.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
let canvas;
const shapes = [];
let posX, posY;
let shape;
function windowResized() {
resizeCanvas(windowWidth, windowHeight);
}
function setup() {
canvas = createCanvas(windowWidth,windowHeight);
canvas.position(0,0);
canvas.style('z-index',-1);
posX = random(width);
posY = random(height);
}
function draw(){
background(50);
fill(20);
if(shapes.length <50) {
for (let i = 0; i < 50; i++) {
let c = new Shape();
shapes.push(c);
}
}
for(let i =0; i< shapes.length; i++) {
shapes[i].diam = 700;
shapes[i].update();
shapes[i].show(1);
}
fill(20);
rect(0,windowHeight*.015,width-windowWidth*0,height-windowHeight*0, 2);
}
class Shape {
constructor() {
//location
this.x = random(windowWidth*(1/4),windowWidth*(3/4));
this.y = random(windowHeight*(1/4),windowHeight*(3/4));
//this.x2 = this.x + 100;
//movement vectors
this.vx = random(-1,1);
this.vy = random(-1,1);
// colors
this.r = random(0,255);
this.g = random(0,255);
this.b = random(0,255)
// size
this.diam = random(10,50);
let temp = 0;
}
update() {
this.x += this.vx;
this.y += this.vy;
if(this.vx > 0) {
if (this.x >= (windowWidth)) {
this.vx = this.vx * -1;
}
}
if(this.vx < 0) {
if(this.x <= 0) {
this.vx = this.vx * -1;
}
}
if(this.vy > 0) {
if (this.y >= (windowHeight)) {
this.vy = this.vy * -1;
}
}
if(this.vy < 0) {
if(this.y <= 0) {
this.vy = this.vy * -1;
}
}
}
show() {
noStroke();
fill(this.r, this.g, this.b);
ellipse(this.x, this.y, this.diam);
}
}