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.

skyscraper.py 1.1KB

2 months ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. from turtle import Turtle
  2. def draw_building(turtle):
  3. turtle.fillcolor('black')
  4. turtle.pencolor('black')
  5. draw_filled_rectangle(turtle,100, 210)
  6. turtle.left(90)
  7. for _ in range(5):
  8. draw_floor(turtle)
  9. def draw_floor(turtle):
  10. turtle.penup()
  11. turtle.forward(10)
  12. turtle.right(90)
  13. turtle.forward(10)
  14. turtle.pendown()
  15. for _ in range(3):
  16. draw_window(turtle)
  17. next_window(turtle)
  18. turtle.penup()
  19. turtle.backward(100)
  20. turtle.left(90)
  21. turtle.forward(30)
  22. def draw_window(turtle):
  23. turtle.fillcolor('yellow')
  24. turtle.pencolor('yellow')
  25. draw_filled_rectangle(turtle, 20, 30)
  26. def next_window(turtle):
  27. turtle.penup()
  28. turtle.forward(30)
  29. turtle.pendown()
  30. def draw_filled_rectangle(turtle, width, height):
  31. turtle.begin_fill()
  32. for _ in range(2):
  33. turtle.forward(width)
  34. turtle.left(90)
  35. turtle.forward(height)
  36. turtle.left(90)
  37. turtle.end_fill()
  38. sophia = Turtle()
  39. sophia.screen.bgcolor('blue')
  40. draw_building(sophia)
  41. sophia.hideturtle()
  42. sophia.screen.mainloop()