3
import turtle
back = turtle.Turtle()
back.speed(0)
back.penup()
back.goto(-255,175)
back.pendown()
back.begin_fill()
for x in range(4):
  back.forward(500)
  back.right(90)
  back.forward(350)
  back.right(90)
back.end_fill()

back.penup()
back.goto(245,0)
back.pendown()
back.right(-180)
back.forward(300)
back.setheading(139)
back.forward(270)

back.penup()
back.goto(-55,0)
back.pendown()
back.setheading(-139)
back.forward(270)

As you can see, I am trying to create the Philippines flag using Turtle. What is one way of colouring/ filling in inside the flag? Is there an easy way?

ggorlen
  • 44,755
  • 7
  • 76
  • 106

1 Answers1

0

If you slow down your turtle, you'll see that it's looping around excessively, repeating the same path over and over, which makes fills hard to control.

The goal for fills is to start and end at the same point, drawing a non-overlapping polygon that is easily fillable.

import turtle

t = turtle.Turtle()
#t.speed(0)
t.penup()
t.goto(-255, 175)
t.pendown()

t.color("blue")
t.begin_fill()
t.forward(500)
t.right(90)
t.forward(125)
t.right(90)
t.forward(330)
t.goto(-255, 175)
t.end_fill()

turtle.exitonclick()

I haven't followed the dimensions of the actual flag, so consider this just a proof of concept of drawing a filled shape to get you started.

ggorlen
  • 44,755
  • 7
  • 76
  • 106