-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtry_perspective.py
80 lines (62 loc) · 1.71 KB
/
try_perspective.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
"""
GENUARY 2021 - "2D Perspective"
Ram Narasimhan
Jan26 2021
"""
from datetime import datetime
from math import sqrt
margin = 0
w, h, = 960, 960
wm, hm = w + 2 * margin, h + 2 * margin
pal = ["#264653", "#2a9d8f", "#e9c46a", "#f4a261", "#e76f51"]
def render_background():
ystep = 20
num = height / ystep
noStroke()
for ry in range(int(num)):
fill(ry, 31, 49, 150 - ry)
rect(0, ry * ystep, width, ystep)
th = 80
tw = th * sqrt(3) / 2
num_cols = int(w / tw)
num_rows = int(2 * h / th)
dots = []
for col in range(num_cols):
row_dots = []
for row in range(num_rows):
p = PVector()
xoffset = 0 if row % 2 else tw
x = col * tw * 2 + xoffset
y = row * th / 2
p.x, p.y = x, y
p.row, p.col = row, col
row_dots.append(p)
dots.append(row_dots)
bg_color = 25
def setup():
size(wm, hm, P3D) # including margin
# # background(bg_color)
# # noStroke()
# stroke(200)
# col3 = [10, 100, 200]
# Re-creates the default perspective
# size(100, 100, P3D)
lights()
fill("#ffc5c5")
fov = PI / 3.0
cameraZ = (height / 2.0) / tan(fov / 2.0)
perspective(fov, float(width) / float(height), cameraZ / 10.0, cameraZ * 10.0)
translate(width / 2, height * 0.75, 0)
rotateX(-PI / 6)
rotateY(PI / 6)
directionalLight(0, 255, 0, 0, -1, 0)
box(100)
# draw_canvas_border(40, border_color=bg_color)
# timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
# titlestr = "perspective_"
# save("frames/" + titlestr + timestamp + ".png")
def draw_canvas_border(grid_margin, border_color=255):
strokeWeight(grid_margin)
noFill()
stroke(border_color)
rect(0, 0, w, h)