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 package import turtle
# record a polygon turtle.begin_poly() # form a polygon turtle.seth( - 45 )
turtle.circle( 20 , 90 )
turtle.circle( 10 , 90 )
turtle.circle( 20 , 90 )
turtle.circle( 10 , 90 )
turtle.end_poly() # get polygon pairs = turtle.get_poly()
# register shape with # name : new_shape # polygon : pairs turtle.register_shape( "new_shape" , pairs)
# clear screen turtle.clearscreen() # use new shape and # apply properties turtle.shape( "new_shape" )
turtle.fillcolor( "blue" )
# do some motion for i in range ( 50 ):
turtle.forward( 5 + 2 * i)
turtle.right( 45 )
|
Output :
Article Tags :