-
Notifications
You must be signed in to change notification settings - Fork 0
/
draw.py
140 lines (109 loc) · 3.96 KB
/
draw.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import turtle
import time
from multiprocessing import Process
from multiprocessing import Queue
from typing import List, Tuple
from elevator import Elevator
# Create color choosing squares at the top of screen
colors = ["red", "orange", "yellow", "green", "blue", "indigo", "violet", "black", "#F9F9F9"]
class Window:
WIDTH = 1000
HEIGHT = 1000
def __init__(self, /, num_of_people: int, num_of_elevators: int = 1) -> None:
self.setup()
self.elevators: List[ElevatorShape] = []
self.draw_elevators(num_of_elevators)
self.people: List[PersonShape] = []
self.draw_people(num_of_people)
self.draw_agenda()
self.loop()
def __call__(self, queue):
self.queue = queue
def loop(self):
while True:
# self.screen.forward(1)
time.sleep(0.01)
# on exit turtle.done()
def draw_elevators(self, num_of_elevators: int):
x, y = (-400, -400)
for _ in range(num_of_elevators):
elevator = ElevatorShape(x, y, 3)
x += ElevatorShape.WIDTH # Move the next elevator to the right
self.elevators.append(elevator)
def draw_agenda(self):
pass
def draw_people(self, num_of_people: int):
x, y = (-400, 0)
for index in range(num_of_people):
person = PersonShape(x, y, "Josh", colors[index])
y += 20 # Height of a person
self.people.append(person)
new = self.people[0].screen.clone()
new.goto(-390, -390)
def draw(self):
pass
def setup(self) -> None:
turtle.setup(width=self.WIDTH, height=self.HEIGHT, startx=200, starty=200)
turtle.title("Elevators")
class Screen:
def __init__(self) -> None:
self.queue: Queue = Queue()
self.window = Window(num_of_elevators=3, num_of_people=2)
self.draw_process = Process(target=self.window, args=(self.queue,), daemon=True)
self.draw_process.start()
def draw(self, elevators: List[Elevator]) -> None:
pass
class ElevatorShape:
WIDTH = 100
FLOOR_HEIGHT = 100
def __init__(self, x: int, y: int, floors: int) -> None:
self.floors: int = floors
self.initial_x = x
self.initial_y = y
self.screen = turtle.Turtle()
self.screen.penup()
self.screen.goto(x, y)
self.screen.pendown()
self.screen.forward(self.WIDTH)
self.screen.left(90)
# Draw wall
for _ in range(self.floors):
self.screen.forward(self.FLOOR_HEIGHT)
self.screen.left(90)
self.screen.forward(self.WIDTH)
self.screen.left(90)
# Draw wall
for _ in range(self.floors):
self.screen.forward(self.FLOOR_HEIGHT)
self.draw_elevator()
def draw_elevator(self):
# TODO: Make into shapes
self.elevator = turtle.Shape('compound')
# https://stackoverflow.com/questions/47144177/how-do-i-move-a-turtle-graphics-drawn-object-using-only-built-in-functions
self.elevator = turtle.Turtle()
self.elevator.penup()
self.elevator.goto(self.initial_x, self.initial_y)
self.elevator.color("red")
self.elevator.pendown()
self.elevator.forward(self.WIDTH)
self.elevator.left(90)
self.elevator.forward(self.WIDTH)
self.elevator.left(90)
self.elevator.forward(self.WIDTH)
self.elevator.left(90)
self.elevator.forward(self.WIDTH)
self.elevator.left(90)
def move(self, move_vector: Tuple(int)):
pass
class PersonShape:
def __init__(self, x: int, y: int, name: str, color: str) -> None:
self.name = name
self.screen = turtle.Turtle(shape="turtle")
self.screen.color(color)
self.screen.penup()
self.screen.goto(x, y)
self.screen.write(f" {self.name}") # Extra spaces to align on the view
class Agenda:
pass
if __name__ == "__main__":
screen = Screen()