leafleafleafDocy banner shape 01Docy banner shape 02Man illustrationFlower illustration

Python turtle module combat: complete code for drawing a robot cat

Estimated reading: 3 minutes 16 views

Whether your program is compiled successfully, the following is the complete code for drawing the robot cat, if there is an error, please check and modify it with the correct code in time:

The complete code of the robot cat:

from turtle import *
def drawRound(size,filled): #Draw a circle
    pendown()        
    if filled==True: #Determine whether to fill the color
        begin_fill()
    setheading(180)  
    circle(size,360)
    if filled==True:
        end_fill()   
def drawRect(length,width,filled): #Draw a rectangle
    setheading(0)    
    pendown()        
    if filled==True:
        begin_fill()
    forward(length)  
    right(90)        
    forward(width)   
    right(90)        
    forward(length)  
    right(90)        
    forward(width)   
    if filled==True:
        end_fill()  
   
def head(): #head
    #draw a big blue circle
    color("blue","blue")
    penup()
    goto(0,100)
    drawRound(75,True)
    #draw a white circle
    color("white","white")
    penup()
    goto(0,72)
    drawRound(60,True)
   
def eyes(): #eyes
    #left eye socket
    color("black","white")
    penup()
    goto(-15,80)
    drawRound(17,True)
    #right eye socket
    color("black","white")
    penup()
    goto(19,80)
    drawRound(17,True)
    #left eyeball
    color("black","black")
    penup()
    goto(-8,70)
    drawRound(6,True)   
    color("white","white")
    penup()
    goto(-8,66)
    drawRound(2,True)
    #right eyeball
    color("black","black")
    penup()
    goto(12,70)
    drawRound(6,True)   
    color("white","white")
    penup()
    goto(12,66)
    drawRound(2,True)   
   
def nose(): #nose
    color("red", "red")
    penup()
    goto(0,40)
    drawRound(7,True)
  
def mouth(): #mouth
    #mouth
    color("black","black")
    penup()
    goto(-30,-20)
    pendown()
    setheading(-27)
    circle(70,55)
    #people
    penup()
    goto(0,26)    
    pendown()
    goto(0,-25)
def whiskers(): #whiskers   
    color("black","black")
    #left middle beard
    penup()
    goto(10,5)    
    pendown()
    goto(-40,5)
    #right middle beard
    penup()
    goto(10,5)    
    pendown()
    goto(40,5)
    #top left beard
    penup()
    goto(-10,15)    
    pendown()
    goto(-40,20)
    #top right beard
    penup()
    goto(10,15)    
    pendown()
    goto(40,20)
    #lower left beard
    penup()
    goto(-10,-5)    
    pendown()
    goto(-40,-10)
    #lower right beard
    penup()
    goto(10,-5)    
    pendown()
    goto(40,-10)
   
def body(): #body
    #blue body
    color("blue","blue")
    penup()
    goto(-50,-40)
    drawRect(100,80,True)
  
    #white belly
    color("white","white")
    penup()
    goto(0,-30)
    drawRound(40,True)
    #red ribbon
    color("red", "red")
    penup()
    goto(-60,-35)
    drawRect(120,10,True)
    #white legs
    color("white","white")
    penup()
    goto(15,-127)
    pendown()
    begin_fill()
    setheading(90)
    circle(14,180)
    end_fill()
   
def feet(): #foot
    #leftfoot
    color("black","white")
    penup()
    goto(-30,-110)
    drawRound(20,True)  
    #rightfoot
    color("black","white")
    penup()
    goto(30,-110)
    drawRound(20,True)
def arms(): #arms
    #left arm
    color("blue","blue")
    penup()
    begin_fill()
    goto(-51,-50)    
    pendown()
    goto(-51,-75)
    left(70)
    goto(-76,-85)
    left(70)
    goto(-86,-70)
    left(70)
    goto(-51,-50)
    end_fill()
    #right arm
    color("blue","blue")
    penup()
    begin_fill()
    goto(49,-50)    
    pendown()
    goto(49,-75)
    left(70)
    goto(74,-85)
    left(70)
    goto(84,-70)
    left(70)
    goto(49,-50)
    end_fill()
   
def hands(): #hands
    #lefthand
    color("black","white")
    penup()
    goto(-90,-71)
    drawRound(15,True)
    #right hand
    color("black","white")
    penup()
    goto(90,-71)
    drawRound(15,True)
   
def bell(): #bell
    #Yellow solid circle represents copper bell
    color("yellow","yellow")
    penup()
    goto(0,-41)
    drawRound(8,True)
    #Black rectangles indicate patterns
    color("black","black")
    penup()
    goto(-10,-47)    
    drawRect(20,4,False)
    #The black solid circle represents the impacted metal shot
    color("black","black")
    penup()
    goto(0,-53)
    drawRound(2,True)
   
def package(): #Pocket
    #semicircle
    color("black","black")
    penup()
    goto(-25,-70)
    pendown()
    setheading(-90)
    circle(25,180)
    goto(-25,-70)
    hideturtle()
#Set the window size
setup(500,500)
#setup brush
speed(10)      
#shape("turtle")
colormode(255)
#draw Doraemon
head() #head
eyes() #eyes
nose() #nose
mouth() #mouth
whiskers() #moustache
body() #body
feet() #foot
arms() #arms
hands() #hands
bell() #bell
package() #Pocket

Leave a Comment

CONTENTS