-
Notifications
You must be signed in to change notification settings - Fork 0
/
artist.py
86 lines (68 loc) · 2.42 KB
/
artist.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
'''
This is the artist class that will be responsible for drawing the GUI for each
of the elements.
'''
import turtle
class Artist:
# Constructor
# Parameters: Takes in the radius for the GUI element
def __init__(self, r):
# TODO: Jin: I know it looks hacky, but it works on Spyder
turtle.colormode(255)
try:
self.artist = turtle.Turtle()
except:
self.artist = turtle.Turtle()
self.radius = r / 22 # Magical multiplier to get them correctly scaled
self.x_pos = 0
self.y_pos = 0
self.col = "black"
''' --------------Setters for build method (head)-------------- '''
def x_position(self, x):
self.x_pos = x
return self
def y_position(self, y):
self.y_pos = y
return self
def colour(self, colour):
self.col = colour
return self
''' --------------Setters for build method (tail)-------------- '''
# Method for drawing
# This method will always draw a circle filled in by that colour for a
# for a given position.
# Parameters:
# ...
def draw(self):
turtle.tracer(0, 0)
# fill in the colour
self.fill_colour()
# draw the body
self.draw_body()
# draw in other details if necessary
self.draw_detail()
turtle.update()
# Method for drawing the body of the element as a circle
def draw_body(self):
# draw the element itself as a circle
self.artist.penup()
self.artist.goto(self.x_pos, self.y_pos)
self.artist.pendown()
self.artist.shape("circle")
self.artist.shapesize(self.radius*2, self.radius*2)
# Method for filling in the colour of the element.
# This is a template method approach for Artist#draw() invoked at the start
# of the method
def fill_colour(self):
self.artist.fillcolor(self.col)
# Method for drawing in other necessary detail for the element.
# This is a template method approach for Artist#draw() invoked after the
# main body of the element is drawn.
# -- TO BE IMPLEMENTED BY CONCRETE CHILDREN CLASSES --
def draw_detail(self):
pass
def clear(self):
self.artist.clear()
def destroy(self):
turtle.turtles().remove(self.artist)
self.artist = None # Prevent turtle from being used anymore