-
Notifications
You must be signed in to change notification settings - Fork 0
/
grid_flip.py
88 lines (70 loc) · 2.65 KB
/
grid_flip.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
"""
A dumb version of something I saw on JvR's lecture: https://vimeo.com/230514302
"""
from _lib.drawShapes import cRect
PAGESIZE = 500
CELLSIZE = 50
FRAMES = 10
TURNS = 8
ROWS = 8
COLS = 8
for turn in range(TURNS):
for frame in range(FRAMES+1):
f = frame / FRAMES
newPage(PAGESIZE, PAGESIZE)
#canvas
fill(1)
rect(0, 0, PAGESIZE, PAGESIZE)
#squares
translate(CELLSIZE/3, CELLSIZE/3) # margin
for row in range(ROWS):
save()
for col in range(COLS):
fill(1, col / COLS, row / ROWS, 1)
newPath()
if turn == 0:
moveTo((0, f * CELLSIZE))
lineTo((0, CELLSIZE))
lineTo((CELLSIZE, CELLSIZE))
lineTo((CELLSIZE, 0))
elif turn == 1:
moveTo((0, CELLSIZE))
lineTo((CELLSIZE, CELLSIZE))
lineTo((CELLSIZE, 0))
lineTo((CELLSIZE - f * CELLSIZE, 0))
elif turn == 2:
moveTo((f * CELLSIZE, CELLSIZE))
lineTo((CELLSIZE, CELLSIZE))
lineTo((CELLSIZE, 0))
lineTo((0, 0))
elif turn == 3:
moveTo((0, 0))
lineTo((0, f * CELLSIZE))
lineTo((CELLSIZE, CELLSIZE))
lineTo((CELLSIZE, 0))
elif turn == 4:
moveTo((0, 0))
lineTo((0, CELLSIZE))
lineTo((CELLSIZE, CELLSIZE - f * CELLSIZE))
lineTo((CELLSIZE, 0))
elif turn == 5:
moveTo((0, 0))
lineTo((0, CELLSIZE))
lineTo((f * CELLSIZE, CELLSIZE))
lineTo((CELLSIZE, 0))
elif turn == 6:
moveTo((0, 0))
lineTo((0, CELLSIZE))
lineTo((CELLSIZE, CELLSIZE))
lineTo((CELLSIZE - f * CELLSIZE, 0))
elif turn == 7:
moveTo((0, 0))
lineTo((0, CELLSIZE))
lineTo((CELLSIZE, CELLSIZE))
lineTo((CELLSIZE, CELLSIZE - f * CELLSIZE))
closePath()
drawPath()
translate(CELLSIZE * 1.1875, 0) # gutter between columns
restore()
translate(0, CELLSIZE * 1.1875) # gutter between rows
saveImage("_gifs/grid_flip.gif")