Draw a house

mail@pastecode.io avatar
unknown
python
2 years ago
2.5 kB
12
Indexable
Never
import turtle  
import math  
  
screen = turtle.Screen()  
screen.bgcolor("skyblue")  
  
george = turtle.Turtle()  
george.color("black")  
george.shape("turtle")  
george.speed(10)  
  
george.pencolor("black")  
george.fillcolor("white")  
  
def drawTriangle(t, length, color):  
 t.fillcolor(color)  
 t.begin_fill()  
 t.forward(length)  
 t.left(135)  
 t.forward(length / math.sqrt(2))  
 t.left(90)  
 t.forward(length / math.sqrt(2))  
 t.left(135)  
 t.end_fill()  
  
def drawRectangle(t, width, height, color):  
 t.fillcolor(color)  
 t.begin_fill()  
 t.forward(width)  
 t.left(90)  
 t.forward(height)  
 t.left(90)  
 t.forward(width)  
 t.left(90)  
 t.forward(height)  
 t.left(90)  
 t.end_fill()  
  
#Draw house  
george.penup()  
george.goto(-100,100)  
george.pendown()  
  
george.begin_fill()  
  
george.right(90)  
george.forward(200)  
george.left(90)  
george.forward(200)  
george.left(90)  
george.forward(200)  
george.left(90)  
george.forward(200)  
  
george.goto(0,150)  
george.goto(100,100)  
george.penup()  
george.end_fill()  
  
#Draw Door  
george.goto(-40,-100)  
george.setheading(90)  
  
george.pendown()  
george.forward(130)  
george.right(90)  
george.forward(80)  
george.right(90)  
george.forward(130)  
george.penup()  
  
#Draw door knob  
george.goto(-30,-30)  
george.setheading(90)  
george.fillcolor("black")  
george.begin_fill()  
george.circle(5)  
george.end_fill()  
  
# Tree base  
george.penup()   
george.goto(150, -100)  
george.pendown()  
george.setheading(0)  
drawRectangle(george, 20, 40, "brown")  
  
# Tree top  
george.penup()   
george.goto(115, -60)  
george.pendown()  
drawTriangle(george, 90, "lightgreen")  
george.penup()   
george.goto(120, -15)  
george.pendown()  
drawTriangle(george, 80, "lightgreen")  
george.penup()   
george.goto(125, 25)  
george.pendown()  
drawTriangle(george, 70, "lightgreen")  
  
  
#Sun body  
george.penup()  
george.goto(200,200)  
george.setheading(90)  
george.pendown()  
george.fillcolor("yellow")  
george.begin_fill()  
george.circle(30)  
george.end_fill()  
  
#Sun spokes (using a loop which runs 8 times  
  
george.penup()  
george.goto(170,200)  
  
for i in range(8):  
 george.penup()  
 george.forward(30)  
 george.pendown()  
 george.forward(20)  
 george.penup()  
 george.backward(50)  
 george.left(45)