Thursday, September 4, 2025
HomeLanguagesturtle.shapetransform() function in Python

turtle.shapetransform() 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.shapetransform()

This function is used to set or return the current transformation matrix of the turtle shape. If none of the matrix elements are given, it returns the transformation matrix. Otherwise, set the given elements and transform the turtleshape according to the matrix consisting of first row t11, t12, and second-row t21, 22. 

Syntax : turtle.shapetransform(t11=None, t12=None, t21=None, t22=None)

Parameters: 

t11, t12, t21, t22 (optional): The determinant t11 * t22 – t12 * t21 must not be zero, otherwise an error is raised.

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

Example 1 :

Python3




# import package
import turtle
  
# check the default value
print(turtle.shapetransform())


Output :

(1.0, 0.0, 0.0, 1.0)

Example 2 :

Python3




# import package
import turtle
  
# change shapetransform to 2,0,2,0
# as determinant of the matrix 
# [[2,0],[0,2]] is 0.
# so, raised an error 
turtle.shapetransform(2,0,2,0)


Output :

turtle.TurtleGraphicsError: Bad shape transform matrix: must not be singular

Example 3 :

Python3




# import package
import turtle
  
# loop for pattern
for i in range(5):
    for j in range(10):
        
        # motion
        turtle.forward(5+5*(i+j))
        turtle.left(45)
  
    # transform the shape 
    turtle.shapetransform(i+1,0,0,i+1)


Output :

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32262 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6626 POSTS0 COMMENTS
Nicole Veronica
11799 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11857 POSTS0 COMMENTS
Shaida Kate Naidoo
6749 POSTS0 COMMENTS
Ted Musemwa
7025 POSTS0 COMMENTS
Thapelo Manthata
6696 POSTS0 COMMENTS
Umr Jansen
6716 POSTS0 COMMENTS