-
Notifications
You must be signed in to change notification settings - Fork 1
/
animation.py
95 lines (83 loc) · 2.31 KB
/
animation.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
from turtle import
def draw_shape(sides, length):
begin_fill()
for _ in range(sides):
forward(length)
right(360 / sides)
# fillcolor("green")
end_fill()
def draw_matrix(matrix):
color('yellow')
speed(100)
startX = -200
startY = 200
shapeSide = 50
for row in range(len(matrix)):
for col in range(len(matrix[row])):
cell = matrix[row][col]
if cell == 1:
fillcolor("blue")
elif cell == 2:
fillcolor("grey")
elif cell == 3:
fillcolor("green")
else:
fillcolor("black")
curX = startX + shapeSide * col
curY = startY - shapeSide * row
penup()
goto(curX, curY)
pendown()
draw_shape(4, shapeSide)
def draw_anime(arrayOfMatrix):
for matrix in arrayOfMatrix:
draw_matrix(matrix)
matrix1 = \
[
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 1, 1, 0, 0, 0],
[0, 0, 0, 1, 1, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0]
]
matrix2 = \
[
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 2, 2, 2, 2, 0, 0],
[0, 0, 2, 1, 1, 2, 0, 0],
[0, 0, 2, 1, 1, 2, 0, 0],
[0, 0, 2, 2, 2, 2, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0]
]
matrix3 = \
[
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 3, 3, 3, 3, 3, 3, 0],
[0, 3, 2, 2, 2, 2, 3, 0],
[0, 3, 2, 1, 1, 2, 3, 0],
[0, 3, 2, 1, 1, 2, 3, 0],
[0, 3, 2, 2, 2, 2, 3, 0],
[0, 3, 3, 3, 3, 3, 3, 0],
[0, 0, 0, 0, 0, 0, 0, 0]
]
matrix4 = \
[
[1, 1, 1, 1, 1, 1, 1, 1],
[1, 3, 3, 3, 3, 3, 3, 1],
[1, 3, 2, 2, 2, 2, 3, 1],
[1, 3, 2, 1, 1, 2, 3, 1],
[1, 3, 2, 1, 1, 2, 3, 1],
[1, 3, 2, 2, 2, 2, 3, 1],
[1, 3, 3, 3, 3, 3, 3, 1],
[1, 1, 1, 1, 1, 1, 1, 1]
]
smileAnime = [matrix1, matrix2, matrix3, matrix4]
setup(width=600, height=600, startx=0, starty=0)
hideturtle()
draw_anime(smileAnime)
exitonclick()