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.
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.
•Here I am changing the colour of turtle to white using color() method and background color to black using bgcolor() method
•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.
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
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)
•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)
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.
It's time for running the code
•After pressing F5,save the file.
•Now it will ask "How are you"
I have pressed "m" as a result here is a mad face on your screen.
Similarly ,as we press "h" a happy face will appear and for "s" a sad face.
That's all from my side .I hope it would be helpful for you.
Thanks for visiting!
Special thanks to @vvarishayy
You've got a free upvote from witness fuli.
Peace & Love!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
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
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Nice post
It would be helpful if you make your source code editable
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit