# drawing.py # ---------- # By Tom Naber # # (Briefly describe what this program does.) # This program is going to draw a snowman, some snowflakes, and # trees from turtle import * from math import sqrt """this function takes the turtle to the lower left corner of the drawing""" def goToCorner(): penup() setx(-250) sety(-250) pendown() """ This function will turn the turtle left the specified angle, and then will move the turtle the specified distance without drawing anything then returns to the direction the turtle was pointing. """ def fly (angle, dist): left(angle) penup() forward(dist) pendown() right(angle) """This function draws a rectangle with a top and bottom of size width and a left and right size of size height, with a fill color and line color specified.""" def drawRectangle(width, height, fill, line): color(line) fillcolor(fill) begin_fill() forward(width) left(90) forward(height) left(90) forward(width) left(90) forward(height) left(90) end_fill() """draws an isosceles triangle with legs the length of size and a color/outline as specified from fill and line.""" def drawTriangle(size, fill, line): color(line) fillcolor(fill) begin_fill() forward(size * sqrt(2)/2) left(135) forward(size) left(90) forward(size) left(135) forward(size * sqrt(2)/2) end_fill() """ This function draws a tree with a brown rectangular trunk, and green triangles as the top. """ def drawTree(size): drawRectangle(size, size * 2, "saddle brown", "black") fly(90, size * 2) forward(size/2) drawTriangle(size * 4, "dark green", "dark green") fly(90, size * 1.5) drawTriangle(size * 3, "dark green", "dark green") fly(90, size * 1.5) drawTriangle(size * 2, "dark green", "dark green") fly(-90, size * 5) fly(180, size/2) """ draws a snowflake of specified size. The turtle ends in the same place that it starts. """ def drawSnowflake(size): pensize(2) color("alice blue") left(90) for number in range(1, 4): forward(size) fly(120, size/2) left(240) right(90) """The code below draws a picture of a mountain with five equally spaced trees at its base, and then 28 snowflakes in the air.""" goToCorner() fly(180,60) drawRectangle(300 * sqrt(2) + 120, 300, "sky blue", "black") fly(0, 150 * sqrt(2) + 60) drawTriangle(300, "slate gray", "black") fly(90, 100 * sqrt(2)) drawTriangle(100, "white", "black") goToCorner() for number in range(1, 6): drawTree(15) fly(0, 300 * sqrt(2)/4 - 3.75) goToCorner() fly(90, 270) for number in range(1, 11): drawSnowflake(8) fly(-60, 30) drawSnowflake(8) fly(-120, 40) drawSnowflake(8) fly(10, 25) drawSnowflake(8) fly(80,40) drawSnowflake(8) fly(40,25) done()