can anyone help how to move the car to the traffic lights? and something is wrong with my traffics lights too..it does not seem to change the color after 5 sec..it just stay still?? and my stickfigure is not sticking with the face?? please help! i am using graphics.py
from graphics import *
import random
import time
# create the window/frame
w = 1090
h = 900
win = GraphWin("Late Night", w, h)
# first rectangle using corner x, y coordinates
upper_left = Point(0, 0)
lower_right = Point(1090, 900)
rect1 = Rectangle(upper_left, lower_right)
rect1.setFill('dark blue')
rect1.setWidth(0) # no border
rect1.draw(win)
# second rectangle using corner x, y coordinates
upper_left = Point(50, 300)
lower_right = Point(200, 890)
rect2 = Rectangle(upper_left, lower_right)
rect2.setFill('gray')
rect2.setWidth(5)
rect2.draw(win)
# third rectangle using corner x, y coordinates
upper_left = Point(310, 190)
lower_right = Point(490, 890)
rect3 = Rectangle(upper_left, lower_right)
rect3.setFill('gray')
rect3.setWidth(5)
rect3.draw(win)
# fourth rectangle using corner x, y coordinates
upper_left = Point(570, 190)
lower_right = Point(750, 890)
rect4 = Rectangle(upper_left, lower_right)
rect4.setFill('gray')
rect4.setWidth(5)
rect4.draw(win)
# fifth rectangle using corner x, y coordinates
upper_left = Point(830, 350)
lower_right = Point(1000, 890)
rect5 = Rectangle(upper_left, lower_right)
rect5.setFill('gray')
rect5.setWidth(5)
rect5.draw(win)
# circle needs center x, y coordinates and radius
c = Circle(Point(100,100), 80)
c.setFill('yellow')
c.draw(win)
# Make objects move
def lights(x,y,win):
'''draw yellow circle representing one light of a building.'''
lights=Circle(Point(x,y),5)
lights.setOutline("yellow")
lights.setFill("light yellow")
# Make objects move
for i in range(190):
'''turn lights on the windows of a buildings.'''
x=random.randrange(60,190)
y=random.randrange(310,900)
lights1=Circle(Point(x,y),5)
lights1.setOutline("yellow")
lights1.setFill("light yellow")
lights1.draw(win)
x=random.randrange(330,480)
y=random.randrange(200,900)
lights2=Circle(Point(x,y),5)
lights2.setOutline("yellow")
lights2.setFill("light yellow")
lights2.draw(win)
x=random.randrange(580,740)
y=random.randrange(200,900)
lights3=Circle(Point(x,y),5)
lights3.setOutline("yellow")
lights3.setFill("light yellow")
lights3.draw(win)
x=random.randrange(840,990)
y=random.randrange(360,900)
lights4=Circle(Point(x,y),5)
lights4.setOutline("yellow")
lights4.setFill("light yellow")
lights4.draw(win)
# circle needs center x, y coordinates and radius
c1 = Circle(Point(290,750), 10)
c2 = Circle(Point(350,750),10)
c3 = Circle(Point(650,750),15)
c4 = Circle(Point(550,750),15)
c1.setFill('black')
c1.draw(win)
c2.setFill('black')
c2.draw(win)
c3.setFill('black')
c3.draw(win)
c4.setFill('black')
c4.draw(win)
# six rectangle using corner x, y coordinates
upper_left = Point(250, 700)
lower_right = Point(400, 750)
rect6 = Rectangle(upper_left, lower_right)
rect6.setFill('red')
rect6.draw(win)
# seven rectangle using corner x, y coordinates
upper_left = Point(340, 655)
lower_right = Point(290, 701)
rect7 = Rectangle(upper_left, lower_right)
rect7.setFill('red')
rect7.draw(win)
# eight rectangle using corner x, y coordinates
upper_left = Point(330, 662)
lower_right = Point(300, 701)
rect8 = Rectangle(upper_left, lower_right)
rect8.setFill('black')
rect8.draw(win)
# ninth rectangle using corner x, y coordinates
upper_left = Point(680, 680)
lower_right = Point(500, 750)
rect9 = Rectangle(upper_left, lower_right)
rect9.setFill('green')
rect9.draw(win)
# tenth rectangle using corner x, y coordinates
upper_left = Point(679, 681)
lower_right = Point(610, 650)
rect10 = Rectangle(upper_left, lower_right)
rect10.setFill('green')
rect10.draw(win)
# circle needs center x, y coordinates and radius
c5 = Circle(Point(299,755), 10)
c6 = Circle(Point(359,755),10)
c7 = Circle(Point(659,759),15)
c8 = Circle(Point(559,759),15)
c5.setFill('black')
c5.draw(win)
c6.setFill('black')
c6.draw(win)
c7.setFill('black')
c7.draw(win)
c8.setFill('black')
c8.draw(win)
def trafficLights():
win = GraphWin()
red = Circle(Point(100, 50), 20)
red.setFill("black")
#
red.draw(win)
#
amber = Circle(Point(100, 100), 20)
#
amber.setFill("black")
#
amber.draw(win)
#
green = Circle(Point(100, 150), 20)
#
green.setFill("black")
#
green.draw(win)
#
while True:
#
import time
#
time.sleep(5)
def moveAll(shapeList, dx, dy):
for shape in shapeList:
shape.move(dx, dy)
def moveAllOnLine(shapeList, dx, dy, repetitions, delay):
for i in range(repetitions):
moveAll(shapeList, dx, dy)
time.sleep(delay)
def makeFace(center, win):
head = Circle(center, 5)
head.setFill("tan")
head.draw(win)
eye1Center = center.clone()
eye1Center.move(-3, 1)
eye1 = Circle(eye1Center, 1)
eye1.setFill('black')
eye1.draw(win)
eye2End1 = eye1Center.clone()
eye2End1.move(3.5, 0)
eye2End2 = eye2End1.clone()
eye2End2.move(3.5, 0)
eye2 = Line(eye2End1, eye2End2)
eye2.setWidth(3)
eye2.draw(win)
mouthCorner1 = center.clone()
mouthCorner1.move(-2, -2)
mouthCorner2 = mouthCorner1.clone()
mouthCorner2.move(5, -1)
mouth = Oval(mouthCorner1, mouthCorner2)
mouth.setFill("red")
mouth.draw(win)
return [head, eye1, eye2, mouth]
def drawFigure():
body = Line(Point(100, 80), Point(100, 120)).draw(win)
arms= Line(Point(60, 100), Point(140, 100)).draw(win)
leg1 = Line(Point(100,120), Point(60,160)).draw(win)
leg2 = Line(Point(100,120), Point(140,160)).draw(win)
drawFigure()
def main():
winWidth = 600
winHeight = 600
win.setCoords(0, 0, winWidth, winHeight) # make right side up coordinates!
faceList = makeFace(Point(150, 125), win) #NEW
faceList2 = makeFace(Point(150, 125), win) #NEW
stepsAcross = 8 #NEW section
dx = 5
dy = 3
wait = .05
offScreenJump = winWidth*2
for i in range(3):
moveAllOnLine(faceList, dx, 0, stepsAcross, wait)
moveAll(faceList2, offScreenJump, 0) # face 2 jumps off the screen
moveAllOnLine(faceList, -dx, dy, stepsAcross/2, wait)
moveAll(faceList2, -offScreenJump, 0) # face 2 jumps back on screen
moveAllOnLine(faceList, -dx, -dy, stepsAcross/2, wait)
Text(Point(winWidth/2, 20), 'Click anywhere to quit.').draw(win)
# wait, click mouse to go on/exit
#
win.getMouse()
#
win.close()
#
if __name__ == '__main__':
main()