我目前正在使用graphics.py,我正试图弄清楚如何将一堆线移动到一起。我写的程序绘制了一个线条网格,我不确定如何写一些东西,每隔X秒移动整个网格1,1秒。有没有办法将所有线合并在一起?或者,怎么会这样做呢?
from graphics import *
win = GraphWin("Thing",500,500)
win.setCoords(0.0, 0.0, 10.0, 10.0)
a = 0
slength = 1
while True:
a = a + slength
vgrid = Line(Point(a,0),Point(a,500))
hgrid = Line(Point(0,a),Point(500,a))
vgrid.draw(win)
hgrid.draw(win)
答案 0 :(得分:0)
你可以尝试将它们存储在一个类中,然后一起访问它们的位置。请记住,我对graphics.py库一无所知,但您应该可以执行win = GraphWin("Thing",500,500)
win.setCoords(0.0, 0.0, 10.0, 10.0)
class MyDrawing:
def __init__(self):
self.horizontals = []
self.verticals = []
a = 0
slength = 1
while True:
a = a + slength
self.verticals.append(Line(Point(a,0),Point(a,500)))
self.horizontals.append(hgrid = Line(Point(0,a),Point(500,a)))
for line in self.verticals:
line.draw(win)
for line in self.horizontals:
line.draw(win)
def move(self, x, y):
for line in self.verticals:
line.Point1 = Point(line.Point1.x + x, line.Point1.y + y)
line.Point2 = Point(line.Point2.x + x, line.Point2.y + y)
for line in self.horizontals:
line.Point1 = Point(line.Point1.x + x, line.Point1.y + y)
line.Point2 = Point(line.Point2.x + x, line.Point2.y + y)
之类的操作。然后你应该能够做到:
eof