-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrectangle.py
49 lines (35 loc) · 1.51 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
import math
from point import *
# Written by Ron Broner
# All rights reserved
class Rectangle():
# Initialize all variables needed to draw a rectangle
def __init__(self, canvas,x,y,width,height):
# Drawing surface canvas
self.canvas = canvas
# Coordinates of the top left corner of the rectangle
self.p = Point(x,y)
# Width and height of the rectangle
self.width = width
self.height = height
# Initialize the color of the rectangle to be white
self.color = 'white'
# Draw the rectangle object on the canvas
self.shape = canvas.create_rectangle(self.p.getPointCoords()[0],self.p.getPointCoords()[1],self.p.getPointCoords()[0]+self.width,self.p.getPointCoords()[1]+self.width,fill=self.color,outline="")
# Move the coordinates of the top left corner of the rectangle to (x,y)
def move(self,x,y):
self.p.setPoint(x,y)
# Change the width and height of the rectangle
def resize(self,width,height):
self.width = width
self.height = height
# Draw the rectangle object on the canvas given the current coordinates, width/height, and color
def draw(self):
self.canvas.coords(self.shape,self.p.getPointCoords()[0],self.p.getPointCoords()[1],self.p.getPointCoords()[0]+self.width,self.p.getPointCoords()[1]+self.height)
self.canvas.itemconfig(self.shape, fill=self.color)
# Hide the rectangle by setting all dimensions to 0
def hide(self):
self.canvas.coords(self.shape,0,0,0,0)
# Change the color profile of the rectangle
def changeColor(self,rgb):
self.color = "#%02x%02x%02x" % (rgb)