-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.py
57 lines (40 loc) · 1.17 KB
/
background.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
import turtle
from turtle import Turtle
# Constants
BACKGROUND_CORNER = 290
class BorderTurtle(Turtle):
def __init__(self):
"""Initialize the border turtle"""
super().__init__()
self.hideturtle()
# green field
self.fillcolor("#8AC847")
# brown borderline
self.pencolor("#6f4e37")
def draw_square(self, corner):
"""
Draw a filled square given corner coordinates
Args:
corner (int): positive number, sets xcor and ycor for corner points
"""
self.begin_fill()
x = corner
y = corner
# left down corner - initial position
self.teleport(-x, -y)
# right down corner
self.goto(x, -y)
# right up corner
self.goto(x, y)
# left up corner
self.goto(-x, y)
# left down corner - square is closed
self.goto(-x, -y)
self.end_fill()
class Background:
def __init__(self):
# make background light brown
turtle.bgcolor("#c19a6b")
# fill play field green
self.border_turtle = BorderTurtle()
self.border_turtle.draw_square(BACKGROUND_CORNER)