【发布时间】:2016-06-08 08:36:00
【问题描述】:
我正在用 Python 制作一个抽象艺术模板生成器,它接受最小半径、最大半径和圆数的输入。它在随机的地方绘制随机的圆圈,也符合用户的规格。我想将 Turtle 图形转换为 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()
【问题讨论】:
-
我不是 python 之神,但也许这些代码示例会有所帮助:code.activestate.com/recipes/…