📅  最后修改于: 2023-12-03 15:38:11.182000             🧑  作者: Mango
本篇文章将介绍如何使用Python语言生成一个方形多色方形螺旋图形。
import turtle
import random
window = turtle.Screen()
window.setup(width=1000, height=1000)
window.bgcolor("black")
pen = turtle.Turtle()
pen.speed(0)
pen.width(2)
pen.hideturtle()
colors = ["red", "orange", "yellow", "green", "blue", "purple"]
size = 20
def square():
pen.color(random.choice(colors))
pen.begin_fill()
for i in range(4):
pen.forward(size)
pen.left(90)
pen.end_fill()
def spiral():
for i in range(1, 501):
square()
pen.right(3)
size += 0.03
spiral()
import turtle
import random
window = turtle.Screen()
window.setup(width=1000, height=1000)
window.bgcolor("black")
pen = turtle.Turtle()
pen.speed(0)
pen.width(2)
pen.hideturtle()
colors = ["red", "orange", "yellow", "green", "blue", "purple"]
size = 20
def square():
pen.color(random.choice(colors))
pen.begin_fill()
for i in range(4):
pen.forward(size)
pen.left(90)
pen.end_fill()
def spiral():
for i in range(1, 501):
square()
pen.right(3)
size += 0.03
spiral()
生成的多色方形螺旋图形如下:
本篇文章简要介绍了使用Python语言生成方形多色方形螺旋图形的实现过程,读者可以根据需要对代码进行更改和优化,以得到更满意的结果。