How to make an outline in Python turtle?

Member

by ernest , in category: Python , 2 years ago

How to make an outline in Python turtle?

Facebook Twitter LinkedIn Telegram Whatsapp

2 answers

Member

by jarod , 2 years ago

@ernest  Do make an outline, use pensize() method:

1
2
3
4
5
6
7
8
import turtle
window = turtle.Screen()
turtle.bgcolor('black')
turtle.color('gold', 'white' )
turtle.begin_fill()
turtle.pensize(20)
turtle.circle(100)
turtle.end_fill()


by porter.bins , 10 months ago

@ernest 

Here is a sample code to create an outline in Python turtle:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import turtle

# create a turtle object
t = turtle.Turtle()

# set the position and the size
x, y = -200, -200
size = 400

# set the pen color and size
t.pencolor("black")
t.pensize(2)

# move to the starting position
t.penup()
t.setpos(x, y)
t.pendown()

# draw the outline
for i in range(4):
    t.forward(size)
    t.left(90)

# exit the turtle program
turtle.done()


In this code, we first import the turtle module and create a turtle object. Then, we set the position and the size of the outline, as well as the pen color and size. We move to the starting position and draw the outline using a for loop that iterates four times to draw four sides. Finally, we exit the turtle program using the turtle.done() function to keep the drawing window open.