Из следующего списка графических объектов, я сказал undraw
все они, один за другим, но я не знаю как.Undraw список графических объектов
win = GraphWin("plot", 500, 500) #defines the graphical window to work with
win.setBackground("white") #white background
win.setCoords(0, -10, 10, 10) #the specified coordinates are as such
Line(Point(0,0), Point(10,0)).draw(win) #draws the x-axis for clarity
def plot(fun, color): #user defines a function (of x) and the colour it appears with
listP = []
for i in range(0,1001): #I am told to sample points in the interval x(0,10) at the
#specified rate (one thousand times)
x = i/100
try:
y = eval(fun)
except(ZeroDivisionError, ValueError): #to avoid program crash on division by 0
pass #or definition errors like log(x) for x=0
else:
p = Point(x,y) #for every x,y combination, defines a point
p.draw(win) #which is then plotted
p.setFill(color) #and coloured according to specification
listP.append((x,y)) #and then added to a list of points
return(listP) #in the end I am told to return the list
Теперь, учитывая этот список, я сказал, что я должен тогдаundraw
каждая точка, но как я могу позвонить по существующим точкам/графических объектов? Попытка теперь определить точку p = Point(x,y)
для каждого набора x,y
в списке listP
создает только новые точки, поэтому я не могу использовать p.undraw()
.
У меня возникает соблазн использовать «бедный человек» для того, чтобы просто нарисовать белую коробку над существующими точками, но в упражнении конкретно говорится, что я должен указывать точку для точки, и она полностью меня превзошла.