Ads

Turtle shape() function in Python | Shape type in python turtle | python turtle graphics

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

This function is used to set the turtle shape to shape with a given name or, if the name is not given, return the name of the current shape.


Syntax:


turtle.shape(name=None)

Shape with name must exist in the Turtle Screen’s shape dictionary. Initially, there are the following polygon shapes: “arrow”, “turtle”, “circle”, “square”, “triangle”, “classic”. 



#................................................ PYTHON PROGRAM TO shape() function .....................................



# import package

import turtle


# for default shape

turtle.pensize(5)

turtle.forward(200)


# for circle shape

turtle.color("crimson")

turtle.shape("circle")

turtle.right(60)

turtle.forward(200)


# for triangle shape

turtle.color("lime")

turtle.shape("triangle")

turtle.right(60)

turtle.forward(200)


# for square shape

turtle.color("blue")

turtle.shape("square")

turtle.right(60)

turtle.forward(200)


# for arrow shape

turtle.color("purple")

turtle.shape("arrow")

turtle.right(60)

turtle.forward(200)


# for turtle shape

turtle.color("orangered")

turtle.shape("turtle")

turtle.right(60)

turtle.forward(200)





Post a Comment

0 Comments