-
Notifications
You must be signed in to change notification settings - Fork 0
/
sketch.js
70 lines (60 loc) · 1.82 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
var angle = 0;
var w = 30;
var ma;
var maxD;
var rotation = 0;
var DIMENSION = 600;
function setup() {
createCanvas(DIMENSION, DIMENSION, WEBGL);
ma = atan(cos(QUARTER_PI));
maxD = dist(0, 0, 200, 200);
// create sliders
rotateXSlider = createSlider(-ma, ma * 10, ma, 0.1);
rotateXSlider.position(20, DIMENSION + 20);
boxSizeSlider = createSlider(12, 150, 25, 1);
boxSizeSlider.position(20, DIMENSION + 40);
multiplierSlider = createSlider(0, 3, 1, 0.01);
multiplierSlider.position(20, DIMENSION + 60);
minHeightSlider = createSlider(1, DIMENSION, 100, 1);
minHeightSlider.position(20, DIMENSION + 80);
maxHeightSlider = createSlider(1, DIMENSION, 300, 1);
maxHeightSlider.position(20, DIMENSION + 100);
rotationSpeed = createSlider(0, 0.8, 0.005, 0.001);
rotationSpeed.position(20, DIMENSION + 120);
waveSpeed = createSlider(0, 0.5, 0.1, 0.001);
waveSpeed.position(20, DIMENSION + 140);
ambientLight(100, 80, 80);
pointLight(200, 200, 200, 100, 100, 100);
specularMaterial(100,255,0);
}
function draw() {
background(255,255,255);
rotation+=rotationSpeed.value();
rotation=rotation%180;
ortho(
DIMENSION,
-DIMENSION,
DIMENSION,
-DIMENSION,
0,
1000);
rotateX(rotateXSlider.value());
rotateY(rotation);
w = boxSizeSlider.value();
multipleir = multiplierSlider.value();
minH = minHeightSlider.value();
maxH = maxHeightSlider.value();
for (var z = 0; z < height; z += w) {
for (let x = 0; x < width; x += w) {
push();
var d = dist(x, z, width * 0.5, height * 0.5);
var offset = map(d, 0, maxD, -PI * multipleir, PI * multipleir);
var a = angle + offset;
var h = floor(map(sin(a), -1, 1, minH, maxH));
translate(x - width / 2, 0, z - height / 2);
box(w, h, w);
pop();
}
}
angle -= waveSpeed.value();
}