You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ampel.py 985B

3 months ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. from turtle import Turtle
  2. def draw_rectangle(turtle, width, height):
  3. for _ in range(2):
  4. turtle.forward(width)
  5. turtle.left(90)
  6. turtle.forward(height)
  7. turtle.left(90)
  8. def draw_case(turtle):
  9. turtle.pencolor('black')
  10. turtle.fillcolor('black')
  11. turtle.pendown()
  12. turtle.begin_fill()
  13. draw_rectangle(turtle, 70, 190)
  14. turtle.end_fill()
  15. turtle.penup()
  16. def draw_light(turtle, color):
  17. turtle.pencolor(color)
  18. turtle.fillcolor(color)
  19. turtle.pendown()
  20. turtle.begin_fill()
  21. turtle.right(90)
  22. turtle.circle(25)
  23. turtle.end_fill()
  24. turtle.penup()
  25. turtle.left(90)
  26. def draw_traffic_light(turtle):
  27. draw_case(turtle)
  28. turtle.forward(35)
  29. turtle.left(90)
  30. turtle.forward(10)
  31. draw_light(turtle, 'green')
  32. turtle.forward(60)
  33. draw_light(turtle, 'yellow')
  34. turtle.forward(60)
  35. draw_light(turtle, 'red')
  36. zoe = Turtle()
  37. draw_traffic_light(zoe)
  38. zoe.hideturtle()
  39. zoe.screen.mainloop()