在python turtle graphics绘制的图形_在Python-Turtle图形中绘制线条并按屏幕大小限制它们...

我需要为我的方形螺旋绘图程序添加正确的处理超过屏幕尺寸的初始长度,但是,我不确定屏幕尺寸的长度。我假设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)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值