如何使用Vispy在不同时间绘制不同类型的线条?
我想绘制不同类型的线条,例如白色车道,黄色车道,白色长车道等,但是当我每次调用 Visual.Line() 时,它只能保留最后一个绘制事件,只有一种类型画布中的车道。 Vispy是否具有与plot相同或相似的操作,我们可以通过调用plot times来绘制不同的线?任何人都可以帮助我,我将非常感激!
这是代码:
for i in range(len(white_lane_nodes)-1):
white_lane = visuals.Line(pos=white_lane_nodes[i],
connect=lane_pair,
color=white,
parent=view.scene)
for i in range(len(yellow_lane_nodes)-1):
yellow_lane = visuals.Line(pos=yellow_lane_nodes[i],
connect=lane_pair,
color=orange,
parent=view.scene)
我尝试了示例代码来更新行,但它没有按我想要的方式工作,我不需要计时器。
def update(event):
for line in lines:
cale = [np.sin(np.pi * event.elapsed)+2,
np.cos(np.pi * event.elapsed)+2]
line.transform.scale = scale
timer = app.Timer('auto', connect=update, start=True)
I want to draw different types of lines, such as, white lane, yellow lane, white long lane and so on, but when I call visual.Line() eachtime, it can only keep the last draw-event , just only one type of lane in the Canvas. Does Vispy has the same or likely operation like plot, we can plot different lines by calling plot times? Can anybody help me, I will be appreciated it a lot!
Here is code:
for i in range(len(white_lane_nodes)-1):
white_lane = visuals.Line(pos=white_lane_nodes[i],
connect=lane_pair,
color=white,
parent=view.scene)
for i in range(len(yellow_lane_nodes)-1):
yellow_lane = visuals.Line(pos=yellow_lane_nodes[i],
connect=lane_pair,
color=orange,
parent=view.scene)
I tried the example code to update line, but it didn't works the way that I want, I dont need the Timer.
def update(event):
for line in lines:
cale = [np.sin(np.pi * event.elapsed)+2,
np.cos(np.pi * event.elapsed)+2]
line.transform.scale = scale
timer = app.Timer('auto', connect=update, start=True)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你说的是这个例子吧?
https://vispy.org/gallery/scene/line.html
在原始版本中示例代码,这就是线条的创建方式:
请注意线条对象是如何创建的 (
line = scene.visuals.Line
),然后存储在lines
列表中(lines.append(line)
)。您的代码似乎没有此行列表
。尝试将其添加回来,它应该可以工作。如果这不起作用,请检查脚本的输出是否有错误。如果有任何问题,您可以使用新信息更新上面的问题,并对此答案发表评论,让我知道您已经进行了更新。
You mean this example, right?
https://vispy.org/gallery/scene/line.html
In that original example code, this is how the lines are created:
Note how the line objects are created (
line = scene.visuals.Line
) and then stored in alines
list (lines.append(line)
). Your code doesn't seem to have this list oflines
. Try adding that back in and it should work.If that doesn't work, check the output of your script for errors. If there are any you can update your question above with the new information and comment on this answer to let me know that you've made an update.