Draw a Heart

Use graphics.py for this project. Click HERE for more information. (download, install, documentation, ...)

Project #1

Draw a heart in Python. Convert the code to graphics.py rather than Turtle. (No fill and no pen, just the outline.)

# ======================================================== # Draw Heart Using Turtle Graphics in Python # # https://www.geeksforgeeks.org/python/ # draw-heart-using-turtle-graphics-in-python/ # ======================================================== import turtle pen = turtle.Turtle() # Defining a method to draw a curve def curve(): for i in range(200): pen.right(1) pen.forward(1) # Defining method to draw a full heart 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() # Defining method to write text def txt(): pen.up() pen.setpos(-68, 95) pen.down() pen.color('lightgreen') pen.write("GeeksForGeeks", font=("Verdana",12,"bold")) heart() txt() pen.ht()

Python 3.14.3 documentation - Turtle graphics

The command "turtle.forward(10)" moves 10 pixels in the direction the turtle (pen) is facing, drawing a line as it moves.

The command "turtle.right(30)" rotates the turtle (pen) in-place 30° clockwise.

Project #1a

This is not necessary but you might want to give it a try.

The heart code draws curves (half circles?). Click HERE for information to add drawing arcs to graphics.py.

Project #2

Expand Project #1 to include user input on the color, size, and location of hearts to be drawn. Set reasonable limits.

Another Version of the Draw a Heart (Found on the Web)

import turtle # Set up the screen screen = turtle.Screen() screen.bgcolor("white") # Set the background color # Create a turtle object (the "pen") heart = turtle.Turtle() heart.speed(1) # Set the drawing speed (1 is slow, 0 is fastest) heart.color("red") # Set the outline color heart.fillcolor("red") # Set the fill color # Start drawing the heart shape heart.begin_fill() # Start the left side of the heart heart.left(140) heart.forward(111.65) # or a similar length, e.g., # 133 or 180 depending on the exact shape # Draw the left curve for i in range(200): heart.right(1) heart.forward(1) # Draw the right curve heart.left(120) for i in range(200): heart.right(1) heart.forward(1) # Complete the right side heart.forward(111.65) # Use the same length as the left # forward movement heart.end_fill() # Hide the turtle cursor and keep the window open heart.hideturtle() turtle.done() # or screen.exitonclick() to close on click

FYI - Graphics Window Coordinates

# -------------------------------------------------------------- # # Cartesian Coordinate System Graphics Window Coordinates # (viewer is at +z infinity) (viewer is at +z infinity) # # +y (0,0) # | +------------- +x # | | # | | # | | # | | # +------------- +x +y # (0,0) # # --------------------------------------------------------------