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.

flags.py 1014B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. # Zeichnen von Flaggen mit der Turtle
  2. from turtle import Turtle
  3. def draw_flag(turtle, color1, color2, color3):
  4. turtle.pencolor('black')
  5. turtle.pendown()
  6. draw_rectangle(turtle, 600, 300)
  7. turtle.penup()
  8. draw_segment(turtle, color1)
  9. draw_segment(turtle, color2)
  10. draw_segment(turtle, color3)
  11. def draw_segment(turtle, color):
  12. turtle.fillcolor(color)
  13. draw_filled_rectangle(turtle, 200, 300)
  14. turtle.forward(200)
  15. def draw_filled_rectangle(turtle, width, height):
  16. turtle.begin_fill()
  17. draw_rectangle(turtle, width, height)
  18. turtle.end_fill()
  19. def draw_rectangle(turtle, width, height):
  20. for _ in range(2):
  21. turtle.forward(width)
  22. turtle.left(90)
  23. turtle.forward(height)
  24. turtle.left(90)
  25. Turtle.draw_flag = draw_flag
  26. sophia = Turtle()
  27. sophia.draw_flag('green', 'white', 'red')
  28. sophia.backward(600)
  29. sophia.right(90)
  30. sophia.forward(400)
  31. sophia.left(90)
  32. sophia.draw_flag('blue', 'white', 'red')
  33. sophia.hideturtle()
  34. sophia.screen.mainloop()