My turtle
Landscape: House in the Forest
![]()
Task: Build Landscape
Code:
import turtle from random import randint from math import sqrt # Screen settings screen = turtle.Screen() screen.setup(width=600, height=400) screen.bgcolor("light blue") pic = turtle.Turtle() pic.speed(0) def grass (h, s, r): for i in range(r): ht = randint(0, h) pic.pencolor("green") pic.pensize(s) pic.setheading(90) pic.forward(ht) pic.backward(ht) pic.setheading(0) pic.forward(s) def rectangle (xa, ya, xc, yc): pic.penup() pic.goto(xa,ya) pic.pendown() pic.begin_fill() pic.goto(xc,ya) pic.goto(xc,yc) pic.goto(xa,yc) pic.goto(xa,ya) pic.end_fill() def tree (c,s): #c — leg of the triangle, S — number of cycles def triangle (c): pic.color("dark green") pic.begin_fill() pic.setheading(315) pic.forward(c) pic.setheading(180) pic.forward(sqrt(2*c*c))#hypotenuse pic.setheading(45) pic.forward(c) pic.end_fill() for i in range (s): c=c*3/2 #Enlarge the next triangle to 3/2c. triangle(c) pic.setheading(270) pic.forward(c/3) #to descend to с/3 def sun (rd, sx, sy, ang): pic.penup() pic.goto(sx,sy) pic.pendown() pic.color("yellow") for i in range(50): dis = randint(10, 100) ang = ang + 15 pic.pensize(2) pic.setheading(ang) pic.forward(dis) pic.backward(dis) pic.dot(rd) # land pic.pencolor("green") pic.fillcolor("green") rectangle (-300, 0, 300, -200) grass(10, 3, 200) # sun sun(50, 220, 140, 0) # house pic.pencolor("grey") pic.fillcolor("white") rectangle (0, 20, 200, -100) pic.pencolor("brown") pic.fillcolor("brown") pic.begin_fill() pic.setheading(180) pic.forward(20) pic.setheading(60) pic.forward(60) pic.setheading(0) pic.forward(180) pic.setheading(300) pic.forward(60) pic.setheading(180) pic.forward(240) pic.end_fill() pic.penup() # wndow rectangle (20, 0, 90, -60) pic.penup() pic.pencolor("white") pic.fillcolor("light blue") rectangle (30, -10, 50, -50) rectangle (60, -10, 80, -50) # door pic.pencolor("brown") pic.fillcolor("brown") pic.begin_fill() rectangle (120, 0, 180, -100) pic.end_fill() pic.penup() pic.pencolor("light salmon") rectangle (130, -10, 170, -100) # cloud pic.penup() pic.pencolor("white") pic.goto(-250, 150) pic.dot(60) pic.setheading(340) pic.forward(40) pic.dot(80) pic.setheading(0) pic.forward(40) pic.dot(60) pic.setheading(180) pic.forward(50) pic.dot(60) # tree pic.goto(-250,50) tree(10,4) pic.goto(-150,140) tree(15,6) # stepway pic.penup() pic.goto(120, -100) pic.pencolor("tan") pic.fillcolor("tan") pic.pendown() pic.begin_fill() pic.setheading(240) pic.forward(110) pic.setheading(0) pic.forward(170) pic.setheading(120) pic.forward(110) pic.setheading(180) pic.forward(60) pic.end_fill() pic.hideturtle() screen.mainloop()
2026-07-09 08:49:25
Comments
No comments yet. Be the first to leave one!
Leave a Comment