Question

Write a function that draw your initials. (Using python 3 turtle) (H, Z)

Write a function that draw your initials. (Using python 3 turtle)

(H, Z)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

# code to copy (please indent using screenshots if code gets messed-up)

# import necessary libraries
import turtle
import random

# points of alphabets to move turtle to draw
points = {
    'H': ((0,0), (0,1),
          (0,0.5),(0.75,0.5),
          (0.75,1),(0.75,0)),
    'Z': ((0,1),(0.75,1),
          (0,0),(0.75,0))}

# define function drawmsg which print the given message
# takes 4 arguments (1.Message to draw, 2. font size,
#                    3 & 4. x and y position from where alphabets to draw)
def drawmsg(msg,sizefont,x,y) :
    # iterate over each Alphabets to draw
    for char in msg:            
        if char in points:
            dots = points[char]    # fetch the point to move turtle
            drawturtle.penup()

            # draw character
            for d in dots :
                drawturtle.goto(x +d[0]*sizefont, y+ d[1]*sizefont)
                drawturtle.pendown()
            x += sizefont
    
        if char == " " :
            x += sizefont
        x += charSpacing 


# initialize turtle object
drawturtle = turtle.Turtle()
drawturtle.hideturtle()
drawturtle.speed(0)
drawturtle.pensize(2)      # size of pen (can increase or decrease based on requirement)

windowObj = turtle.Screen()   # initialize screen to display
windowObj.bgcolor("#000001")  # color of background
sizefont = 80        # font size (can increase or decrease based on requirement)
color = "#FF00FE"    # color of character 
charSpacing = 5

msg = "H Z"

drawturtle.color(color)
drawmsg(msg,sizefont,-190,0)    
windowObj.exitonclick()        # to hold screen 

#screenshot of the code

1import necessary 1ibraries 2 import turtle 3 import randonm 5 # points of alphabets to move turtle to draw 6 points (0,0.5),36 drawturtle.hideturtle) 37 drawturtle.speed(0) 38 drawturtle.pensize(2) 39 40 windowObj-: turtle . Screen() # initialize sc

# screeenshot of the output

Python Turtle Graphics

Add a comment
Know the answer?
Add Answer to:
Write a function that draw your initials. (Using python 3 turtle) (H, Z)
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT