我似乎无法绘制一个输入周期数的旋风。该代码应该让用户单击一个起点和终点,然后将使用从起点到终点的输入循环绘制一个旋风。
from math import *
from graphics import *
def main():
win = GraphWin("Drawing a Cyclone",600,450)
win.setCoords(0,0,600,450)
msg = "Please enter the number of cycles, and click the start and end positions in the window."
Text(Point(300, 438), msg).draw(win)
Text(Point(65,415),"# of cycles:").draw(win)
inbox =Entry(Point(130,415),5)
inbox.draw(win)
start=win.getMouse()
start.setFill("red")
start.draw(win)
stop=win.getMouse()
stop.setFill("red")
stop.draw(win)
cycles=eval(inbox.getText())
radius = 0
length = sqrt((stop.x-start.x)**2+(stop.y-start.y)**2)
step_radius = length / (120*cycles)
radian = atan((stop.y-start.y)/(stop.x-start.x))
initial_angle = int(degrees(radian))
for i in (0, cycles*360, 3):
radius = radius + step_radius
theta=radians(initial_angle + (360*cycles*i)+3*i)
stop.x = start.x + radius*cos(theta)
stop.y = start.y + radius*sin(theta)
line=Line(start,stop)
line.draw(win)
start.x=stop.x
start.y=stop.y
win.getMouse()
win.close()
main()