我需要为我的方形螺旋绘图程序添加正确的处理超过屏幕尺寸的初始长度,但是,我不确定屏幕尺寸的长度。我假设Turtle graphics illustrator从屏幕中间开始,它就在程序窗口的中间。在这种情况下,下面的代码应该工作,我只需要知道屏幕大小的长度。在while startLength >(screen size here):
startLength=float(input("please enter a value greater than zero: "))
此外,这需要在所有平台上通用,并假设没有wx这样的跨平台。在
我尝试过:
^{pr2}$
但是当我输入300-350之间的长度时,它超过了窗口大小。此外,当它完成绘制第一条线并旋转90度以绘制螺旋线的下一条线时(向下),它也会超出屏幕的大小。在
我正在使用import turtle
这是我的程序的完整代码。在from turtle import *
import turtle
startLength = float(input("Please enter the length of first side: "))
while startLength < 0:
startLength=float(input("please enter a value greater than zero: "))
while startLength > (turtle.window_width()/2):
startLength=float(input("please enter a value that will fit in the window: "))
decrement = int(input("Please enter the change in length of side: "))
while startLength > decrement:
forward(startLength)
right(90)
startLength = startLength - decrement
forward(startLength)
right(90)