Learning to code can be an exciting journey, and one of the most rewarding experiences is seeing your creations come to life on the screen. If you’re just starting out with Python, drawing a simple smiley face can be a fun and easy project to get you familiar with basic programming concepts. In this guide, we’ll walk through the steps to draw a simple smiley face using Python’s built-in turtle
graphics module.
Step 1: Import the Turtle Module
First, you need to import the turtle
module. This module allows you to create simple graphics by controlling a turtle that moves around the screen.
pythonCopy Codeimport turtle
Step 2: Set Up the Screen
Before drawing, it’s a good idea to set up the screen. You can do this by creating a turtle.Screen()
object and setting its title and background color.
pythonCopy Codescreen = turtle.Screen()
screen.title("Simple Smiley Face")
screen.bgcolor("white")
Step 3: Create the Turtle
Now, create a turtle that you’ll use to draw the smiley face. You can customize your turtle by giving it a shape, color, and speed.
pythonCopy Codeface = turtle.Turtle()
face.shape("circle")
face.color("yellow")
face.speed(1)
Step 4: Draw the Face
With your turtle ready, you can start drawing the face. A simple smiley face consists of a circle for the head and semicircles for the eyes and mouth.
pythonCopy Code# Draw the head
face.penup()
face.goto(0, -100)
face.pendown()
face.circle(100)
# Draw the left eye
face.penup()
face.goto(-40, 50)
face.pendown()
face.fillcolor("white")
face.begin_fill()
face.circle(10)
face.end_fill()
# Draw the right eye
face.penup()
face.goto(40, 50)
face.pendown()
face.fillcolor("white")
face.begin_fill()
face.circle(10)
face.end_fill()
# Draw the mouth
face.penup()
face.goto(-40, 20)
face.pendown()
face.setheading(-60)
face.circle(40, 120)
Step 5: Hide the Turtle and Keep the Window Open
After drawing the smiley face, you might want to hide the turtle and keep the window open so you can see your creation.
pythonCopy Codeface.hideturtle() turtle.done()
And that’s it! You’ve successfully drawn a simple smiley face using Python’s turtle
module. This project is a great starting point for learning more about programming and creating more complex graphics. As you progress, you can experiment with different shapes, colors, and sizes to make your smiley face unique.
[tags]
Python, programming, turtle graphics, smiley face, beginner project