当前在循环中绘制的对象
Object currently drawn in loop
我的代码有点问题,基本上我需要创建图中显示的模式
使用 John Zelle 教授编写的 graphics
模块(可用 here)。
这是10条直线,需要根据用户的选择制作不同大小的canvas。所以我决定循环它并在每行之间添加额外的 space,但是当我执行循环时我收到一条错误消息,说这条线已经画好了,有人知道如何避免这种情况吗?
from graphics import *
def Main():
valid = False
while not valid:
sizeInput= eval(input("PLease select a size, 7, 9, 11: "))
if sizeInput == 7 or sizeInput == 9 or sizeInput == 11 :
size= sizeInput*100
valid=True
else:
print("Invalid Number")
Draw(size)
def Draw(size):
win = GraphWin("Pat1",size,size)
PointX= Point(0,0)
PointY= Point(700,70)
line = Line(PointX,PointY)
i = 0
while i<10:
line.draw(win)
PointX.x+70
PointY.y+70
i=i+1
作为一个 Python 新手,我尝试了这个项目。这是我想出的。我确定需要进行优化并且需要添加错误检查,但它确实有效。
from graphics import *
def Main():
# Have user enter actual window size (ex: "500" for a 500x500 window)
size = int(input("Please enter a window size: "))
# Have user enter number of lines to draw
line_count = int(input("Please enter a line count: "))
# Create the window
win = GraphWin("Pat1", size, size)
# Calculate space between lines
step = size / line_count
# Renamed these to something more logical
point_start = Point(0, 0)
point_end = Point(size, step)
# Draw top half
for i in range(line_count):
line = Line(point_start, point_end)
line.draw(win)
point_start.x += step
point_end.y += step
point_start = Point(0, 0)
point_end = Point(step, size)
# Draw bottom half
for i in range(line_count):
line = Line(point_start, point_end)
line.draw(win)
point_start.y += step
point_end.x += step
Main()
我的代码有点问题,基本上我需要创建图中显示的模式
使用 John Zelle 教授编写的 graphics
模块(可用 here)。
这是10条直线,需要根据用户的选择制作不同大小的canvas。所以我决定循环它并在每行之间添加额外的 space,但是当我执行循环时我收到一条错误消息,说这条线已经画好了,有人知道如何避免这种情况吗?
from graphics import *
def Main():
valid = False
while not valid:
sizeInput= eval(input("PLease select a size, 7, 9, 11: "))
if sizeInput == 7 or sizeInput == 9 or sizeInput == 11 :
size= sizeInput*100
valid=True
else:
print("Invalid Number")
Draw(size)
def Draw(size):
win = GraphWin("Pat1",size,size)
PointX= Point(0,0)
PointY= Point(700,70)
line = Line(PointX,PointY)
i = 0
while i<10:
line.draw(win)
PointX.x+70
PointY.y+70
i=i+1
作为一个 Python 新手,我尝试了这个项目。这是我想出的。我确定需要进行优化并且需要添加错误检查,但它确实有效。
from graphics import *
def Main():
# Have user enter actual window size (ex: "500" for a 500x500 window)
size = int(input("Please enter a window size: "))
# Have user enter number of lines to draw
line_count = int(input("Please enter a line count: "))
# Create the window
win = GraphWin("Pat1", size, size)
# Calculate space between lines
step = size / line_count
# Renamed these to something more logical
point_start = Point(0, 0)
point_end = Point(size, step)
# Draw top half
for i in range(line_count):
line = Line(point_start, point_end)
line.draw(win)
point_start.x += step
point_end.y += step
point_start = Point(0, 0)
point_end = Point(step, size)
# Draw bottom half
for i in range(line_count):
line = Line(point_start, point_end)
line.draw(win)
point_start.y += step
point_end.x += step
Main()