Turtle is an inbuilt module in Python. It provides:
- Drawing using a screen (cardboard).
- Turtle (pen).
To draw something on the screen, we need to move the turtle (pen) and to move the turtle, there are some functions like the forward(), backward(), etc
Prerequisite: Turtle Programming Basics
Draw Heart Using Turtle Graphics
In this section, we will discuss how to draw Heart using Turtle Graphics.
Approach:
- Import Turtle
- Make Turtle Object
- Define a method to draw a curve with simple forward and left moves
- Define a method to draw the full heart and fill the red color in it
- Define a method to display some text by setting position
- Call all the methods in main section.
Code:
python3
import turtle
pen = turtle.Turtle()
def curve():
for i in range ( 200 ):
pen.right( 1 )
pen.forward( 1 )
def heart():
pen.fillcolor( 'red' )
pen.begin_fill()
pen.left( 140 )
pen.forward( 113 )
curve()
pen.left( 120 )
curve()
pen.forward( 112 )
pen.end_fill()
def txt():
pen.up()
pen.setpos( - 68 , 95 )
pen.down()
pen.color( 'lightgreen' )
pen.write( "GeeksForGeeks" , font = (
"Verdana" , 12 , "bold" ))
heart()
txt()
pen.ht()
|
Output:
