七彩正方形矩阵
import turtle as tt.setup(400,400)
t.bgcolor("black")
t.speed(0)
t.penup()
def square(a):
t.pendown()
t.begin_fill()
for i in range(4):
t.forward(a)
t.right(90)
t.end_fill()
t.penup()
t.color("white","yellow")
n = 1
y = 200
for i in range(10):
t.goto(-200,y)
for j in range(10):
if n % 7 == 1:
t.color("red")
elif n % 7 == 2:
t.color("orange")
elif n % 7 == 3:
t.color("yellow")
elif n % 7 == 4:
t.color("green")
elif n % 7 == 5:
t.color("cyan")
elif n % 7 == 6:
t.color("blue")
else:
t.color("purple")
square(40)
t.forward(40)
n += 1
y -= 40
t.hideturtle()
t.done()
页:
[1]