-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrectangle.py
53 lines (45 loc) · 1.53 KB
/
rectangle.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
"""
Riccardo Prosdocimi
CS 5001, Fall 2021
Final Project -- The Game: Puzzle Slider
This is a Rectangle class.
This makes drawing rectangles of various sizes and colors possible.
"""
import turtle
class Rectangle:
def __init__(self, x_coord, y_coord, width, height, size, color):
"""
This is the constructor of the Rectangle class.
:param x_coord: the rectangle's x coordinate on the screen (int)
:param y_coord: the rectangle's y coordinate on the screen (int)
:param width: the rectangle's width (int)
:param height: the rectangle's height (int)
:param size: the rectangle's border's size (int)
:param color: the rectangle's border's color (str)
"""
self.t = turtle.Turtle()
self.t.hideturtle()
self.t.penup()
self.t.speed(0)
self.x_coord = x_coord
self.y_coord = y_coord
self.width = width
self.height = height
self.size = size
self.color = color
def draw(self):
"""
This method draws/shows the rectangle on the screen.
"""
self.t.setpos(self.x_coord, self.y_coord)
self.t.pendown()
self.t.pencolor(self.color)
self.t.pensize(self.size)
self.t.forward(self.width)
self.t.right(90) # side 1
self.t.forward(self.height)
self.t.right(90) # side 2
self.t.forward(self.width)
self.t.right(90) # side 3
self.t.forward(self.height)
self.t.right(90) # side 4