我正在用Python制作一个抽象艺术模板生成器,它需要输入最小半径、最大半径和圆的数量。它会在随机位置绘制随机圆形,并满足用户的规格要求。我想将海龟绘图转换为PNG格式,以便用户可以根据需要编辑模板,但我不知道该如何操作。以下是我的代码:
import random
import time
import turtle
print("Abstract Art Template Generator")
print()
print("This program will generate randomly placed and sized circles on a blank screen.")
num = int(input("Please specify how many circles you would like to be drawn: "))
radiusMin = int(input("Please specify the minimum radius you would like to have: "))
radiusMax = int(input("Please specify the maximum radius you would like to have: "))
screenholder = input("Press ENTER when you are ready to see your circles drawn: ")
t = turtle.Pen()
win = turtle.Screen()
def mycircle():
x = random.randint(radiusMin,radiusMax)
t.circle(x)
t.up()
y = random.randint(0,360)
t.seth(y)
if t.xcor() < -300 or t.xcor() > 300:
t.goto(0, 0)
elif t.ycor() < -300 or t.ycor() > 300:
t.goto(0, 0)
z = random.randint(0,100)
t.forward(z)
t.down()
for i in range(0, num):
mycircle()
turtle.done()