-
Notifications
You must be signed in to change notification settings - Fork 1
/
circle_of_boxes.py
107 lines (88 loc) · 2.44 KB
/
circle_of_boxes.py
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
"""
GENUARY 2021 - "2D Perspective"
Ram Narasimhan
Jan26 2021
"""
from datetime import datetime
bg_color = 20
def setup():
background(bg_color)
size(1000, 1000, P3D)
strokeWeight(3)
lights()
fov = PI / 3.0
cameraZ = (height / 2.0) / tan(fov / 2.0)
perspective(fov, float(width) / float(height), cameraZ / 2.0, cameraZ * 2.0)
num_pts = 12
a_step = TWO_PI / num_pts
rots = [
10 * a_step,
10 * a_step,
9.5 * a_step,
9 * a_step,
8.5 * a_step,
8 * a_step,
8 * a_step,
8 * a_step,
8 * a_step,
9 * a_step,
10 * a_step,
10 * a_step,
]
fill(108, 187, 60, 120) # green
fill(255, 216, 1, 120) # yellow
fill(181, 101, 30, 120) # brown
radius = 450
for c in range(num_pts):
theta = c * a_step
x = radius * cos(theta)
y = radius * sin(theta)
pushMatrix()
translate(width / 2 + x, height / 2 + y)
rotateY(rots[c]) # around the vertical Y axis
box(300, 120, 120)
popMatrix()
radius = 300
fill(250, 170, 160, 180)
for c in range(num_pts):
theta = c * a_step
x = radius * cos(theta)
y = radius * sin(theta)
pushMatrix()
translate(width / 2 + x, height / 2 + y)
rotateY(rots[c]) # around the vertical Y axis
box(200, 80, 80)
popMatrix()
radius = 200
fill(254, 64, 25, 200)
for c in range(num_pts):
theta = c * a_step
x = radius * cos(theta)
y = radius * sin(theta)
pushMatrix()
translate(width / 2 + x, height / 2 + y)
rotateY(rots[c]) # around the vertical Y axis
box(100, 40, 40)
popMatrix()
radius = 130
fill(254, 195, 11, 240)
for c in range(num_pts):
theta = c * a_step
x = radius * cos(theta)
y = radius * sin(theta)
pushMatrix()
translate(width / 2 + x, height / 2 + y)
rotateY(rots[c]) # around the vertical Y axis
box(80, 30, 30)
popMatrix()
fill(220, 200, 240)
ellipse(width / 2, height / 2, 50, 50)
draw_canvas_border(40, border_color=120)
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
titlestr = "boxes_"
save("frames/" + titlestr + timestamp + ".png")
def draw_canvas_border(grid_margin, border_color=255):
strokeWeight(grid_margin)
noFill()
stroke(border_color)
rect(0, 0, 990, 990)