turtle.register_shape() function in Python
Last Updated :
28 Jul, 2020
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 turtle
turtle.begin_poly()
turtle.seth( - 45 )
turtle.circle( 20 , 90 )
turtle.circle( 10 , 90 )
turtle.circle( 20 , 90 )
turtle.circle( 10 , 90 )
turtle.end_poly()
pairs = turtle.get_poly()
turtle.register_shape( "new_shape" , pairs)
turtle.clearscreen()
turtle.shape( "new_shape" )
turtle.fillcolor( "blue" )
for i in range ( 50 ):
turtle.forward( 5 + 2 * i)
turtle.right( 45 )
|
Output :
Share your thoughts in the comments
Please Login to comment...