+

HELLO stamp with turtle module

Methods used by the turtle —

Functions used to move the turtle:

FunctionDescription
forward (no. of steps) This function is used to move the turtle forward the specified number of steps.
backward (no. Of steps) This function is used to move the turtle forward the specified number of steps.
left (angle) This function is used to rotate the turtle left / anti-clockwise with the specified angle .
right (angle) This function is used to rotate the turtle right / clockwise with the specified angle.

Function used to determine the state of the turtle:

position () & # 8212 ; this function is used to get the coordinates / position of the turtle pointer. No parameters are required here, as this function is not used for input, but is used to output the position of the turtle in the console window.

Functions used for coloring:

Function Description
bgcolor (“color”) This function is used to give background color to the turtle window.
pencolor (“color”) This function is used to give color to the turtle pen.
fillcolor (“color”) This function is used to fill color in any closed shape.
color (pencolor, fillcolor) This is a shorthand function used to assign pencolor and fillcolor at the same time.

Function used to control the pen:

Function Description
penup () or pu () This function is used to lift pen from th e current position.
goto () This function is used to move the pen to a new location after lifting.
pendown () or pd () This function is used again put down the pen to a new location.
pensize (int) This function is used to specify the width of the line drawn by pen.

Note: To learn more about the turtle,

# Python program for
# demonstrate the basics of a turtle

 
# Import and make a turtle object
# with white background

import turtle

 

frame = turtle.Screen (). bgcolor ( " White " )

draw = turtle.Turtle ()

draw.left ( 90 )

d raw.forward ( 100 )

draw .right ( 90 )

draw. forward ( 100 )

Output:

Now that we`ve covered the basics of the turtle, let`s write the code to print "HELLO". Below is the implementation.

Output:

Get Solution for free from DataCamp guru

# Python program for
# HELLO print demo
# using the turtle

 
# Here, the frame is initialized with
# background color as "White"

import turtle

frame = turtle.Screen (). bgcolor ( "White" )

draw = turtle.Turtle ()

 
# Pen color, width and speed initialized  

draw.color ( "Green" )

draw.width ( 3 )

draw.speed ( 10 )

 
# Now let`s start with real code
# print the letter H

draw.left ( 90 )

draw.forward ( 70 )

draw.penup ()

draw .goto ( 0 , 35 )

draw.pendown ()

draw. right ( 90 )

draw.forward ( 30 )

draw.penup ()

draw.goto ( 30 , 70 )

draw.pendown ()

draw.right ( 90 )

draw.forward ( 70 )

 
# print letter E
draw.penup ()

draw.goto ( 40 , 0 )

draw.pendown ( )

draw.right ( 180 )

draw.forward ( 70 )

draw.right ( 90 )

draw.forward ( 35 )

draw.penup ()

draw.goto ( 40 , 35 )

draw .pendown ()

draw.forward ( 35 )

draw.penup ()

draw.goto ( 40 , 0 )

draw.pen down ()

draw.forward ( 35 )

 
# print letter L
draw.penup ()

draw.goto ( 90 , 70 )

draw.pendown ()

draw.right ( 90 )

draw.forward ( 70 )

draw.left ( 90 )

draw.forward ( 35 )

 
# print letter L
draw.penup ()

draw.goto ( 135 , 70 )

draw.pendown ()

draw.right ( 90 )

draw.forward ( 70 )

draw.left ( 90 )

draw.forward ( 35 )

 
# print the letter O
draw.penup ()

draw.goto ( 210 , 70 )

dra w.pendown ()

for i in range ( 25 ):

  draw.right ( 15 )

  draw. forward ( 10 )