-
Notifications
You must be signed in to change notification settings - Fork 0
/
dragon.py
91 lines (83 loc) · 1.85 KB
/
dragon.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
#STARTERS
import pygame, time, random, sys
pygame.init()
screen = pygame.display.set_mode([640,480])
screen.fill([255,255,255])
direction = 'north'
current = [0,0,1]
increment = 5
sleep = .0025
xx = 60
yy = 120-increment
plotPoints = [[xx,yy+increment],[xx,yy]]
#DIRECTIONS
def rightTurn():
global sleep
global increment
global direction
global xx
global yy
if direction == 'north':
xx += increment
direction = 'east'
elif direction == 'south':
xx -= increment
direction = 'west'
elif direction == 'west':
yy -= increment
direction = 'north'
elif direction == 'east':
yy += increment
direction = 'south'
plotPoints.append([xx,yy])
pygame.draw.lines(screen,[0,0,0],False,plotPoints,1)
pygame.display.flip()
time.sleep(sleep)
def leftTurn():
global sleep
global increment
global direction
global xx
global yy
if direction == 'north':
xx -= increment
direction = 'west'
elif direction == 'south':
xx += increment
direction = 'east'
elif direction == 'west':
yy += increment
direction = 'south'
elif direction == 'east':
yy -= increment
direction = 'north'
plotPoints.append([xx,yy])
pygame.draw.lines(screen,[0,0,0],False,plotPoints,1)
pygame.display.flip()
time.sleep(sleep)
#ITERATIONS
def Iterate():
global current
second = current[:]
second.reverse()
third = []
for element in second:
if element == 0:
third.append(1)
elif element == 1:
third.append(0)
current.append(0)
current.extend(third)
return current
for i in range(0,9):
Iterate()
for element in current:
if element == 0:
rightTurn()
elif element == 1:
leftTurn()
#EXIT
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()