class Line(object):
def __init__(self, x0, y0, x1, y1, color, orientation, speed):
self.xc = x0
self.yc = y0
self.x0 = x0
self.x1 = x1
self.y0 = y0
self.y1 = y1
self.color = color
self.orientation = orientation
self.speed = speed
def move(self):
if self.orientation == "horizontal":
if self.xc < self.x1:
self.xc += self.speed
else:
self.xc = self.x0
elif self.orientation == "vertical":
if self.yc < self.y1:
self.yc += self.speed
else:
self.yc = self.y0
def init(data):
data.mode = False
data.grey = '#%02x%02x%02x' % (240, 241, 242)
data.maroon = '#%02x%02x%02x' % (176, 30, 40)
data.verticalLine1 = Line(10, 207, 15, 417, "black", "vertical", 2) #vertical line 1
data.verticalLine2 = Line(217, 0, 225, 625, "black", "vertical", 10) #vertical line 2
data.verticalLine3 = Line(330, 0, 338, 625, "black", "vertical", 6) #vertical line 3
data.horizontalLine1 = Line(0, 197, 490, 207, "black", "horizontal", 4) #horizontal line 1
data.horizontalLine2 = Line(0, 417, 490, 427, "black", "horizontal", 12) #horizontal line 2
data.lines = [data.verticalLine1, data.verticalLine2, data.verticalLine3, data.horizontalLine1, data.horizontalLine2]
def mousePressed(event, data):
pass
def keyPressed(event, data):
if data.mode == False:
data.mode = True
elif data.mode == True:
data.mode = False
def timerFired(data):
if data.mode == True:
for line in data.lines:
line.move()
def redrawAll(canvas, data):
canvas.create_rectangle(0, 0, 490, 625, fill = data.grey)
canvas.create_rectangle(0, 0, 217, 207, fill=data.maroon) #rectangle
canvas.create_rectangle(10, 207, 15, data.verticalLine1.yc, fill="black") #vertical line 1
canvas.create_rectangle(217, 0, 225, data.verticalLine2.yc, fill="black") #vertical line 2
canvas.create_rectangle(330, 0, 338, data.verticalLine3.yc, fill="black") #vertical line 3
canvas.create_rectangle(0, 197, data.horizontalLine1.xc, 207, fill="black") #horizontal line 1
canvas.create_rectangle(0, 417, data.horizontalLine2.xc, 427, fill="black") #horizontal line 2
Click to Expand
Content Rating
Is this a good/useful/informative piece of content to include in the project? Have your say!
You must login before you can post a comment. .