Is there any way to change the outline size of a turtle compound shape?
Question:
I am trying to create a compound shape. What I want now is to change the outline size of this new compound shape.
I have made the shape like this:
import turtle
points_1 = [...] # list of points
points_2 = [...] # list of points
shape = turtle.Shape('compound')
poly = turtle.Turtle()
poly.begin_poly()
for point_list in [points_1, points_2]:
poly.goto(point_list [0][0], point_list[0][1])
poly.begin_poly()
for point in point_list[1:]:
poly.goto(point[0], point[1])
poly.goto(point_list[0][0], point_list[0][1])
poly.end_poly()
shape.addcomponent(poly.get_poly(), '', 'darkgreen')
screen = turtle.Screen()
screen.register_shape('my_turtle', shape)
screen.clearscreen()
my_shape = turtle.Turtle()
my_shape.shape('my_turtle')
turtle.done()
I tried to change the pensize
of the poly and my_shape, but none of them worked.
How can I achieve this with a compound shape of multiple polygons?
Answers:
What you want is the shapesize()
method:
shapesize(stretch_wid=None, stretch_len=None, outline=None)
For example:
from turtle import Screen, Shape, Turtle
points_1 = [(10, -25), (10, -5), (-10, -5), (-10, -25)] # list of points
points_2 = [(10, -5.77), (0, 11.55), (-10, -5.77)] # list of points
turtle = Turtle()
shape = Shape('compound')
for point_list in [points_1, points_2]:
turtle.goto(point_list[0])
turtle.begin_poly()
for point in point_list[1:]:
turtle.goto(point)
turtle.goto(point_list[0])
turtle.end_poly()
shape.addcomponent(turtle.get_poly(), '', 'darkgreen')
screen = Screen()
screen.register_shape('my_turtle', shape)
screen.clearscreen()
my_shape = Turtle()
my_shape.shape('my_turtle')
my_shape.shapesize(2, 3, outline=10)
screen.mainloop()
To just change the outline width, leave off the other arguments and specify on the outline=10
argument by name.
PS: The shapesize()
method also has the alias turtlesize()
which can be used instead.
I am trying to create a compound shape. What I want now is to change the outline size of this new compound shape.
I have made the shape like this:
import turtle
points_1 = [...] # list of points
points_2 = [...] # list of points
shape = turtle.Shape('compound')
poly = turtle.Turtle()
poly.begin_poly()
for point_list in [points_1, points_2]:
poly.goto(point_list [0][0], point_list[0][1])
poly.begin_poly()
for point in point_list[1:]:
poly.goto(point[0], point[1])
poly.goto(point_list[0][0], point_list[0][1])
poly.end_poly()
shape.addcomponent(poly.get_poly(), '', 'darkgreen')
screen = turtle.Screen()
screen.register_shape('my_turtle', shape)
screen.clearscreen()
my_shape = turtle.Turtle()
my_shape.shape('my_turtle')
turtle.done()
I tried to change the pensize
of the poly and my_shape, but none of them worked.
How can I achieve this with a compound shape of multiple polygons?
What you want is the shapesize()
method:
shapesize(stretch_wid=None, stretch_len=None, outline=None)
For example:
from turtle import Screen, Shape, Turtle
points_1 = [(10, -25), (10, -5), (-10, -5), (-10, -25)] # list of points
points_2 = [(10, -5.77), (0, 11.55), (-10, -5.77)] # list of points
turtle = Turtle()
shape = Shape('compound')
for point_list in [points_1, points_2]:
turtle.goto(point_list[0])
turtle.begin_poly()
for point in point_list[1:]:
turtle.goto(point)
turtle.goto(point_list[0])
turtle.end_poly()
shape.addcomponent(turtle.get_poly(), '', 'darkgreen')
screen = Screen()
screen.register_shape('my_turtle', shape)
screen.clearscreen()
my_shape = Turtle()
my_shape.shape('my_turtle')
my_shape.shapesize(2, 3, outline=10)
screen.mainloop()
To just change the outline width, leave off the other arguments and specify on the outline=10
argument by name.
PS: The shapesize()
method also has the alias turtlesize()
which can be used instead.