-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathposter_05.js
More file actions
75 lines (68 loc) · 1.54 KB
/
poster_05.js
File metadata and controls
75 lines (68 loc) · 1.54 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
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
let cols = 10
let rows = 10
let boxSize = 20
let gap
let rotStep
let angle = 0
let fCubes = []
function setup() {
pixelDensity(2)
createCanvas(800, 800, WEBGL)
background(0)
stroke(255)
strokeWeight(2)
noFill()
gap = (width - boxSize * 3 - (boxSize * cols)) / (cols - 1)
ortho()
rotStep = PI / 120
for (let y = 0; y < rows; y++) {
for (let x = 0; x < cols; x++) {
push()
translate(-width / 2 + boxSize * 2 + boxSize * x + gap * x, 0, 0)
translate(0, -height / 2 + boxSize * 2 + boxSize * y + gap * y, 0)
let fCube = new FCube(boxSize)
fCube.randomize()
fCube.create()
fCubes.push(fCube)
pop()
}
}
}
function draw() {
background(0)
for (let y = 0; y < rows; y++) {
for (let x = 0; x < cols; x++) {
push()
translate(-width / 2 + boxSize * 2 + boxSize * x + gap * x, 0, 0)
translate(0, -height / 2 + boxSize * 2 + boxSize * y + gap * y, 0)
fCubes[y * cols + x].animate(angle)
pop()
}
}
angle += rotStep
}
class FCube {
constructor(size) {
this.size = size
this.rotX = random(-PI, PI)
this.rotY = random(-PI, PI)
this.rotZ = random(-PI, PI)
this.cdX = random([-1, 1])
this.cdY = random([-1, 1])
this.cdZ = random([-1, 1])
}
create() {
box(this.size)
}
randomize() {
rotateX(this.rotX)
rotateY(this.rotY)
rotateZ(this.rotZ)
}
animate(step) {
rotateX(this.rotX + step * this.cdX)
rotateY(this.rotY + step * this.cdY)
rotateZ(this.rotZ + step * this.cdZ)
box(this.size)
}
}