Wednesday, July 3, 2024
HomeLanguagesPythonturtle.turtlesize() function in Python

turtle.turtlesize() function in Python

The turtle module provides turtle graphics primitives, in both object-oriented and procedure-oriented ways. Because it uses Tkinter for the underlying graphics, it needs a version of Python installed with Tk support.

turtle.turtlesize()

This function is used to return or set the pen’s attributes x or y-stretchfactors and outline. 

Syntax :

turtle.turtlesize(stretch_wid=None, stretch_len=None, outline=None)

Parameters:

Arguments Value Type Description
stretch_wid positive number stretchfactor perpendicular to orientation
stretch_len positive number stretchfactor in direction of turtles orientation
outline positive number determines the width of the shapes’s outline

Below is the implementation of the above method with some examples :

Example 1 :

Python3




# import package
import turtle
  
# set turtle
turtle.speed(1)
turtle.shape("turtle")
turtle.fillcolor("blue")
  
# loop for motion
for i in range(4):
    
    # set turtle width
    turtle.turtlesize(stretch_wid=(i+1)*0.5)
    turtle.forward(100)
    turtle.right(90)


Output :

Example 2 :

Python3




# import package
import turtle
  
# set turtle
turtle.speed(1)
turtle.shape("turtle")
turtle.fillcolor("blue")
  
# loop for motion
for i in range(4):
  
    # set turtle length
    turtle.turtlesize(stretch_len=(i+1)*0.5)
    turtle.forward(100)
    turtle.right(90)


Output :

Example 3 :

Python3




# import package
import turtle
  
# set turtle
turtle.speed(1)
turtle.shape("turtle")
turtle.fillcolor("blue")
  
# loop for motion
for i in range(4):
    
    # set turtle outline
    turtle.turtlesize(outline=i+1)
    turtle.forward(100)
    turtle.right(90)


Output :

Example 4 :

Python3




# import package
import turtle
  
# set turtle
turtle.speed(1)
turtle.shape("turtle")
turtle.fillcolor("blue")
  
# loop for motion
for i in range(4):
    
    # set turtlesize properties all together
    turtle.turtlesize(stretch_wid=(i+1)*0.5,
                      stretch_len=(i+1)*0.5,
                      outline=(i+1)
                     )
    turtle.forward(100)
    turtle.right(90)


Output :

Shaida Kate Naidoo
am passionate about learning the latest technologies available to developers in either a Front End or Back End capacity. I enjoy creating applications that are well designed and responsive, in addition to being user friendly. I thrive in fast paced environments. With a diverse educational and work experience background, I excel at collaborating with teams both local and international. A versatile developer with interests in Software Development and Software Engineering. I consider myself to be adaptable and a self motivated learner. I am interested in new programming technologies, and continuous self improvement.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments