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 976B

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