-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
49 lines (44 loc) · 1.06 KB
/
script.js
File metadata and controls
49 lines (44 loc) · 1.06 KB
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
let cubes = [];
function setup() {
createCanvas(windowWidth, windowHeight); ;
}
function mousePressed() {
let cubeSides = random(10, 75);
let r = random(255);
let g = random(255);
let b = random(255);
let strw = random(1, 6);
let newCube = new Cube(mouseX, mouseY, cubeSides, r, g, b, strw);
cubes.push(newCube);
}
function draw() {
background(0);
for (let i = 0; i < cubes.length; i++) {
cubes[i].move();
cubes[i].display();
}
}
function windowResized() {
resizeCanvas(windowWidth, windowHeight);
}
class Cube {
constructor(x, y, s, r, g, b, strw) {
this.x = x;
this.y = y;
this.s = s;
this.r = r;
this.g = g;
this.b = b;
this.strw = strw;
}
move() {
this.x += random(-1, 1);
this.y += random(-1, 1);
}
display() {
stroke(this.r,this.g,this.b);
strokeWeight(this.strw);
noFill();
square(this.x, this.y, this.s);
}
}