# drawing.py # ---------- # By Patrick Wick # # This program will (hopefully) draw a dog from turtle import * import math # for the dog's ears def ear(rad,color): pendown() fillcolor(color) begin_fill() # draw an ellipse, rad is the "radius" of the ellipse for i in range(2): # two arcs, each one half of the ellipse circle(rad,90) # long side circle(rad//25,90) # short side end_fill() penup() # main part of the dog's face def face(rad,color): pendown() fillcolor(color) begin_fill() # draw an ellipse, rad is the "radius" of the ellipse for i in range(2): # two arcs, each one half of the ellipse circle(rad,90) # long side circle(rad//2,90) # short side end_fill() penup() def nose(rad): # circles are drawn CCW so if the turtle is facing right, the nose is upside down setheading(180) pendown() color = 'black' fillcolor(color) begin_fill() # initial position will need to be shifted +X by rad/2 to be centered for i in range(3): forward(rad) circle(rad,120) end_fill() penup() # reset position and do the dogs septum/upper lip forward(rad/2) left(90) forward(2*rad) x = xcor() y = ycor() pendown() # swoop right forward(2*rad) circle(rad,150) penup() goto(x,y) setheading(270) pendown() # swoop left forward(2*rad) circle(-rad,150) penup() def eye(rad,color): pendown() fillcolor(color) begin_fill() circle(rad) end_fill() penup() speed(0) penup() pencolor('black') pensize(4) hideturtle() faceLength = 200 right(20) goto(2*(faceLength/2)*math.sin(math.pi/4)*0.5,0) ear(-faceLength,'sienna') goto(-2*(faceLength/2)*math.sin(math.pi/4)*0.5,0) right(140) ear(faceLength,'sienna') goto(-2*(faceLength/2)*math.sin(math.pi/4)*0.5,0) setheading(-135) face(faceLength,'white') goto(-2*(faceLength/2)*math.sin(math.pi/4),-2*(faceLength)*math.sin(math.pi/4)*1.25) setheading(-45) face(faceLength,'sienna') setheading(0) goto(-2*(faceLength/2)*math.sin(math.pi/4)*0.4,-faceLength/2) eye(faceLength/12,'black') goto(2*(faceLength/2)*math.sin(math.pi/4)*0.4,-faceLength/2) eye(faceLength/12,'black') goto(faceLength/12,-2*(faceLength/2)*math.sin(math.pi/4)*1.25) nose(faceLength/6) done()