SIZ TUTORIAL | Drawing emotions using Python's turtle module | 20% beneficiary to @siz-official

Assalam o alaikum!
Hope you all are doing well. Today I am here with a tutorial .In this tutorial I am gonna show you how to draw different emotions using Python.

To draw different shapes in python,we use turtle module.

IMG-20211017-WA0005.jpg

We will draw happy,sad and mad face as per the user choice.

Zskj9C56UonWToSX8tGXNY8jeXKSedJ2aRhGRj6HDecqrifjetw2PxQWXjxetSZ9xR2zUCygcwfozdbB14n91mVa1U2HhyoGUJ9zrdzCCy6CrMAaZYuL.png

Let's start


From turtle import *
By using this statement we have imported everything i.e we don't have to write turtle.Screen().We can simply use any function my its name.

•When we run these statements a blank canvas will appear on screen,titled as Python Turtle Graphics due to Screen() function and a small pointer or pen will appear on that screen due to turtle () method or function.

•I have comment out the python input statement.
IMG-20211016-WA0053.jpg

•Here I am changing the colour of turtle to white using color() method and background color to black using bgcolor() method
IMG-20211016-WA0054.jpg

•Now I am drawing a circle of radius 100 with function circle(100) and passing 100 as an argument.

•I have set the boundary color white and will fill in yellow color with function color('white','yellow')

•The color filling process is done with begin_fill() and end_fill() functions

•Now I am taking the penup().

The names of the functions are quite clear, anyone can easily understand that what a particular function is performing.

IMG-20211016-WA0055.jpg

It's time to draw eyes
Left eye
•First of all we have to change the colour of the pen to black by color() method

•As the pen is up ,we will goto(-30,135),it means we take the pen to -30 on x-axis and 135 on y-axis and now take the pendown()

•Now drawing the dot with radius 25 using dot() method.

•Again taking the penup()

Right eye
•Same code will be repeated for right eye.We will just change the position of pen by goto() function,which means where we want to draw the right eye
IMG-20211016-WA0057.jpg

Now we are drawing mouth or smile, whatever you want to call it :)
•I don't want to draw a narrow line that's why I have set the pensize() to 5

•Then goto (-60,60) and keep the pendown()

•I have changed the direction of the turtle to an angle of -50 by setheading() method.

•And draw a circle of radius 70 till an angle of 120° with circle (70,120)
IMG-20211016-WA0056.jpg

•Now I have introduced if else statement,if user press "h" a happy face appear on screen otherwise sad face appear .

•In else statement ,I just goto(60,60) and turn the header by setheading (120) and again draw the circle with radius 70 of 120° by function circle(70,120)

IMG-20211017-WA0000.jpg

Here is the whole code!
In this I have uncommit the input statement and and introduced an other if statement that if user press "m" the inside color of the circle becomes red by circle ('white','red') function and a mad face will appear on screen.
Other than that,all the code remain same.

IMG-20211017-WA0001.jpg

It's time for running the code

•After pressing F5,save the file.

•Now it will ask "How are you"

IMG-20211017-WA0006.jpg

I have pressed "m" as a result here is a mad face on your screen.

IMG-20211017-WA0002.jpg

Similarly ,as we press "h" a happy face will appear and for "s" a sad face.

IMG-20211017-WA0004.jpg

IMG-20211017-WA0003.jpg

Zskj9C56UonWToSX8tGXNY8jeXKSedJ2aRhGRj6HDecqrifjetw2PxQWXjxetSZ9xR2zUCygcwfozdbB14n91mVa1U2HhyoGUJ9zrdzCCy6CrMAaZYuL.png

That's all from my side .I hope it would be helpful for you.
Thanks for visiting!

Zskj9C56UonWToSX8tGXNY8jeXKSedJ2aRhGRj6HDecqrifjetw2PxQWXjxetSZ9xR2zUCygcwfozdbB14n91mVa1U2HhyoGUJ9zrdzCCy6CrMAaZYuL.png

Special thanks to @vvarishayy

Sort:  

You've got a free upvote from witness fuli.
Peace & Love!

 3 years ago 

Good post dear friend please make a justify your text because then your post is more valuable and attractive to see for everyone.

Regards, Faran Nabeel

 3 years ago 

Nice post

It would be helpful if you make your source code editable

Coin Marketplace

STEEM 0.27
TRX 0.11
JST 0.031
BTC 70992.50
ETH 3860.06
USDT 1.00
SBD 3.52