use*_*784 2 python drawing python-2.7 kivy
这是我在此处发布的文章的继续:在Kivy中使用和移动小部件/按钮
我想在Kivy中的两个节点(椭圆)之间创建一条线,以便可以在移动节点时动态更新端点。这是我当前的混乱框架:
class GraphEdge(Widget):
def __init__(self, **kwargs):
super(GraphEdge, self).__init__(**kwargs)
with self.canvas:
Line(points=[100, 100, 200, 100, 100, 200], width=1)
pass
Run Code Online (Sandbox Code Playgroud)
我只是为这些点输入了一些占位符值,因为我不确定如何开始使用App中其他小部件的值。
我的最终目标是能够选择两个节点,然后单击一个按钮以添加行(甚至更干净的行)。我并不是要有人为我制作这个,只是一些正确方向的指针会很棒:)。
链接中提供了更多信息,但如果需要,我很乐意在此处提供更多信息。
谢谢。
编辑:
附加信息:
我想根据一些事件来更新线的位置。例如,如果将椭圆移动到直线上,则希望最接近的边缘捕捉到椭圆并跟随它。
def snap_to_node(self, node):
if self.collide_widget(node):
print "collision detected"
self.line.points=[node.pos]
Run Code Online (Sandbox Code Playgroud)
(这只是一个很糟糕的尝试,我知道它根本不起作用。)最终目标是能够将“节点”与“边缘”连接起来。
编辑2:
所以我取得了一些进展。我创建了一个在时钟时间表中调用的更新方法:
def update(self, dt):
# detect node collision
self.edge.snap_to_node(self.node)
def snap_to_node(self, node):
if self.collide_widget(node):
print "collision detected"
self.line.points+=node.pos
Run Code Online (Sandbox Code Playgroud)
现在,我要使其仅更新一个点集(其想法是将其中一个线段捕捉到节点)。
到目前为止,此代码仅检测直线上某一点上的集合。另外,这些点不会检测到碰撞。
Line(points=[100, 100, 200, 100, 100, 200], width=1)
Run Code Online (Sandbox Code Playgroud)
^^您可以将其替换为
self.line = Line(points=[100, 100, 200, 100, 100, 200], width=1)
Run Code Online (Sandbox Code Playgroud)
然后,稍后再做类似self.line.width = 2或的操作来修改该行self.line.points = [200, 100, 100, 200, 200, 100]。
除此之外,我不确定您要问什么,您能否更具体?