Рет қаралды 19
Hey there, future coders! Today, we’re going to have a blast creating an angry face using Python’s turtle module. By the end of this video, you’ll have a cool drawing and a taste of coding fun! I made this video intended for those young people who want to have tons of fun while getting started in writing some code and hopefully get you guys interested in signing up in computer science courses in the future.
This instruction set is going to be about us drawing an angry face in python. First, we need python downloaded in our computer, so we can follow the next steps.
Step number one is like getting our pen out of our pockets in real life, so we need to import a turtle in Python which is going to be like our pen. We do this by writing:
Import turtle
Step number two is going to be creating a screen to draw on in python by writing the following code:
screen = turtle.Screen()
screen.bgcolor("white")
Step number three is going to be us creating our turtle object that will help us draw by implementing this code
pen = turtle.Turtle()
pen.speed(50)
Note that we have implemented a speed of 50 to the movement of our turtle.
Step number four is going to be writing a definition that will help us later with the creation of circles like face and eyes with the following code
def draw_circle(color, radius, x, y):
pen.penup()
pen.color(color)
pen.fillcolor(color)
pen.goto(x, y)
pen.pendown()
pen.begin_fill()
pen.circle(radius)
pen.end_fill()
You see that we end up using pen up and pen down to signal when we are going to move freely in the screen without drawing and when we are going to move and draw in our screen.
Step number five is to draw the face with the help of this same definition. Note that we have the color, radius of our circle, and the position of our pen signaled in the parameters here:
draw_circle("yellow", 100, 0, -100)
Step number six will be to draw the eyes by using the same method and just changing the parameters.
draw_circle("white", 15, -35, 20)
draw_circle("white", 15, 35, 20)
draw_circle("black", 7, -35, 20)
draw_circle("black", 7, 35, 20)
Then we go into drawing our eyebrows for our seventh step with the help of moving our pen down and up when we move so we do not mess up our craft
pen.penup()
pen.goto(-55, 70)
pen.pendown()
pen.width(5)
pen.goto(-15, 50)
pen.penup()
pen.goto(55, 70)
pen.pendown()
pen.goto(15, 50)
8th Step: draw the mouth with these same functions.
pen.penup()
pen.goto(-40, -20)
pen.pendown()
pen.right(90)
pen.circle(40, 180)
9th Step: Let’s hide the pen so we can see our drawing clearly.
pen.hideturtle()
Finish Up: Keep the window open to admire your work!
turtle.done()
Congratulations! You created a yellow angry face, and while having fun implementing this code and drawing it, you learned how to implement some methods and used some others already defined. If you have any questions, you should go back and see the code again. Thank you for watching!