|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- from turtle import Turtle
-
- def draw_building(turtle):
- turtle.fillcolor('black')
- turtle.pencolor('black')
- draw_filled_rectangle(turtle,100, 210)
- turtle.left(90)
- for _ in range(5):
- draw_floor(turtle)
-
- def draw_floor(turtle):
- turtle.penup()
- turtle.forward(10)
- turtle.right(90)
- turtle.forward(10)
- turtle.pendown()
- for _ in range(3):
- draw_window(turtle)
- next_window(turtle)
- turtle.penup()
- turtle.backward(100)
- turtle.left(90)
- turtle.forward(30)
-
- def draw_window(turtle):
- turtle.fillcolor('yellow')
- turtle.pencolor('yellow')
- draw_filled_rectangle(turtle, 20, 30)
-
- def next_window(turtle):
- turtle.penup()
- turtle.forward(30)
- turtle.pendown()
-
-
- def draw_filled_rectangle(turtle, width, height):
- turtle.begin_fill()
- for _ in range(2):
- turtle.forward(width)
- turtle.left(90)
- turtle.forward(height)
- turtle.left(90)
- turtle.end_fill()
-
-
- sophia = Turtle()
- sophia.screen.bgcolor('blue')
- draw_building(sophia)
- sophia.hideturtle()
- sophia.screen.mainloop()
|