pythondrawturtle-graphicsfillpython-turtle

How to draw filled letters (e.g. OLEG) without write() in turtle


I created a code and easily got letters, but now I just understood that I don't know how to make them fill. I made only an E and an L, but I don't understand how to make O and G fill.

This is what I tried with G.

import turtle
t = turtle.Turtle()
t.speed(50) # 1:slowest, 3:slow, 5:normal, 10:fast, 0:fastest

t.circle(-100,-180)
t.right(90)
t.penup()
t.setpos(0, 0)
t.pendown()
t.right(180)
t.forward(20)
t.right(270)
t.circle(-80,-180)
t.right(90)
t.forward(60)
t.left(90)
t.forward(40)
t.right(90)
t.forward(20)
t.right(90)
t.forward(60)
t.right(241)
t.circle(80,-100)


t.hideturtle()

Solution

  • To make a shape fillable, it needs to be drawn in a closed circuit, as if drawn by hand without lifting the pen from the paper, starting and ending at the same point, and without crossing any lines already drawn.

    The following code breaks this rule:

    t.penup()
    t.setpos(0, 0)
    t.pendown()
    

    Instead, keep the pen down and trace the outline of the shape in one continuous path:

    from turtle import Screen, Turtle
    
    
    t = Turtle()
    t.begin_fill()
    t.circle(-100, -270)
    t.right(90)
    t.forward(60)
    t.left(90)
    t.forward(20)
    t.left(90)
    t.forward(40)
    t.left(72)
    t.circle(78, -250)
    t.right(90)
    t.forward(20)
    t.end_fill()
    Screen().exitonclick()
    

    The G shape here isn't beautiful, simply a quick guesstimation, but at least it shows the principle of operation. Improving the look is left as an exercise.

    An alternative strategy is to make the pen thicker (but this probably isn't in the spirit of what you're asking):

    t = Turtle()
    t.pensize(30)
    t.circle(-100, -270)
    t.right(90)
    t.forward(60)
    Screen().exitonclick()