1 回答
TA贡献1829条经验 获得超4个赞
这是代码 - 但它对问题来说不太重要。
代码对问题总是很重要!
有足够的代码,而且问题相当模糊,我将尝试将您的代码翻译成 Python 的方法;-),看看您的问题是否仍然存在:
from turtle import Screen, Turtle
from random import random, randint
def quickshape(sides, size, thickness):
turtle.width(thickness)
angle = 360 / sides
for _ in range(sides):
turtle.forward(size)
turtle.right(angle)
def correct_position():
global x, y
x = randint(-400, 400)
y = randint(-250, 250)
def move_alot():
global x, y
x += randint(-100, 100)
y += randint(-100, 100)
print("My Doodle .co can draw you lots of shapes, depending on what you ask us!")
print()
print("Before we start, do you want day or night mode?")
goes = 1
while True:
mode = input("Mode: ")
if mode[0].lower() == 'd':
print("Day mode it is.")
mode = 'day'
break
if mode[0].lower() == 'n':
print("Night mode it is.")
mode = 'night'
break
print("Hmm... which mode?")
titlename = input("Title: ")
print("Configuring - takes a couple of seconds...")
screen = Screen()
screen.tracer(False)
screen.setup(width=1.0, height=1.0)
if mode == 'day':
screen.bgcolor("white")
else:
screen.bgcolor("black")
turtle = Turtle()
turtle.hideturtle()
while True:
screen.title(titlename + " [Waiting for input - do not close]")
pattern = "[Pattern {}]".format(goes)
sides = screen.numinput(pattern, "Number of sides:", default=6, minval=3, maxval=35)
if sides is None:
break
sides = int(sides) # numinput() returns float
numshapes = screen.numinput(pattern, "Number of shapes:", default=3, minval=1, maxval=50)
if numshapes is None:
break
numshapes = int(numshapes)
size = screen.numinput(pattern, "Length of each side:", default=25, minval=5, maxval=500)
if size is None:
break
thickness = screen.numinput(pattern, "Thickness of pen:", default=1, minval=1, maxval=10)
if thickness is None:
break
x = randint(-200, 200)
y = randint(-100, 100)
for part in range(1, numshapes + 1):
turtle.penup()
percentage = round(part/numshapes * 100, 2)
screen.title(titlename + " [Drawing pattern. " + str(percentage) + "% complete.]")
turtle.color(random(), random(), random())
if randint(1, 45) == 1:
move_alot()
else:
x += randint(-10, 5)
y += randint(-5, 10)
if not (-650 < x < 650 and -500 < y < 500):
correct_position()
turtle.setposition(x, y)
turtle.pendown()
quickshape(sides, size, thickness)
screen.title(titlename + " [Finished drawing pattern " + str(goes) + "]")
screen.update()
goes += 1
screen.mainloop()
我遗漏了以下功能:
要制作一组新图案,请关闭图案页面......但仅限于绘制时。
因为一旦关闭窗口,就无法再次启动 Python turtle。
添加回答
举报