from turtle import *
pensize(1); speed(0)
def square(x, y, size, c):
pu(); goto(x, y); pd(); color(c)
begin_fill()
for _ in range(4): fd(size); rt(90)
end_fill()
color("red")
while size >= d:
for _ in range(4): fd(size); rt(90)
size -= d
n = int(input())
d = 40
for i in range(n, 0, -1):
if i ==1: square(0, 0, d, "yellow")
else:
L = (i-1) * d
x, y = -L//2, L//2
square(x, y, d * i, "yellow")
square(x, y, d, "blue"); square(x + L, y, d, "blue")
square(x, y - L, d, "blue"); square(x + L, y - L, d, "blue")
ht()
Bình luận
code b1
2 bình luận nữa