Did you know python had its own turtle? Similar to one which people have as their pets, it can move, it can grow in size (change size), and also do other cool things like changing color, shape, or speed you can consider this as a super-turtle! In python, the turtle is a built-in graphical library that allows us to create images and drawings on a given screen. In short, the cursor shown is called a turtle which moves around the screen according to given commands.
Understanding Python’s Turtle Library
Turtle has many operations which can assist us in drawing and creating images . Although we would only be implementing how to change the size of the turtle we can have a look at other operations too.
Classes used to create turtle objects:
The directions you can move the turtle:
Events that turtle can respond to:
Read more about turtle.
Syntax of trutle.shapesize()
turtle.shapesize(stretch_wid=None, stretch_len=None, outline=None)
We would be using the above function to change the size of the turtle.
stretch_wid: This parameter will change the size of the turtle vertically (up and down).
stretch_len: This parameter will change the size of the turtle horizontally (left and right).
outline: This parameter will change the width size of the outline of the turtle icon.
Examples of Changing Turtle Size
Let’s get right into the methods to change the turtle size in Python
Example 1: Making turtle size large
from turtle import * s = getscreen() t = Turtle() t.shapesize(stretch_wid=5, stretch_len=5, outline=1) Screen().turtles() Screen().exitonclick()
We import all the modules
* from the
turtle library. The
getscreen() function is used to return the turtle screen object on which we draw stored in variable
Later we create a turtle object via Turtle() function stored in a variable
You can rename
t to any other name, you wish to example my_turtle or the_turtle.
t.shapesize contains all the required dimensions, we specify the width and length in stretch_wid and strech_len.
In this example, we have set the outline
outline to 1 which is none.Screen().turtles() function returns a list of all the turtles present on the screen. To exit the screen we have defined
Screen().exitonclick() function which would allow us to exit on click.
Example 2: Making the turtle smaller
from turtle import * s = getscreen() t = Turtle() t.shapesize(stretch_wid=2, stretch_len=2, outline=1) Screen().turtles() Screen().exitonclick()
In this example, we change the parameters to make the turtle smaller.
Note: For better understanding, I have uploaded a comparison between the previous turtle size and the present turtle size
Note: For better understanding, I have uploaded a comparison between the previous turtle size and the present turtle size.
Example 3: Making a Turtle with a Thicker Outline
from turtle import * s = getscreen() t = Turtle() t.shapesize(stretch_wid=2, stretch_len=2, outline=8) Screen().turtles() Screen().exitonclick()
In this example, we increase the
outline parameter value from 1 to 8. This will enable us to get a thicker outline of the turtle thus making it more visible even if it’s small.
Note: For better understanding, I have uploaded a comparison between the previous turtle outline size and the present turtle outline.
In this article, we came across the process of changing the turtle size. Although various other manipulations can also be carried out on turtles.
Resizing the turtle size can be implemented for:
- Visual clarity: when the canvas is bigger drawing a complex design can be a tedious task with the small cursor
- Aesthetics: Changing the shape and color of the turtle can make a program more visually appealing
- Animations: Manipulating the appearance of turtle can be used to create the illusion of movement and add a sense of dynamism to the animation.
Overall, changing the turtle size is a useful feature that can help make turtle graphics programs more visually appealing, easier to understand, and more engaging.