We are building a project in which we will learn How to make a smiling face in Python turtle library. In this, we will split the code and explain how we can make a smiling face by using functions and methods.
Now we are moving forward to start this project. Here we are just importing the libraries.
from turtle import *
import turtle
Hereafter importing the library now we are creating an object for this turtle.
tur = turtle.Turtle[]
Now we are using the function to create an eye. For the Creation of an eye, we have to use the following functions.
- tur.down[] is used to start the drawing on the screen with the help of the turtle.
- tur.fillcolor[color] is used to fill the color in the shape which we draw on the screen.
- tur.begin_fill[] is used to start filling the color in the shape.
- tur.circle[radius] is used to draw the shape of a circle.
- tur.end_fill[] is used to stop filling color.
- tur.up[] is used to stop the drawing.
def eyes[color, radius]:
tur.down[]
tur.fillcolor[color]
tur.begin_fill[]
tur.circle[radius]
tur.end_fill[]
tur.up[]
Now we are using the function to make the shape of a face. For making a face we are using the following function.
- tur.fillcolor[‘cyan’] is used to fill the color inside the shape of the face that is a circle.
- tur.begin_fill[] is used to start filling the shape.
- tur.circle[100] is used to draw the shape of a circle.
- tur.end_fill[] is used to stop filling color.
- tur.up[] is used to stop the drawing.
tur.fillcolor['cyan']
tur.begin_fill[]
tur.circle[100]
tur.end_fill[]
tur.up[]
Now we are using the function to make the shape of eyes. For drawing an eye we are using the following function.
- tur.goto[-40, 120] is used to move the turtle at its accurate position.
- eyes[‘white’, 15] is used to give the white color to the outer part of the eye.
tur.goto[-40, 120]
eyes['white', 15]
tur.goto[-37, 125]
eyes['blue', 5]
tur.goto[40, 120]
eyes['white', 15]
tur.goto[40, 125]
eyes['blue', 5]
Now we are using the function to make the shape of the nose. For drawing a nose we are using the following function.
tur.goto[0, 75] is used to move the turtle at its accurate position.
eyes[‘red’, 8] is used to give red color to the eye.
tur.goto[0, 75]
eyes['red', 8]
Now we are using the function to make the shape of the mouth. For drawing a mouth we are using the following function.
- tur.goto[0, 75] is used to move the turtle at its accurate position.
- tur.down[] is used to start the drawing on the screen with the help of the turtle.
- tur.right[] is used to change position to right side.
- tur.circle[] is used to draw the shape of a circle.
- tur.up[] is used to stop the drawing.
tur.goto[-40, 85]
tur.down[]
tur.right[90]
tur.circle[40, 180]
tur.up[]
Now we are using the function to make the shape of the tongue. For drawing a tongue we are using the following function.
- tur.goto[0, 75] is used to move the turtle at its accurate position.
- tur.down[] is used to start the drawing on the screen with the help of the turtle.
- tur.right[] is used to change position to right side.
- tur.fillcolor[‘red’] is used to fill the red color inside the tongue.
- tur.circle[100] is used to draw the shape of a circle.
- tur.end_fill[] is used to stop filling color.
- tur.hideturtle[] is used hide the turtle which is used to draw the shape.
tur.goto[-10, 45]
tur.down[]
tur.right[180]
tur.fillcolor['red']
tur.begin_fill[]
tur.circle[10, 180]
tur.end_fill[]
tur.hideturtle[]
turtle.done[]
Hereafter splitting the code and explaining how we can make a smiling face using python turtle now, we will see how the output looks like after running the whole code.
from turtle import *
import turtle
tur = turtle.Turtle[]
def eyes[color, radius]:
tur.down[]
tur.fillcolor[color]
tur.begin_fill[]
tur.circle[radius]
tur.end_fill[]
tur.up[]
tur.fillcolor['cyan']
tur.begin_fill[]
tur.circle[100]
tur.end_fill[]
tur.up[]
tur.goto[-40, 120]
eyes['white', 15]
tur.goto[-37, 125]
eyes['blue', 5]
tur.goto[40, 120]
eyes['white', 15]
tur.goto[40, 125]
eyes['blue', 5]
tur.goto[0, 75]
eyes['red', 8]
tur.goto[-40, 85]
tur.down[]
tur.right[90]
tur.circle[40, 180]
tur.up[]
tur.goto[-10, 45]
tur.down[]
tur.right[180]
tur.fillcolor['red']
tur.begin_fill[]
tur.circle[10, 180]
tur.end_fill[]
tur.hideturtle[]
turtle.done[]
After running the above code we get the following output in which we can see a lovely smiling face is drawn on the screen.
How to make a smiling face in python turtleSo, in this tutorial, we have illustrated how to make a smiling face in python turtle. Moreover, we have also discussed the whole code used in this tutorial.
Also, take a look at some more tutorials related to Python Turtle.
- Fractal Python Turtle + Examples
- Python Clear Turtle with examples
- Python Turtle Clock – How to Draw
- Python Turtle Screen Size
- Python turtle draw letters
- Python Turtle Get Position
- Python Turtle Dot – Helpful Guide
- Python turtle title with examples
- Python turtle input
Python is one of the most popular languages in the United States of America. I have been working with Python for a long time and I have expertise in working with various libraries on Tkinter, Pandas, NumPy, Turtle, Django, Matplotlib, Tensorflow, Scipy, Scikit-Learn, etc… I have experience in working with various clients in countries like United States, Canada, United Kingdom, Australia, New Zealand, etc. Check out my profile.