turtle.register_shape() 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.register_shape()
This function is used to add a turtle shape to TurtleScreen’s shapelist.
Syntax :
turtle.register_shape(name, shape=None)
Parameters:Arguments Description name string shape tuple of pairs of coordinates
Below is the implementation of the above method with an example :
Python3
# import packageimport turtle # record a polygonturtle.begin_poly() # form a polygonturtle.seth(-45)turtle.circle(20, 90)turtle.circle(10, 90)turtle.circle(20, 90)turtle.circle(10, 90) turtle.end_poly() # get polygonpairs = turtle.get_poly() # register shape with# name : new_shape# polygon : pairsturtle.register_shape("new_shape", pairs) # clear screenturtle.clearscreen() # use new shape and# apply propertiesturtle.shape("new_shape")turtle.fillcolor("blue") # do some motionfor i in range(50): turtle.forward(5+2*i) turtle.right(45) |
Output :






