proyecto cruce con semaforos
en este proyecto se muestra el uso de los comando anteriormente usados agregando el uso de los pines de la raspberry mostrandolo tanto en fisico como en la pantalla con el modulo turtle
from turtle import*
import time
import random
from gpiozero import LED
green1=LED(17)
yellow1=LED(22)
red1=LED(27)
green2=LED(5)
yellow2=LED(6)
red2=LED(13)
green3=LED(24)
yellow3=LED(23)
red3=LED(18)
green4=LED(21)
yellow4=LED(20)
red4=LED(16)
t=Turtle()
s1=Turtle()
s2=Turtle()
s3=Turtle()
s4=Turtle()
c1=Turtle()
c2=Turtle()
c3=Turtle()
c4=Turtle()
c5=Turtle()
c6=Turtle()
c7=Turtle()
c8=Turtle()
c9=Turtle()
c10=Turtle()
c1.penup()
c2.penup()
c3.penup()
c4.penup()
c5.penup()
c6.penup()
c7.penup()
c8.penup()
c9.penup()
c10.penup()
#inicializacion de carros
c1.speed(0)
c1.shape("turtle")
c1.color("red")
c2.speed(0)
c2.shape("turtle")
c2.color("brown")
c3.speed(0)
c3.shape("turtle")
c3.color("orange")
c4.speed(0)
c4.shape("turtle")
c4.color("yellow")
c5.speed(0)
c5.shape("turtle")
c5.color("green")
c6.speed(0)
c6.shape("turtle")
c6.color("blue")
c7.speed(0)
c7.shape("turtle")
c7.color("purple")
c8.speed(0)
c8.shape("turtle")
c8.color("white")
c9.speed(0)
c9.shape("turtle")
c9.color("gold")
c10.speed(0)
c10.shape("turtle")
c10.color("silver")
screen=t.getscreen()
setup(800,800,0,0)
screensize(800,800)
t.speed(0)
#posicion de carros
c1.goto(-420,-25)
c1.speed(0)
c2.goto(-420,-75)
c2.speed(0)
c3.goto(-75,420)
c3.right(90)
c3.speed(0)
c4.goto(-25,420)
c4.right(90)
c4.speed(0)
c5.goto(420,75)
c5.right(180)
c5.speed(0)
c6.goto(420,25)
c6.right(180)
c6.speed(0)
c7.goto(25,-420)
c7.left(90)
c7.speed(0)
c8.goto(75,-420)
c8.left(90)
c8.speed(0)
c9.goto(-420,-25)
c9.speed(0)
c10.goto(-75,420)
c10.right(90)
c10.speed(0)
t.penup()
t.goto(-400,400)
t.pensize(7)
t.pendown()
t.fillcolor("green")
t.begin_fill()
t.goto(-400,400)
t.goto(400,400)
t.goto(400,-400)
t.goto(-400,-400)
t.end_fill()
t.fillcolor("gray")
t.penup()
t.goto(-400,100)
t.begin_fill()
pendown()
t.goto(-400,150)
t.goto(-150,150)
t.goto(-150,400)
t.goto(-100,400)
t.goto(-100,100)
t.goto(-400,100)
t.end_fill()
t.fillcolor("gray")
t.penup()
t.goto(400,100)
t.begin_fill()
pendown()
t.goto(400,150)
t.goto(150,150)
t.goto(150,400)
t.goto(100,400)
t.goto(100,100)
t.goto(400,100)
t.end_fill()
t.fillcolor("gray")
t.penup()
t.goto(-400,-100)
t.begin_fill()
pendown()
t.goto(-400,-150)
t.goto(-150,-150)
t.goto(-150,-400)
t.goto(-100,-400)
t.goto(-100,-100)
t.goto(-400,-100)
t.end_fill()
t.fillcolor("gray")
t.penup()
t.goto(400,100)
t.begin_fill()
pendown()
t.goto(400,-150)
t.goto(150,-150)
t.goto(150,-400)
t.goto(100,-400)
t.goto(100,-100)
t.goto(400,-100)
t.end_fill()
t.penup()
t.goto(-400,-100)
t.fillcolor("black")
t.begin_fill()
t.pendown()
t.goto(-400,100)
t.goto(-100,100)
t.goto(-100,400)
t.goto(100,400)
t.goto(100,100)
t.goto(400,100)
t.goto(400,-100)
t.goto(100,-100)
t.goto(100,-400)
t.goto(-100,-400)
t.goto(-100,-100)
t.goto(-400,-100)
t.end_fill()
t.penup()
t.pensize(5)
t.pencolor("white")
t.goto(-400,0)
for i in range (-400,-100,50):
t.pendown()
t.goto(i,0)
t.goto(i+25,0)
t.penup()
t.goto(i+25,0)
t.goto(i+50,0)
t.penup()
t.pensize(5)
t.pencolor("white")
t.goto(0,400)
for i in range (400,100,-50):
t.pendown()
t.goto(0,i)
t.goto(0,i-25)
t.penup()
t.goto(0,i-25)
t.goto(0,i-50)
t.penup()
t.pensize(5)
t.pencolor("white")
t.goto(400,0)
for i in range (400,100,-50):
t.pendown()
t.goto(i,0)
t.goto(i-25,0)
t.penup()
t.goto(i-25,0)
t.goto(i-50,0)
t.penup()
t.pensize(5)
t.pencolor("white")
t.goto(0,-400)
for i in range (-400,-100,50):
t.pendown()
t.goto(0,i)
t.goto(0,i+25)
t.penup()
t.goto(0,i+25)
t.goto(0,i+50)
t.penup()
t.pensize(7)
t.pencolor("yellow")
t.goto(-110,-100)
for i in range (-100,110,20):
t.pendown()
t.goto(-150,i)
t.penup()
t.goto(-110,i+20)
t.penup()
t.goto(-100,110)
for i in range (-100,110,20):
t.pendown()
t.goto(i,150)
t.penup()
t.goto(i+20,110)
t.penup()
t.goto(110,100)
for i in range (100,-110,-20):
t.pendown()
t.goto(150,i)
t.penup()
t.goto(110,i-20)
t.penup()
t.goto(100,-110)
for i in range (100,-110,-20):
t.pendown()
t.goto(i,-150)
t.penup()
t.goto(i-20,-110)
t.penup()
t.pencolor("white")
t.pensize(8)
t.goto (-100,-100)
t.pendown()
t.goto (-100,100)
t.goto (100,100)
t.goto (100,-100)
t.goto(-100,-100)
t.penup()
t.goto(-160,-100)
t.pendown()
t.goto(-160,100)
t.penup()
t.goto(-100,160)
t.pendown()
t.goto(100,160)
t.penup()
t.goto(160,100)
t.pendown()
t.goto(160,-100)
t.penup()
t.goto(100,-160)
t.pendown()
t.goto(-100,-160)
t.penup()
t.pensize(5)
t.goto(-250,-50)
t.pendown()
t.goto(-200,-50)
t.goto(-225,-38)
t.penup()
t.goto(-200,-50)
t.pendown()
t.goto(-225,-62)
t.penup()
t.pensize(5)
t.goto(50,-250)
t.pendown()
t.goto(50,-200)
t.goto(38,-225)
t.penup()
t.goto(50,-200)
t.pendown()
t.goto(62,-225)
t.penup()
t.pensize(5)
t.goto(250,50)
t.pendown()
t.goto(200,50)
t.goto(225,38)
t.penup()
t.goto(200,50)
t.pendown()
t.goto(225,62)
t.penup()
t.pensize(5)
t.goto(-50,250)
t.pendown()
t.goto(-50,200)
t.goto(-38,225)
t.penup()
t.goto(-50,200)
t.pendown()
t.goto(-62,225)
t.pensize(1)
t.pencolor("orange")
t.fillcolor("orange")
t.begin_fill()
t.penup()
t.goto(-180,80)
t.pendown()
t.goto(-200,80)
t.goto(-200,160)
t.goto(-180,160)
t.goto(-180,80)
t.end_fill()
t.pensize(1)
t.pencolor("orange")
t.fillcolor("orange")
t.begin_fill()
t.penup()
t.goto(-80,-180)
t.pendown()
t.goto(-80,-200)
t.goto(-160,-200)
t.goto(-160,-180)
t.goto(-80,-180)
t.end_fill()
t.pensize(1)
t.pencolor("orange")
t.fillcolor("orange")
t.begin_fill()
t.penup()
t.goto(80,180)
t.pendown()
t.goto(80,200)
t.goto(160,200)
t.goto(160,180)
t.goto(80,180)
t.end_fill()
t.pensize(1)
t.pencolor("orange")
t.fillcolor("orange")
t.begin_fill()
t.penup()
t.goto(180,-80)
t.pendown()
t.goto(200,-80)
t.goto(200,-160)
t.goto(180,-160)
t.goto(180,-80)
t.end_fill()
t.hideturtle()
s1.speed(0)
s2.speed(0)
s3.speed(0)
s4.speed(0)
s1.penup()
s2.penup()
s3.penup()
s4.penup()
s1.hideturtle()
s2.hideturtle()
s3.hideturtle()
s4.hideturtle()
s1.goto(-190,140)
s1.dot(10,"green")#semaforo 1
green1.on()
s4.goto(190,-140)
s4.dot(10,"green")#semaforo 4
green4.on()
s2.goto(-100,-190)
s2.dot(10,"red")#semaforo 2
red2.on()
s3.goto(100,190)
s3.dot(10,"red")#semaforo 3
red3.on()
s1.goto(-190,100)
s1.dot(10,"black")#semaforo 1
yellow1.off()
s1.goto(-190,120)
s1.dot(10,"black")#semaforo 1
red1.off()
s4.goto(190,-100)
s4.dot(10,"black")#semaforo 4
yellow4.off()
s4.goto(190,-120)
s4.dot(10,"black")#semafor 4
red4.off()
s2.goto(-120,-190)
s2.dot(10,"black")#semaforo 2
green2.off()
s2.goto(-140,-190)
s2.dot(10,"black")#semaforo 2
yellow2.off()
s3.goto(120,190)
s3.dot(10,"black")#semaforo 3
green3.off()
s3.goto(140,190)
s3.dot(10,"black")#semaforo 3
yellow3.off()
while(True):
s1.goto(-190,140)
s1.dot(10,"green")#semaforo 1
green1.on()
s4.goto(190,-140)
s4.dot(10,"green")#semaforo 4
green4.on()
s2.goto(-100,-190)
s2.dot(10,"red")#semaforo 2
red2.on()
s3.goto(100,190)
s3.dot(10,"red")#semaforo 3
red3.on()
s1.goto(-190,100)
s1.dot(10,"black")#semaforo 1
yellow1.off()
s1.goto(-190,120)
s1.dot(10,"black")#semaforo 1
red1.off()
s4.goto(190,-100)
s4.dot(10,"black")#semaforo 4
yellow4.off()
s4.goto(190,-120)
s4.dot(10,"black")#semafor 4
red4.off()
s2.goto(-120,-190)
s2.dot(10,"black")#semaforo 2
green2.off()
s2.goto(-140,-190)
s2.dot(10,"black")#semaforo 2
yellow2.off()
s3.goto(120,190)
s3.dot(10,"black")#semaforo 3
green3.off()
s3.goto(140,190)
s3.dot(10,"black")#semaforo 3
yellow3.off()
#time.sleep(3)
num=random.randint(1,5)
c1.goto(-420,-25)
c1.speed(0)
c2.goto(-420,-75)
c2.speed(0)
c3.goto(-75,420)
c3.speed(0)
c4.goto(-25,420)
c4.speed(0)
c5.goto(420,75)
c5.speed(0)
c6.goto(420,25)
c6.speed(0)
c7.goto(25,-420)
c7.speed(0)
c8.goto(75,-420)
c8.speed(0)
c9.goto(-420,-25)
c9.speed(0)
c10.goto(-75,420)
c10.speed(0)
c1.showturtle()
c2.showturtle()
c3.showturtle()
c4.showturtle()
c5.showturtle()
c6.showturtle()
c7.showturtle()
c8.showturtle()
c9.showturtle()
c10.showturtle()
c1.speed(1)
c2.speed(1)
c3.speed(1)
c4.speed(1)
c5.speed(1)
c6.speed(1)
c7.speed(1)
c8.speed(1)
c9.speed(1)
c10.speed(1)
if (num==1):
s1.goto(-190,140)
s1.dot(10,"green")#semaforo 1
green1.on()
s4.goto(190,-140)
s4.dot(10,"green")#semaforo 4
green4.on()
c1.goto(425,-25)#
c5.goto(-420,75)
c6.goto(-420,25)
s2.goto(-100,-190)
s2.dot(10,"red")#semaforo 2
red2.on()
s3.goto(100,190)
s3.dot(10,"red")#semaforo 3
red3.on()
c10.goto(-75,190)#
c7.goto(25,-190)
s1.goto(-190,100)
s1.dot(10,"black")#semaforo 1
yellow1.off()
s1.goto(-190,120)
s1.dot(10,"black")#semaforo 1
red1.off()
s4.goto(190,-100)
s4.dot(10,"black")#semaforo 4
yellow4.off()
s4.goto(190,-120)
s4.dot(10,"black")#semafor 4
red4.off()
s2.goto(-120,-190)
s2.dot(10,"black")#semaforo 2
green2.off()
s2.goto(-140,-190)
s2.dot(10,"black")#semaforo 2
yellow2.off()
s3.goto(120,190)
s3.dot(10,"black")#semaforo 3
green3.off()
s3.goto(140,190)
s3.dot(10,"black")#semaforo 3
yellow3.off()
time.sleep(0)
for i in range (3):
s1.goto(-190,140)
s1.dot(10,"green")#semaforo 1
green1.on()
s4.goto(190,-140)
s4.dot(10,"green")#semaforo 4
green4.on()
time.sleep(.5)
s1.goto(-190,140)
s1.dot(10,"black")#semaforo 1
green1.off()
s4.goto(190,-140)
s4.dot(10,"black")#semaforo 4
green4.off()
s1.goto(-190,140)
s1.dot(10,"black")
green1.off()
s4.goto(190,-140)
s4.dot(10,"black")
green4.off()
s1.goto(-190,120)
s1.dot(10,"yellow")
yellow1.on()
s4.goto(190,-120)
s4.dot(10,"yellow")
yellow4.on()
time.sleep(2)
s1.goto(-190,120)
s1.dot(10,"black")
yellow1.off()
s4.goto(190,-120)
s4.dot(10,"black")
yellow4.off()
s2.goto(-120,-190)
s2.dot(10,"black")#semaforo 2
yellow2.off()
s2.goto(-100,-190)
s2.dot(10,"black")#semaforo 2
red2.off()
s3.goto(120,190)
s3.dot(10,"black")#semaforo 3
yellow3.off()
s3.goto(100,190)
s3.dot(10,"black")#semafor 3
red3.off()
s2.goto(-140,-190)
s2.dot(10,"green")#semaforo 2
green2.on()
s4.goto(140,190)
s4.dot(10,"green")#semaforo 3
green3.on()
s1.goto(-190,100)
s1.dot(10,"red")#semaforo 1
red1.on()
s4.goto(190,-100)
s4.dot(10,"red")#semaforo 4
red4.on()
s1.goto(-190,120)
s1.dot(10,"black")#semaforo 1
yellow1.off()
s1.goto(-190,140)
s1.dot(10,"black")#semaforo 1
green1.off()
s4.goto(190,-120)
s4.dot(10,"black")#semaforo 4
yellow4.off()
s4.goto(190,-140)
s4.dot(10,"black")#semaforo 4
green4.off()
c10.speed(5)#
c7.speed(5)
c10.goto(-75,0)
c7.goto(25,0)
c10.goto(-75,-100)
c7.goto(25,100)
c10.goto(-75,-200)
c7.goto(25,200)
c10.goto(-75,-300)
c7.goto(25,300)
c10.goto(-75,-420)
c7.goto(25,420)
time.sleep(0)
for i in range (3):
s2.goto(-140,-190)
s2.dot(10,"green")#semaforo 2
green2.on()
s3.goto(140,190)
s3.dot(10,"green")#semaforo 3
green3.on()
time.sleep(.5)
s2.goto(-140,-190)
s2.dot(10,"black")#semaforo 2
green2.off()
s3.goto(140,190)
s3.dot(10,"black")#semaforo 3
green3.off()
s2.goto(-140,-190)
s2.dot(10,"black")
green2.off()
s3.goto(140,190)
s3.dot(10,"black")
green3.off()
s2.goto(-120,-190)
s2.dot(10,"yellow")
yellow2.on()
s3.goto(120,190)
s3.dot(10,"yellow")
yellow3.on()
time.sleep(2)
s2.goto(-120,-190)
s2.dot(10,"black")
yellow2.off()
s3.goto(120,190)
s3.dot(10,"black")
yellow3.off()
c1.hideturtle()
c2.hideturtle()
c3.hideturtle()
c4.hideturtle()
c5.hideturtle()
c6.hideturtle()
c7.hideturtle()
c8.hideturtle()
c9.hideturtle()
c10.hideturtle()
elif(num==2):
s1.goto(-190,140)
s1.dot(10,"green")#semaforo 1
green1.on()
s4.goto(190,-140)
s4.dot(10,"green")#semaforo 4
green4.on()
c2.speed(5)#
c5.speed(5)
c2.goto(-300,-75)
c5.goto(300,75)
c2.goto(-200,-75)
c5.goto(200,75)
c2.goto(-100,-75)
c5.goto(100,75)
c2.goto(0,-75)
c5.goto(0,75)
c2.goto(100,-75)
c5.goto(-100,75)
c2.goto(200,-75)
c5.goto(-200,75)
c2.goto(300,-75)
c5.goto(-300,75)
c2.goto(420,-75)
c5.goto(-420,75)
s2.goto(-100,-190)
s2.dot(10,"red")#semaforo 2
red2.on()
s3.goto(100,190)
s3.dot(10,"red")#semaforo 3
red3.on()
c10.goto(-75,190)#
c7.goto(25,-190)
s1.goto(-190,100)
s1.dot(10,"black")#semaforo 1
red1.off()
s1.goto(-190,120)
s1.dot(10,"black")#semaforo 1
yellow1.off()
s4.goto(190,-100)
s4.dot(10,"black")#semaforo 4
red4.off()
s4.goto(190,-120)
s4.dot(10,"black")#semafor 4
yellow4.off()
s2.goto(-120,-190)
s2.dot(10,"black")#semaforo 2
yellow2.off()
s2.goto(-140,-190)
s2.dot(10,"black")#semaforo 2
green2.off()
s3.goto(120,190)
s3.dot(10,"black")#semaforo 3
yellow3.off()
s3.goto(140,190)
s3.dot(10,"black")#semaforo 3
green3.off()
time.sleep(0)
for i in range (3):
s1.goto(-190,140)
s1.dot(10,"green")#semaforo 1
green1.on()
s4.goto(190,-140)
s4.dot(10,"green")#semaforo 4
green4.on()
time.sleep(.5)
s1.goto(-190,140)
s1.dot(10,"black")#semaforo 1
green1.off()
s4.goto(190,-140)
s4.dot(10,"black")#semaforo 4
green4.off()
s1.goto(-190,140)
s1.dot(10,"black")
green1.off()
s4.goto(190,-140)
s4.dot(10,"black")
green4.off()
s1.goto(-190,120)
s1.dot(10,"yellow")
yellow1.on()
s4.goto(190,-120)
s4.dot(10,"yellow")
yellow4.on()
time.sleep(2)
s1.goto(-190,120)
s1.dot(10,"black")
yellow1.off()
s4.goto(190,-120)
s4.dot(10,"black")
yellow4.off()
s2.goto(-120,-190)
s2.dot(10,"black")#semaforo 2
yellow2.off()
s2.goto(-100,-190)
s2.dot(10,"black")#semaforo 2
red2.off()
s3.goto(120,190)
s3.dot(10,"black")#semaforo 3
yellow3.off()
s3.goto(100,190)
s3.dot(10,"black")#semafor 3
red3.off()
s2.goto(-140,-190)
s2.dot(10,"green")#semaforo 2
green2.on()
s4.goto(140,190)
s4.dot(10,"green")#semaforo 3
green3.on()
c10.speed(5)#
c7.speed(5)
c10.goto(-75,0)
c7.goto(25,0)
c10.goto(-75,-100)
c7.goto(25,100)
c10.goto(-75,-200)
c7.goto(25,200)
c10.goto(-75,-300)
c7.goto(25,300)
c10.goto(-75,-420)
c7.goto(25,420)
s1.goto(-190,100)
s1.dot(10,"red")#semaforo 1
red1.on()
s4.goto(190,-100)
s4.dot(10,"red")#semaforo 4
red4.on()
s1.goto(-190,120)
s1.dot(10,"black")#semaforo 1
yellow1.off()
s1.goto(-190,140)
s1.dot(10,"black")#semaforo 1
green1.off()
s4.goto(190,-120)
s4.dot(10,"black")#semaforo 4
yellow4.off()
s4.goto(190,-140)
s4.dot(10,"black")#semaforo 4
green4.off()
time.sleep(3)
for i in range (3):
s2.goto(-140,-190)
s2.dot(10,"green")#semaforo 2
green2.on()
s3.goto(140,190)
s3.dot(10,"green")#semaforo 3
green3.on()
time.sleep(.5)
s2.goto(-140,-190)
s2.dot(10,"black")#semaforo 2
green2.off()
s3.goto(140,190)
s3.dot(10,"black")#semaforo 3
green3.off()
s2.goto(-140,-190)
s2.dot(10,"black")
green2.off()
s3.goto(140,190)
s3.dot(10,"black")
green3.off()
s2.goto(-120,-190)
s2.dot(10,"yellow")
yellow2.on()
s3.goto(120,190)
s3.dot(10,"yellow")
yellow3.on()
time.sleep(2)
s2.goto(-120,-190)
s2.dot(10,"black")
yellow2.off()
s3.goto(120,190)
s3.dot(10,"black")
yellow3.off()
c1.hideturtle()
c2.hideturtle()
c3.hideturtle()
c4.hideturtle()
c5.hideturtle()
c6.hideturtle()
c7.hideturtle()
c8.hideturtle()
c9.hideturtle()
c10.hideturtle()
elif(num==3):
s1.goto(-190,140)
s1.dot(10,"green")#semaforo 1
green1.on()
s4.goto(190,-140)
s4.dot(10,"green")#semaforo 4
green4.on()
c8.speed(5)#
c9.speed(5)
c9.goto(-300,-25)
c8.goto(75,-300)
c9.goto(-200,-25)
c8.goto(75,-200)
c9.goto(-100,-25)
c8.goto(75,-190)
c9.goto(0,-25)
c9.goto(100,-25)
c9.goto(200,-25)
c9.goto(300,-25)
c9.goto(420,-25)
s2.goto(-100,-190)
s2.dot(10,"red")#semaforo 2
red2.on()
s3.goto(100,190)
s3.dot(10,"red")#semaforo 3
red3.on()
c10.goto(-75,190)#
s1.goto(-190,100)
s1.dot(10,"black")#semaforo 1
red1.off()
s1.goto(-190,120)
s1.dot(10,"black")#semaforo 1
yellow1.off()
s4.goto(190,-100)
s4.dot(10,"black")#semaforo 4
red4.off()
s4.goto(190,-120)
s4.dot(10,"black")#semafor 4
yellow4.off()
s2.goto(-120,-190)
s2.dot(10,"black")#semaforo 2
yellow2.off()
s2.goto(-140,-190)
s2.dot(10,"black")#semaforo 2
green2.off()
s3.goto(120,190)
s3.dot(10,"black")#semaforo 3
yellow3.off()
s3.goto(140,190)
s3.dot(10,"black")#semaforo 3
green3.off()
time.sleep(0)
for i in range (3):
s1.goto(-190,140)
s1.dot(10,"green")#semaforo 1
green1.on()
s4.goto(190,-140)
s4.dot(10,"green")#semaforo 4
green4.on()
time.sleep(.5)
s1.goto(-190,140)
s1.dot(10,"black")#semaforo 1
green1.off()
s4.goto(190,-140)
s4.dot(10,"black")#semaforo 4
green4.off()
s1.goto(-190,140)
s1.dot(10,"black")
green1.off()
s4.goto(190,-140)
s4.dot(10,"black")
green4.off()
s1.goto(-190,120)
s1.dot(10,"yellow")
yellow1.on()
s4.goto(190,-120)
s4.dot(10,"yellow")
yellow4.on()
time.sleep(2)
s1.goto(-190,120)
s1.dot(10,"black")
yellow1.off()
s4.goto(190,-120)
s4.dot(10,"black")
yellow4.off()
s2.goto(-120,-190)
s2.dot(10,"black")#semaforo 2
yellow2.off()
s2.goto(-100,-190)
s2.dot(10,"black")#semaforo 2
red2.off()
s3.goto(120,190)
s3.dot(10,"black")#semaforo 3
yellow3.off()
s3.goto(100,190)
s3.dot(10,"black")#semafor 3
red3.off()
s2.goto(-140,-190)
s2.dot(10,"green")#semaforo 2
green2.on()
s4.goto(140,190)
s4.dot(10,"green")#semaforo 3
green3.on()
s1.goto(-190,100)
s1.dot(10,"red")#semaforo 1
red1.on()
s4.goto(190,-100)
s4.dot(10,"red")#semaforo 4
red4.on()
s1.goto(-190,120)
s1.dot(10,"black")#semaforo 1
yellow1.off()
s1.goto(-190,140)
s1.dot(10,"black")#semaforo 1
green1.off()
s4.goto(190,-120)
s4.dot(10,"black")#semaforo 4
yellow4.off()
s4.goto(190,-140)
s4.dot(10,"black")#semaforo 4
green4.off()
c10.speed(5)#
c8.speed(5)
c10.goto(-75,0)
c8.goto(25,0)
c10.goto(-75,-100)
c8.goto(25,100)
c10.goto(-75,-200)
c8.goto(25,200)
c10.goto(-75,-300)
c8.goto(25,300)
c10.goto(-75,-420)
c8.goto(25,420)
time.sleep(0)
for i in range (3):
s2.goto(-140,-190)
s2.dot(10,"green")#semaforo 2
green2.on()
s3.goto(140,190)
s3.dot(10,"green")#semaforo 3
green3.on()
time.sleep(.5)
s2.goto(-140,-190)
s2.dot(10,"black")#semaforo 2
green2.off()
s3.goto(140,190)
s3.dot(10,"black")#semaforo 3
green3.off()
s2.goto(-140,-190)
s2.dot(10,"black")
green2.off()
s3.goto(140,190)
s3.dot(10,"black")
green3.off()
s2.goto(-120,-190)
s2.dot(10,"yellow")
yellow2.on()
s3.goto(120,190)
s3.dot(10,"yellow")
yellow3.on()
time.sleep(2)
s2.goto(-120,-190)
s2.dot(10,"black")
yellow2.off()
s3.goto(120,190)
s3.dot(10,"black")
yellow3.off()
c1.hideturtle()
c2.hideturtle()
c3.hideturtle()
c4.hideturtle()
c5.hideturtle()
c6.hideturtle()
c7.hideturtle()
c8.hideturtle()
c9.hideturtle()
c10.hideturtle()
elif(num==4):
s1.goto(-190,140)
s1.dot(10,"green")#semaforo 1
green1.on()
s4.goto(190,-140)
s4.dot(10,"green")#semaforo 4
green4.on()
c8.speed(5)#
c9.speed(5)
c9.goto(-300,-25)
c8.goto(75,-300)
c9.goto(-200,-25)
c8.goto(75,-200)
c9.goto(-100,-25)
c8.goto(75,-190)
c9.goto(0,-25)
c9.goto(100,-25)
c9.goto(200,-25)
c9.goto(300,-25)
c9.goto(420,-25)
s2.goto(-100,-190)
s2.dot(10,"red")#semaforo 2
red2.on()
s3.goto(100,190)
s3.dot(10,"red")#semaforo 3
red3.on()
c10.goto(-75,190)#
s1.goto(-190,100)
s1.dot(10,"black")#semaforo 1
red1.off()
s1.goto(-190,120)
s1.dot(10,"black")#semaforo 1
yellow1.off()
s4.goto(190,-100)
s4.dot(10,"black")#semaforo 4
red4.off()
s4.goto(190,-120)
s4.dot(10,"black")#semafor 4
yellow4.off()
s2.goto(-120,-190)
s2.dot(10,"black")#semaforo 2
yellow2.off()
s2.goto(-140,-190)
s2.dot(10,"black")#semaforo 2
green2.off()
s3.goto(120,190)
s3.dot(10,"black")#semaforo 3
yellow3.off()
s3.goto(140,190)
s3.dot(10,"black")#semaforo 3
green3.off()
time.sleep(0)
for i in range (3):
s1.goto(-190,140)
s1.dot(10,"green")#semaforo 1
green1.on()
s4.goto(190,-140)
s4.dot(10,"green")#semaforo 4
green4.on()
time.sleep(.5)
s1.goto(-190,140)
s1.dot(10,"black")#semaforo 1
green1.off()
s4.goto(190,-140)
s4.dot(10,"black")#semaforo 4
green4.off()
s1.goto(-190,140)
s1.dot(10,"black")
green1.off()
s4.goto(190,-140)
s4.dot(10,"black")
green4.off()
s1.goto(-190,120)
s1.dot(10,"yellow")
yellow1.on()
s4.goto(190,-120)
s4.dot(10,"yellow")
yellow4.on()
time.sleep(2)
s1.goto(-190,120)
s1.dot(10,"black")
yellow1.off()
s4.goto(190,-120)
s4.dot(10,"black")
yellow4.off()
s2.goto(-120,-190)
s2.dot(10,"black")#semaforo 2
yellow2.off()
s2.goto(-100,-190)
s2.dot(10,"black")#semaforo 2
red2.off()
s3.goto(120,190)
s3.dot(10,"black")#semaforo 3
yellow3.off()
s3.goto(100,190)
s3.dot(10,"black")#semafor 3
red3.off()
s2.goto(-140,-190)
s2.dot(10,"green")#semaforo 2
green2.on()
s4.goto(140,190)
s4.dot(10,"green")#semaforo 3
green3.on()
s1.goto(-190,100)
s1.dot(10,"red")#semaforo 1
red1.on()
s4.goto(190,-100)
s4.dot(10,"red")#semaforo 4
red4.on()
s1.goto(-190,120)
s1.dot(10,"black")#semaforo 1
yellow1.off()
s1.goto(-190,140)
s1.dot(10,"black")#semaforo 1
green1.off()
s4.goto(190,-120)
s4.dot(10,"black")#semaforo 4
yellow4.off()
s4.goto(190,-140)
s4.dot(10,"black")#semaforo 4
green4.off()
c10.speed(5)#
c8.speed(5)
c10.goto(-75,0)
c8.goto(25,0)
c10.goto(-75,-100)
c8.goto(25,100)
c10.goto(-75,-200)
c8.goto(25,200)
c10.goto(-75,-300)
c8.goto(25,300)
c10.goto(-75,-420)
c8.goto(25,420)
time.sleep(0)
for i in range (3):
s2.goto(-140,-190)
s2.dot(10,"green")#semaforo 2
green2.on()
s3.goto(140,190)
s3.dot(10,"green")#semaforo 3
green3.on()
time.sleep(.5)
s2.goto(-140,-190)
s2.dot(10,"black")#semaforo 2
green2.off()
s3.goto(140,190)
s3.dot(10,"black")#semaforo 3
green3.off()
s2.goto(-140,-190)
s2.dot(10,"black")
green2.off()
s3.goto(140,190)
s3.dot(10,"black")
green3.off()
s2.goto(-120,-190)
s2.dot(10,"yellow")
yellow2.on()
s3.goto(120,190)
s3.dot(10,"yellow")
yellow3.on()
time.sleep(2)
s2.goto(-120,-190)
s2.dot(10,"black")
yellow2.off()
s3.goto(120,190)
s3.dot(10,"black")
yellow3.off()
c1.hideturtle()
c2.hideturtle()
c3.hideturtle()
c4.hideturtle()
c5.hideturtle()
c6.hideturtle()
c7.hideturtle()
c8.hideturtle()
c9.hideturtle()
c10.hideturtle()
else:
s1.goto(-190,140)
s1.dot(10,"green")#semaforo 1
green1.on()
s4.goto(190,-140)
s4.dot(10,"green")#semaforo 4
green4.on()
c3.speed(5)#
c4.speed(5)
c10.speed(5)
c3.goto(-75,190)
c4.goto(-25,190)
c10.goto(-25,220)
s2.goto(-100,-190)
s2.dot(10,"red")#semaforo 2
red2.on()
s3.goto(100,190)
s3.dot(10,"red")#semaforo 3
red3.on()
c5.goto(-420,75)#
s1.goto(-190,100)
s1.dot(10,"black")#semaforo 1
red1.off()
s1.goto(-190,120)
s1.dot(10,"black")#semaforo 1
yellow1.off()
s4.goto(190,-100)
s4.dot(10,"black")#semaforo 4
red4.off()
s4.goto(190,-120)
s4.dot(10,"black")#semafor 4
yellow4.off()
s2.goto(-120,-190)
s2.dot(10,"black")#semaforo 2
yellow2.off()
s2.goto(-140,-190)
s2.dot(10,"black")#semaforo 2
green2.off()
s3.goto(120,190)
s3.dot(10,"black")#semaforo 3
yellow3.off()
s3.goto(140,190)
s3.dot(10,"black")#semaforo 3
green3.off()
time.sleep(0)
for i in range (3):
s1.goto(-190,140)
s1.dot(10,"green")#semaforo 1
green1.on()
s4.goto(190,-140)
s4.dot(10,"green")#semaforo 4
green4.on()
time.sleep(.5)
s1.goto(-190,140)
s1.dot(10,"black")#semaforo 1
green1.off()
s4.goto(190,-140)
s4.dot(10,"black")#semaforo 4
green4.off()
s1.goto(-190,140)
s1.dot(10,"black")
green1.off()
s4.goto(190,-140)
s4.dot(10,"black")
green4.off()
s1.goto(-190,120)
s1.dot(10,"yellow")
yellow1.on()
s4.goto(190,-120)
s4.dot(10,"yellow")
yellow4.on()
time.sleep(2)
s1.goto(-190,120)
s1.dot(10,"black")
yellow1.off()
s4.goto(190,-120)
s4.dot(10,"black")
yellow4.off()
s2.goto(-120,-190)
s2.dot(10,"black")#semaforo 2
yellow2.off()
s2.goto(-100,-190)
s2.dot(10,"black")#semaforo 2
red2.off()
s3.goto(120,190)
s3.dot(10,"black")#semaforo 3
yellow3.off()
s3.goto(100,190)
s3.dot(10,"black")#semafor 3
red3.off()
s2.goto(-140,-190)
s2.dot(10,"green")#semaforo 2
green2.on()
s4.goto(140,190)
s4.dot(10,"green")#semaforo 3
green3.on()
s1.goto(-190,100)
s1.dot(10,"red")#semaforo 1
red1.on()
s4.goto(190,-100)
s4.dot(10,"red")#semaforo 4
red4.on()
s1.goto(-190,120)
s1.dot(10,"black")#semaforo 1
yellow1.off()
s1.goto(-190,140)
s1.dot(10,"black")#semaforo 1
green1.off()
s4.goto(190,-120)
s4.dot(10,"black")#semaforo 4
yellow4.off()
s4.goto(190,-140)
s4.dot(10,"black")#semaforo 4
green4.off()
c3.speed(5)#
c4.speed(5)
c10.speed(5)
c3.goto(-75,100)
c4.goto(-25,100)
c10.goto(-75,130)
c3.goto(-75,0)
c4.goto(-25,0)
c10.goto(-75,-30)
c3.goto(-75,-100)
c4.goto(-25,-100)
c10.goto(-75,-70)
c3.goto(-75,-200)
c4.goto(-25,-200)
c10.goto(-75,-170)
c3.goto(-75,-300)
c4.goto(-25,-300)
c10.goto(-75,-270)
c3.goto(-75,-420)
c4.goto(-25,-420)
c10.goto(-75,-370)
c10.goto(-75,-420)
time.sleep(0)
for i in range (3):
s2.goto(-140,-190)
s2.dot(10,"green")#semaforo 2
green2.on()
s3.goto(140,190)
s3.dot(10,"green")#semaforo 3
green3.on()
time.sleep(.5)
s2.goto(-140,-190)
s2.dot(10,"black")#semaforo 2
green2.off()
s3.goto(140,190)
s3.dot(10,"black")#semaforo 3
green3.off()
s2.goto(-140,-190)
s2.dot(10,"black")
green2.off()
s3.goto(140,190)
s3.dot(10,"black")
green3.off()
s2.goto(-120,-190)
s2.dot(10,"yellow")
yellow2.on()
s3.goto(120,190)
s3.dot(10,"yellow")
yellow3.on()
time.sleep(2)
s2.goto(-120,-190)
s2.dot(10,"black")
yellow2.off()
s3.goto(120,190)
s3.dot(10,"black")
yellow3.off()
c1.hideturtle()
c2.hideturtle()
c3.hideturtle()
c4.hideturtle()
c5.hideturtle()
c6.hideturtle()
c7.hideturtle()
c8.hideturtle()
c9.hideturtle()
c10.hideturtle()
from turtle import*
import time
import random
from gpiozero import LED
green1=LED(17)
yellow1=LED(22)
red1=LED(27)
green2=LED(5)
yellow2=LED(6)
red2=LED(13)
green3=LED(24)
yellow3=LED(23)
red3=LED(18)
green4=LED(21)
yellow4=LED(20)
red4=LED(16)
t=Turtle()
s1=Turtle()
s2=Turtle()
s3=Turtle()
s4=Turtle()
c1=Turtle()
c2=Turtle()
c3=Turtle()
c4=Turtle()
c5=Turtle()
c6=Turtle()
c7=Turtle()
c8=Turtle()
c9=Turtle()
c10=Turtle()
c1.penup()
c2.penup()
c3.penup()
c4.penup()
c5.penup()
c6.penup()
c7.penup()
c8.penup()
c9.penup()
c10.penup()
#inicializacion de carros
c1.speed(0)
c1.shape("turtle")
c1.color("red")
c2.speed(0)
c2.shape("turtle")
c2.color("brown")
c3.speed(0)
c3.shape("turtle")
c3.color("orange")
c4.speed(0)
c4.shape("turtle")
c4.color("yellow")
c5.speed(0)
c5.shape("turtle")
c5.color("green")
c6.speed(0)
c6.shape("turtle")
c6.color("blue")
c7.speed(0)
c7.shape("turtle")
c7.color("purple")
c8.speed(0)
c8.shape("turtle")
c8.color("white")
c9.speed(0)
c9.shape("turtle")
c9.color("gold")
c10.speed(0)
c10.shape("turtle")
c10.color("silver")
screen=t.getscreen()
setup(800,800,0,0)
screensize(800,800)
t.speed(0)
#posicion de carros
c1.goto(-420,-25)
c1.speed(0)
c2.goto(-420,-75)
c2.speed(0)
c3.goto(-75,420)
c3.right(90)
c3.speed(0)
c4.goto(-25,420)
c4.right(90)
c4.speed(0)
c5.goto(420,75)
c5.right(180)
c5.speed(0)
c6.goto(420,25)
c6.right(180)
c6.speed(0)
c7.goto(25,-420)
c7.left(90)
c7.speed(0)
c8.goto(75,-420)
c8.left(90)
c8.speed(0)
c9.goto(-420,-25)
c9.speed(0)
c10.goto(-75,420)
c10.right(90)
c10.speed(0)
t.penup()
t.goto(-400,400)
t.pensize(7)
t.pendown()
t.fillcolor("green")
t.begin_fill()
t.goto(-400,400)
t.goto(400,400)
t.goto(400,-400)
t.goto(-400,-400)
t.end_fill()
t.fillcolor("gray")
t.penup()
t.goto(-400,100)
t.begin_fill()
pendown()
t.goto(-400,150)
t.goto(-150,150)
t.goto(-150,400)
t.goto(-100,400)
t.goto(-100,100)
t.goto(-400,100)
t.end_fill()
t.fillcolor("gray")
t.penup()
t.goto(400,100)
t.begin_fill()
pendown()
t.goto(400,150)
t.goto(150,150)
t.goto(150,400)
t.goto(100,400)
t.goto(100,100)
t.goto(400,100)
t.end_fill()
t.fillcolor("gray")
t.penup()
t.goto(-400,-100)
t.begin_fill()
pendown()
t.goto(-400,-150)
t.goto(-150,-150)
t.goto(-150,-400)
t.goto(-100,-400)
t.goto(-100,-100)
t.goto(-400,-100)
t.end_fill()
t.fillcolor("gray")
t.penup()
t.goto(400,100)
t.begin_fill()
pendown()
t.goto(400,-150)
t.goto(150,-150)
t.goto(150,-400)
t.goto(100,-400)
t.goto(100,-100)
t.goto(400,-100)
t.end_fill()
t.penup()
t.goto(-400,-100)
t.fillcolor("black")
t.begin_fill()
t.pendown()
t.goto(-400,100)
t.goto(-100,100)
t.goto(-100,400)
t.goto(100,400)
t.goto(100,100)
t.goto(400,100)
t.goto(400,-100)
t.goto(100,-100)
t.goto(100,-400)
t.goto(-100,-400)
t.goto(-100,-100)
t.goto(-400,-100)
t.end_fill()
t.penup()
t.pensize(5)
t.pencolor("white")
t.goto(-400,0)
for i in range (-400,-100,50):
t.pendown()
t.goto(i,0)
t.goto(i+25,0)
t.penup()
t.goto(i+25,0)
t.goto(i+50,0)
t.penup()
t.pensize(5)
t.pencolor("white")
t.goto(0,400)
for i in range (400,100,-50):
t.pendown()
t.goto(0,i)
t.goto(0,i-25)
t.penup()
t.goto(0,i-25)
t.goto(0,i-50)
t.penup()
t.pensize(5)
t.pencolor("white")
t.goto(400,0)
for i in range (400,100,-50):
t.pendown()
t.goto(i,0)
t.goto(i-25,0)
t.penup()
t.goto(i-25,0)
t.goto(i-50,0)
t.penup()
t.pensize(5)
t.pencolor("white")
t.goto(0,-400)
for i in range (-400,-100,50):
t.pendown()
t.goto(0,i)
t.goto(0,i+25)
t.penup()
t.goto(0,i+25)
t.goto(0,i+50)
t.penup()
t.pensize(7)
t.pencolor("yellow")
t.goto(-110,-100)
for i in range (-100,110,20):
t.pendown()
t.goto(-150,i)
t.penup()
t.goto(-110,i+20)
t.penup()
t.goto(-100,110)
for i in range (-100,110,20):
t.pendown()
t.goto(i,150)
t.penup()
t.goto(i+20,110)
t.penup()
t.goto(110,100)
for i in range (100,-110,-20):
t.pendown()
t.goto(150,i)
t.penup()
t.goto(110,i-20)
t.penup()
t.goto(100,-110)
for i in range (100,-110,-20):
t.pendown()
t.goto(i,-150)
t.penup()
t.goto(i-20,-110)
t.penup()
t.pencolor("white")
t.pensize(8)
t.goto (-100,-100)
t.pendown()
t.goto (-100,100)
t.goto (100,100)
t.goto (100,-100)
t.goto(-100,-100)
t.penup()
t.goto(-160,-100)
t.pendown()
t.goto(-160,100)
t.penup()
t.goto(-100,160)
t.pendown()
t.goto(100,160)
t.penup()
t.goto(160,100)
t.pendown()
t.goto(160,-100)
t.penup()
t.goto(100,-160)
t.pendown()
t.goto(-100,-160)
t.penup()
t.pensize(5)
t.goto(-250,-50)
t.pendown()
t.goto(-200,-50)
t.goto(-225,-38)
t.penup()
t.goto(-200,-50)
t.pendown()
t.goto(-225,-62)
t.penup()
t.pensize(5)
t.goto(50,-250)
t.pendown()
t.goto(50,-200)
t.goto(38,-225)
t.penup()
t.goto(50,-200)
t.pendown()
t.goto(62,-225)
t.penup()
t.pensize(5)
t.goto(250,50)
t.pendown()
t.goto(200,50)
t.goto(225,38)
t.penup()
t.goto(200,50)
t.pendown()
t.goto(225,62)
t.penup()
t.pensize(5)
t.goto(-50,250)
t.pendown()
t.goto(-50,200)
t.goto(-38,225)
t.penup()
t.goto(-50,200)
t.pendown()
t.goto(-62,225)
t.pensize(1)
t.pencolor("orange")
t.fillcolor("orange")
t.begin_fill()
t.penup()
t.goto(-180,80)
t.pendown()
t.goto(-200,80)
t.goto(-200,160)
t.goto(-180,160)
t.goto(-180,80)
t.end_fill()
t.pensize(1)
t.pencolor("orange")
t.fillcolor("orange")
t.begin_fill()
t.penup()
t.goto(-80,-180)
t.pendown()
t.goto(-80,-200)
t.goto(-160,-200)
t.goto(-160,-180)
t.goto(-80,-180)
t.end_fill()
t.pensize(1)
t.pencolor("orange")
t.fillcolor("orange")
t.begin_fill()
t.penup()
t.goto(80,180)
t.pendown()
t.goto(80,200)
t.goto(160,200)
t.goto(160,180)
t.goto(80,180)
t.end_fill()
t.pensize(1)
t.pencolor("orange")
t.fillcolor("orange")
t.begin_fill()
t.penup()
t.goto(180,-80)
t.pendown()
t.goto(200,-80)
t.goto(200,-160)
t.goto(180,-160)
t.goto(180,-80)
t.end_fill()
t.hideturtle()
s1.speed(0)
s2.speed(0)
s3.speed(0)
s4.speed(0)
s1.penup()
s2.penup()
s3.penup()
s4.penup()
s1.hideturtle()
s2.hideturtle()
s3.hideturtle()
s4.hideturtle()
s1.goto(-190,140)
s1.dot(10,"green")#semaforo 1
green1.on()
s4.goto(190,-140)
s4.dot(10,"green")#semaforo 4
green4.on()
s2.goto(-100,-190)
s2.dot(10,"red")#semaforo 2
red2.on()
s3.goto(100,190)
s3.dot(10,"red")#semaforo 3
red3.on()
s1.goto(-190,100)
s1.dot(10,"black")#semaforo 1
yellow1.off()
s1.goto(-190,120)
s1.dot(10,"black")#semaforo 1
red1.off()
s4.goto(190,-100)
s4.dot(10,"black")#semaforo 4
yellow4.off()
s4.goto(190,-120)
s4.dot(10,"black")#semafor 4
red4.off()
s2.goto(-120,-190)
s2.dot(10,"black")#semaforo 2
green2.off()
s2.goto(-140,-190)
s2.dot(10,"black")#semaforo 2
yellow2.off()
s3.goto(120,190)
s3.dot(10,"black")#semaforo 3
green3.off()
s3.goto(140,190)
s3.dot(10,"black")#semaforo 3
yellow3.off()
while(True):
s1.goto(-190,140)
s1.dot(10,"green")#semaforo 1
green1.on()
s4.goto(190,-140)
s4.dot(10,"green")#semaforo 4
green4.on()
s2.goto(-100,-190)
s2.dot(10,"red")#semaforo 2
red2.on()
s3.goto(100,190)
s3.dot(10,"red")#semaforo 3
red3.on()
s1.goto(-190,100)
s1.dot(10,"black")#semaforo 1
yellow1.off()
s1.goto(-190,120)
s1.dot(10,"black")#semaforo 1
red1.off()
s4.goto(190,-100)
s4.dot(10,"black")#semaforo 4
yellow4.off()
s4.goto(190,-120)
s4.dot(10,"black")#semafor 4
red4.off()
s2.goto(-120,-190)
s2.dot(10,"black")#semaforo 2
green2.off()
s2.goto(-140,-190)
s2.dot(10,"black")#semaforo 2
yellow2.off()
s3.goto(120,190)
s3.dot(10,"black")#semaforo 3
green3.off()
s3.goto(140,190)
s3.dot(10,"black")#semaforo 3
yellow3.off()
#time.sleep(3)
num=random.randint(1,5)
c1.goto(-420,-25)
c1.speed(0)
c2.goto(-420,-75)
c2.speed(0)
c3.goto(-75,420)
c3.speed(0)
c4.goto(-25,420)
c4.speed(0)
c5.goto(420,75)
c5.speed(0)
c6.goto(420,25)
c6.speed(0)
c7.goto(25,-420)
c7.speed(0)
c8.goto(75,-420)
c8.speed(0)
c9.goto(-420,-25)
c9.speed(0)
c10.goto(-75,420)
c10.speed(0)
c1.showturtle()
c2.showturtle()
c3.showturtle()
c4.showturtle()
c5.showturtle()
c6.showturtle()
c7.showturtle()
c8.showturtle()
c9.showturtle()
c10.showturtle()
c1.speed(1)
c2.speed(1)
c3.speed(1)
c4.speed(1)
c5.speed(1)
c6.speed(1)
c7.speed(1)
c8.speed(1)
c9.speed(1)
c10.speed(1)
if (num==1):
s1.goto(-190,140)
s1.dot(10,"green")#semaforo 1
green1.on()
s4.goto(190,-140)
s4.dot(10,"green")#semaforo 4
green4.on()
c1.goto(425,-25)#
c5.goto(-420,75)
c6.goto(-420,25)
s2.goto(-100,-190)
s2.dot(10,"red")#semaforo 2
red2.on()
s3.goto(100,190)
s3.dot(10,"red")#semaforo 3
red3.on()
c10.goto(-75,190)#
c7.goto(25,-190)
s1.goto(-190,100)
s1.dot(10,"black")#semaforo 1
yellow1.off()
s1.goto(-190,120)
s1.dot(10,"black")#semaforo 1
red1.off()
s4.goto(190,-100)
s4.dot(10,"black")#semaforo 4
yellow4.off()
s4.goto(190,-120)
s4.dot(10,"black")#semafor 4
red4.off()
s2.goto(-120,-190)
s2.dot(10,"black")#semaforo 2
green2.off()
s2.goto(-140,-190)
s2.dot(10,"black")#semaforo 2
yellow2.off()
s3.goto(120,190)
s3.dot(10,"black")#semaforo 3
green3.off()
s3.goto(140,190)
s3.dot(10,"black")#semaforo 3
yellow3.off()
time.sleep(0)
for i in range (3):
s1.goto(-190,140)
s1.dot(10,"green")#semaforo 1
green1.on()
s4.goto(190,-140)
s4.dot(10,"green")#semaforo 4
green4.on()
time.sleep(.5)
s1.goto(-190,140)
s1.dot(10,"black")#semaforo 1
green1.off()
s4.goto(190,-140)
s4.dot(10,"black")#semaforo 4
green4.off()
s1.goto(-190,140)
s1.dot(10,"black")
green1.off()
s4.goto(190,-140)
s4.dot(10,"black")
green4.off()
s1.goto(-190,120)
s1.dot(10,"yellow")
yellow1.on()
s4.goto(190,-120)
s4.dot(10,"yellow")
yellow4.on()
time.sleep(2)
s1.goto(-190,120)
s1.dot(10,"black")
yellow1.off()
s4.goto(190,-120)
s4.dot(10,"black")
yellow4.off()
s2.goto(-120,-190)
s2.dot(10,"black")#semaforo 2
yellow2.off()
s2.goto(-100,-190)
s2.dot(10,"black")#semaforo 2
red2.off()
s3.goto(120,190)
s3.dot(10,"black")#semaforo 3
yellow3.off()
s3.goto(100,190)
s3.dot(10,"black")#semafor 3
red3.off()
s2.goto(-140,-190)
s2.dot(10,"green")#semaforo 2
green2.on()
s4.goto(140,190)
s4.dot(10,"green")#semaforo 3
green3.on()
s1.goto(-190,100)
s1.dot(10,"red")#semaforo 1
red1.on()
s4.goto(190,-100)
s4.dot(10,"red")#semaforo 4
red4.on()
s1.goto(-190,120)
s1.dot(10,"black")#semaforo 1
yellow1.off()
s1.goto(-190,140)
s1.dot(10,"black")#semaforo 1
green1.off()
s4.goto(190,-120)
s4.dot(10,"black")#semaforo 4
yellow4.off()
s4.goto(190,-140)
s4.dot(10,"black")#semaforo 4
green4.off()
c10.speed(5)#
c7.speed(5)
c10.goto(-75,0)
c7.goto(25,0)
c10.goto(-75,-100)
c7.goto(25,100)
c10.goto(-75,-200)
c7.goto(25,200)
c10.goto(-75,-300)
c7.goto(25,300)
c10.goto(-75,-420)
c7.goto(25,420)
time.sleep(0)
for i in range (3):
s2.goto(-140,-190)
s2.dot(10,"green")#semaforo 2
green2.on()
s3.goto(140,190)
s3.dot(10,"green")#semaforo 3
green3.on()
time.sleep(.5)
s2.goto(-140,-190)
s2.dot(10,"black")#semaforo 2
green2.off()
s3.goto(140,190)
s3.dot(10,"black")#semaforo 3
green3.off()
s2.goto(-140,-190)
s2.dot(10,"black")
green2.off()
s3.goto(140,190)
s3.dot(10,"black")
green3.off()
s2.goto(-120,-190)
s2.dot(10,"yellow")
yellow2.on()
s3.goto(120,190)
s3.dot(10,"yellow")
yellow3.on()
time.sleep(2)
s2.goto(-120,-190)
s2.dot(10,"black")
yellow2.off()
s3.goto(120,190)
s3.dot(10,"black")
yellow3.off()
c1.hideturtle()
c2.hideturtle()
c3.hideturtle()
c4.hideturtle()
c5.hideturtle()
c6.hideturtle()
c7.hideturtle()
c8.hideturtle()
c9.hideturtle()
c10.hideturtle()
elif(num==2):
s1.goto(-190,140)
s1.dot(10,"green")#semaforo 1
green1.on()
s4.goto(190,-140)
s4.dot(10,"green")#semaforo 4
green4.on()
c2.speed(5)#
c5.speed(5)
c2.goto(-300,-75)
c5.goto(300,75)
c2.goto(-200,-75)
c5.goto(200,75)
c2.goto(-100,-75)
c5.goto(100,75)
c2.goto(0,-75)
c5.goto(0,75)
c2.goto(100,-75)
c5.goto(-100,75)
c2.goto(200,-75)
c5.goto(-200,75)
c2.goto(300,-75)
c5.goto(-300,75)
c2.goto(420,-75)
c5.goto(-420,75)
s2.goto(-100,-190)
s2.dot(10,"red")#semaforo 2
red2.on()
s3.goto(100,190)
s3.dot(10,"red")#semaforo 3
red3.on()
c10.goto(-75,190)#
c7.goto(25,-190)
s1.goto(-190,100)
s1.dot(10,"black")#semaforo 1
red1.off()
s1.goto(-190,120)
s1.dot(10,"black")#semaforo 1
yellow1.off()
s4.goto(190,-100)
s4.dot(10,"black")#semaforo 4
red4.off()
s4.goto(190,-120)
s4.dot(10,"black")#semafor 4
yellow4.off()
s2.goto(-120,-190)
s2.dot(10,"black")#semaforo 2
yellow2.off()
s2.goto(-140,-190)
s2.dot(10,"black")#semaforo 2
green2.off()
s3.goto(120,190)
s3.dot(10,"black")#semaforo 3
yellow3.off()
s3.goto(140,190)
s3.dot(10,"black")#semaforo 3
green3.off()
time.sleep(0)
for i in range (3):
s1.goto(-190,140)
s1.dot(10,"green")#semaforo 1
green1.on()
s4.goto(190,-140)
s4.dot(10,"green")#semaforo 4
green4.on()
time.sleep(.5)
s1.goto(-190,140)
s1.dot(10,"black")#semaforo 1
green1.off()
s4.goto(190,-140)
s4.dot(10,"black")#semaforo 4
green4.off()
s1.goto(-190,140)
s1.dot(10,"black")
green1.off()
s4.goto(190,-140)
s4.dot(10,"black")
green4.off()
s1.goto(-190,120)
s1.dot(10,"yellow")
yellow1.on()
s4.goto(190,-120)
s4.dot(10,"yellow")
yellow4.on()
time.sleep(2)
s1.goto(-190,120)
s1.dot(10,"black")
yellow1.off()
s4.goto(190,-120)
s4.dot(10,"black")
yellow4.off()
s2.goto(-120,-190)
s2.dot(10,"black")#semaforo 2
yellow2.off()
s2.goto(-100,-190)
s2.dot(10,"black")#semaforo 2
red2.off()
s3.goto(120,190)
s3.dot(10,"black")#semaforo 3
yellow3.off()
s3.goto(100,190)
s3.dot(10,"black")#semafor 3
red3.off()
s2.goto(-140,-190)
s2.dot(10,"green")#semaforo 2
green2.on()
s4.goto(140,190)
s4.dot(10,"green")#semaforo 3
green3.on()
c10.speed(5)#
c7.speed(5)
c10.goto(-75,0)
c7.goto(25,0)
c10.goto(-75,-100)
c7.goto(25,100)
c10.goto(-75,-200)
c7.goto(25,200)
c10.goto(-75,-300)
c7.goto(25,300)
c10.goto(-75,-420)
c7.goto(25,420)
s1.goto(-190,100)
s1.dot(10,"red")#semaforo 1
red1.on()
s4.goto(190,-100)
s4.dot(10,"red")#semaforo 4
red4.on()
s1.goto(-190,120)
s1.dot(10,"black")#semaforo 1
yellow1.off()
s1.goto(-190,140)
s1.dot(10,"black")#semaforo 1
green1.off()
s4.goto(190,-120)
s4.dot(10,"black")#semaforo 4
yellow4.off()
s4.goto(190,-140)
s4.dot(10,"black")#semaforo 4
green4.off()
time.sleep(3)
for i in range (3):
s2.goto(-140,-190)
s2.dot(10,"green")#semaforo 2
green2.on()
s3.goto(140,190)
s3.dot(10,"green")#semaforo 3
green3.on()
time.sleep(.5)
s2.goto(-140,-190)
s2.dot(10,"black")#semaforo 2
green2.off()
s3.goto(140,190)
s3.dot(10,"black")#semaforo 3
green3.off()
s2.goto(-140,-190)
s2.dot(10,"black")
green2.off()
s3.goto(140,190)
s3.dot(10,"black")
green3.off()
s2.goto(-120,-190)
s2.dot(10,"yellow")
yellow2.on()
s3.goto(120,190)
s3.dot(10,"yellow")
yellow3.on()
time.sleep(2)
s2.goto(-120,-190)
s2.dot(10,"black")
yellow2.off()
s3.goto(120,190)
s3.dot(10,"black")
yellow3.off()
c1.hideturtle()
c2.hideturtle()
c3.hideturtle()
c4.hideturtle()
c5.hideturtle()
c6.hideturtle()
c7.hideturtle()
c8.hideturtle()
c9.hideturtle()
c10.hideturtle()
elif(num==3):
s1.goto(-190,140)
s1.dot(10,"green")#semaforo 1
green1.on()
s4.goto(190,-140)
s4.dot(10,"green")#semaforo 4
green4.on()
c8.speed(5)#
c9.speed(5)
c9.goto(-300,-25)
c8.goto(75,-300)
c9.goto(-200,-25)
c8.goto(75,-200)
c9.goto(-100,-25)
c8.goto(75,-190)
c9.goto(0,-25)
c9.goto(100,-25)
c9.goto(200,-25)
c9.goto(300,-25)
c9.goto(420,-25)
s2.goto(-100,-190)
s2.dot(10,"red")#semaforo 2
red2.on()
s3.goto(100,190)
s3.dot(10,"red")#semaforo 3
red3.on()
c10.goto(-75,190)#
s1.goto(-190,100)
s1.dot(10,"black")#semaforo 1
red1.off()
s1.goto(-190,120)
s1.dot(10,"black")#semaforo 1
yellow1.off()
s4.goto(190,-100)
s4.dot(10,"black")#semaforo 4
red4.off()
s4.goto(190,-120)
s4.dot(10,"black")#semafor 4
yellow4.off()
s2.goto(-120,-190)
s2.dot(10,"black")#semaforo 2
yellow2.off()
s2.goto(-140,-190)
s2.dot(10,"black")#semaforo 2
green2.off()
s3.goto(120,190)
s3.dot(10,"black")#semaforo 3
yellow3.off()
s3.goto(140,190)
s3.dot(10,"black")#semaforo 3
green3.off()
time.sleep(0)
for i in range (3):
s1.goto(-190,140)
s1.dot(10,"green")#semaforo 1
green1.on()
s4.goto(190,-140)
s4.dot(10,"green")#semaforo 4
green4.on()
time.sleep(.5)
s1.goto(-190,140)
s1.dot(10,"black")#semaforo 1
green1.off()
s4.goto(190,-140)
s4.dot(10,"black")#semaforo 4
green4.off()
s1.goto(-190,140)
s1.dot(10,"black")
green1.off()
s4.goto(190,-140)
s4.dot(10,"black")
green4.off()
s1.goto(-190,120)
s1.dot(10,"yellow")
yellow1.on()
s4.goto(190,-120)
s4.dot(10,"yellow")
yellow4.on()
time.sleep(2)
s1.goto(-190,120)
s1.dot(10,"black")
yellow1.off()
s4.goto(190,-120)
s4.dot(10,"black")
yellow4.off()
s2.goto(-120,-190)
s2.dot(10,"black")#semaforo 2
yellow2.off()
s2.goto(-100,-190)
s2.dot(10,"black")#semaforo 2
red2.off()
s3.goto(120,190)
s3.dot(10,"black")#semaforo 3
yellow3.off()
s3.goto(100,190)
s3.dot(10,"black")#semafor 3
red3.off()
s2.goto(-140,-190)
s2.dot(10,"green")#semaforo 2
green2.on()
s4.goto(140,190)
s4.dot(10,"green")#semaforo 3
green3.on()
s1.goto(-190,100)
s1.dot(10,"red")#semaforo 1
red1.on()
s4.goto(190,-100)
s4.dot(10,"red")#semaforo 4
red4.on()
s1.goto(-190,120)
s1.dot(10,"black")#semaforo 1
yellow1.off()
s1.goto(-190,140)
s1.dot(10,"black")#semaforo 1
green1.off()
s4.goto(190,-120)
s4.dot(10,"black")#semaforo 4
yellow4.off()
s4.goto(190,-140)
s4.dot(10,"black")#semaforo 4
green4.off()
c10.speed(5)#
c8.speed(5)
c10.goto(-75,0)
c8.goto(25,0)
c10.goto(-75,-100)
c8.goto(25,100)
c10.goto(-75,-200)
c8.goto(25,200)
c10.goto(-75,-300)
c8.goto(25,300)
c10.goto(-75,-420)
c8.goto(25,420)
time.sleep(0)
for i in range (3):
s2.goto(-140,-190)
s2.dot(10,"green")#semaforo 2
green2.on()
s3.goto(140,190)
s3.dot(10,"green")#semaforo 3
green3.on()
time.sleep(.5)
s2.goto(-140,-190)
s2.dot(10,"black")#semaforo 2
green2.off()
s3.goto(140,190)
s3.dot(10,"black")#semaforo 3
green3.off()
s2.goto(-140,-190)
s2.dot(10,"black")
green2.off()
s3.goto(140,190)
s3.dot(10,"black")
green3.off()
s2.goto(-120,-190)
s2.dot(10,"yellow")
yellow2.on()
s3.goto(120,190)
s3.dot(10,"yellow")
yellow3.on()
time.sleep(2)
s2.goto(-120,-190)
s2.dot(10,"black")
yellow2.off()
s3.goto(120,190)
s3.dot(10,"black")
yellow3.off()
c1.hideturtle()
c2.hideturtle()
c3.hideturtle()
c4.hideturtle()
c5.hideturtle()
c6.hideturtle()
c7.hideturtle()
c8.hideturtle()
c9.hideturtle()
c10.hideturtle()
elif(num==4):
s1.goto(-190,140)
s1.dot(10,"green")#semaforo 1
green1.on()
s4.goto(190,-140)
s4.dot(10,"green")#semaforo 4
green4.on()
c8.speed(5)#
c9.speed(5)
c9.goto(-300,-25)
c8.goto(75,-300)
c9.goto(-200,-25)
c8.goto(75,-200)
c9.goto(-100,-25)
c8.goto(75,-190)
c9.goto(0,-25)
c9.goto(100,-25)
c9.goto(200,-25)
c9.goto(300,-25)
c9.goto(420,-25)
s2.goto(-100,-190)
s2.dot(10,"red")#semaforo 2
red2.on()
s3.goto(100,190)
s3.dot(10,"red")#semaforo 3
red3.on()
c10.goto(-75,190)#
s1.goto(-190,100)
s1.dot(10,"black")#semaforo 1
red1.off()
s1.goto(-190,120)
s1.dot(10,"black")#semaforo 1
yellow1.off()
s4.goto(190,-100)
s4.dot(10,"black")#semaforo 4
red4.off()
s4.goto(190,-120)
s4.dot(10,"black")#semafor 4
yellow4.off()
s2.goto(-120,-190)
s2.dot(10,"black")#semaforo 2
yellow2.off()
s2.goto(-140,-190)
s2.dot(10,"black")#semaforo 2
green2.off()
s3.goto(120,190)
s3.dot(10,"black")#semaforo 3
yellow3.off()
s3.goto(140,190)
s3.dot(10,"black")#semaforo 3
green3.off()
time.sleep(0)
for i in range (3):
s1.goto(-190,140)
s1.dot(10,"green")#semaforo 1
green1.on()
s4.goto(190,-140)
s4.dot(10,"green")#semaforo 4
green4.on()
time.sleep(.5)
s1.goto(-190,140)
s1.dot(10,"black")#semaforo 1
green1.off()
s4.goto(190,-140)
s4.dot(10,"black")#semaforo 4
green4.off()
s1.goto(-190,140)
s1.dot(10,"black")
green1.off()
s4.goto(190,-140)
s4.dot(10,"black")
green4.off()
s1.goto(-190,120)
s1.dot(10,"yellow")
yellow1.on()
s4.goto(190,-120)
s4.dot(10,"yellow")
yellow4.on()
time.sleep(2)
s1.goto(-190,120)
s1.dot(10,"black")
yellow1.off()
s4.goto(190,-120)
s4.dot(10,"black")
yellow4.off()
s2.goto(-120,-190)
s2.dot(10,"black")#semaforo 2
yellow2.off()
s2.goto(-100,-190)
s2.dot(10,"black")#semaforo 2
red2.off()
s3.goto(120,190)
s3.dot(10,"black")#semaforo 3
yellow3.off()
s3.goto(100,190)
s3.dot(10,"black")#semafor 3
red3.off()
s2.goto(-140,-190)
s2.dot(10,"green")#semaforo 2
green2.on()
s4.goto(140,190)
s4.dot(10,"green")#semaforo 3
green3.on()
s1.goto(-190,100)
s1.dot(10,"red")#semaforo 1
red1.on()
s4.goto(190,-100)
s4.dot(10,"red")#semaforo 4
red4.on()
s1.goto(-190,120)
s1.dot(10,"black")#semaforo 1
yellow1.off()
s1.goto(-190,140)
s1.dot(10,"black")#semaforo 1
green1.off()
s4.goto(190,-120)
s4.dot(10,"black")#semaforo 4
yellow4.off()
s4.goto(190,-140)
s4.dot(10,"black")#semaforo 4
green4.off()
c10.speed(5)#
c8.speed(5)
c10.goto(-75,0)
c8.goto(25,0)
c10.goto(-75,-100)
c8.goto(25,100)
c10.goto(-75,-200)
c8.goto(25,200)
c10.goto(-75,-300)
c8.goto(25,300)
c10.goto(-75,-420)
c8.goto(25,420)
time.sleep(0)
for i in range (3):
s2.goto(-140,-190)
s2.dot(10,"green")#semaforo 2
green2.on()
s3.goto(140,190)
s3.dot(10,"green")#semaforo 3
green3.on()
time.sleep(.5)
s2.goto(-140,-190)
s2.dot(10,"black")#semaforo 2
green2.off()
s3.goto(140,190)
s3.dot(10,"black")#semaforo 3
green3.off()
s2.goto(-140,-190)
s2.dot(10,"black")
green2.off()
s3.goto(140,190)
s3.dot(10,"black")
green3.off()
s2.goto(-120,-190)
s2.dot(10,"yellow")
yellow2.on()
s3.goto(120,190)
s3.dot(10,"yellow")
yellow3.on()
time.sleep(2)
s2.goto(-120,-190)
s2.dot(10,"black")
yellow2.off()
s3.goto(120,190)
s3.dot(10,"black")
yellow3.off()
c1.hideturtle()
c2.hideturtle()
c3.hideturtle()
c4.hideturtle()
c5.hideturtle()
c6.hideturtle()
c7.hideturtle()
c8.hideturtle()
c9.hideturtle()
c10.hideturtle()
else:
s1.goto(-190,140)
s1.dot(10,"green")#semaforo 1
green1.on()
s4.goto(190,-140)
s4.dot(10,"green")#semaforo 4
green4.on()
c3.speed(5)#
c4.speed(5)
c10.speed(5)
c3.goto(-75,190)
c4.goto(-25,190)
c10.goto(-25,220)
s2.goto(-100,-190)
s2.dot(10,"red")#semaforo 2
red2.on()
s3.goto(100,190)
s3.dot(10,"red")#semaforo 3
red3.on()
c5.goto(-420,75)#
s1.goto(-190,100)
s1.dot(10,"black")#semaforo 1
red1.off()
s1.goto(-190,120)
s1.dot(10,"black")#semaforo 1
yellow1.off()
s4.goto(190,-100)
s4.dot(10,"black")#semaforo 4
red4.off()
s4.goto(190,-120)
s4.dot(10,"black")#semafor 4
yellow4.off()
s2.goto(-120,-190)
s2.dot(10,"black")#semaforo 2
yellow2.off()
s2.goto(-140,-190)
s2.dot(10,"black")#semaforo 2
green2.off()
s3.goto(120,190)
s3.dot(10,"black")#semaforo 3
yellow3.off()
s3.goto(140,190)
s3.dot(10,"black")#semaforo 3
green3.off()
time.sleep(0)
for i in range (3):
s1.goto(-190,140)
s1.dot(10,"green")#semaforo 1
green1.on()
s4.goto(190,-140)
s4.dot(10,"green")#semaforo 4
green4.on()
time.sleep(.5)
s1.goto(-190,140)
s1.dot(10,"black")#semaforo 1
green1.off()
s4.goto(190,-140)
s4.dot(10,"black")#semaforo 4
green4.off()
s1.goto(-190,140)
s1.dot(10,"black")
green1.off()
s4.goto(190,-140)
s4.dot(10,"black")
green4.off()
s1.goto(-190,120)
s1.dot(10,"yellow")
yellow1.on()
s4.goto(190,-120)
s4.dot(10,"yellow")
yellow4.on()
time.sleep(2)
s1.goto(-190,120)
s1.dot(10,"black")
yellow1.off()
s4.goto(190,-120)
s4.dot(10,"black")
yellow4.off()
s2.goto(-120,-190)
s2.dot(10,"black")#semaforo 2
yellow2.off()
s2.goto(-100,-190)
s2.dot(10,"black")#semaforo 2
red2.off()
s3.goto(120,190)
s3.dot(10,"black")#semaforo 3
yellow3.off()
s3.goto(100,190)
s3.dot(10,"black")#semafor 3
red3.off()
s2.goto(-140,-190)
s2.dot(10,"green")#semaforo 2
green2.on()
s4.goto(140,190)
s4.dot(10,"green")#semaforo 3
green3.on()
s1.goto(-190,100)
s1.dot(10,"red")#semaforo 1
red1.on()
s4.goto(190,-100)
s4.dot(10,"red")#semaforo 4
red4.on()
s1.goto(-190,120)
s1.dot(10,"black")#semaforo 1
yellow1.off()
s1.goto(-190,140)
s1.dot(10,"black")#semaforo 1
green1.off()
s4.goto(190,-120)
s4.dot(10,"black")#semaforo 4
yellow4.off()
s4.goto(190,-140)
s4.dot(10,"black")#semaforo 4
green4.off()
c3.speed(5)#
c4.speed(5)
c10.speed(5)
c3.goto(-75,100)
c4.goto(-25,100)
c10.goto(-75,130)
c3.goto(-75,0)
c4.goto(-25,0)
c10.goto(-75,-30)
c3.goto(-75,-100)
c4.goto(-25,-100)
c10.goto(-75,-70)
c3.goto(-75,-200)
c4.goto(-25,-200)
c10.goto(-75,-170)
c3.goto(-75,-300)
c4.goto(-25,-300)
c10.goto(-75,-270)
c3.goto(-75,-420)
c4.goto(-25,-420)
c10.goto(-75,-370)
c10.goto(-75,-420)
time.sleep(0)
for i in range (3):
s2.goto(-140,-190)
s2.dot(10,"green")#semaforo 2
green2.on()
s3.goto(140,190)
s3.dot(10,"green")#semaforo 3
green3.on()
time.sleep(.5)
s2.goto(-140,-190)
s2.dot(10,"black")#semaforo 2
green2.off()
s3.goto(140,190)
s3.dot(10,"black")#semaforo 3
green3.off()
s2.goto(-140,-190)
s2.dot(10,"black")
green2.off()
s3.goto(140,190)
s3.dot(10,"black")
green3.off()
s2.goto(-120,-190)
s2.dot(10,"yellow")
yellow2.on()
s3.goto(120,190)
s3.dot(10,"yellow")
yellow3.on()
time.sleep(2)
s2.goto(-120,-190)
s2.dot(10,"black")
yellow2.off()
s3.goto(120,190)
s3.dot(10,"black")
yellow3.off()
c1.hideturtle()
c2.hideturtle()
c3.hideturtle()
c4.hideturtle()
c5.hideturtle()
c6.hideturtle()
c7.hideturtle()
c8.hideturtle()
c9.hideturtle()
c10.hideturtle()
Comentarios
Publicar un comentario