Beispiele und Musterlösungen
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 1009B

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