3

我是 VisPy 的新用户,并尝试从简单的示例开始(根据教程修改)。下面的代码在画布上绘制节点。1.如何绘制圆而不是点?2. 如何通过线连接这些节点(随机或最近的邻居或比 r_max 更近的邻居)?

import numpy as np
from vispy import app, scene
from vispy import gloo

c = app.Canvas(keys='interactive')
#c = scene.SceneCanvas(keys='interactive')

vertex = """
attribute vec2 a_position;
void main (void)
{
    gl_Position = vec4(a_position, 0.0, 1.0);
}
"""

fragment = """
void main()
{
    gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);
}
"""

program = gloo.Program(vertex, fragment)

program['a_position'] = np.c_[
        np.random.uniform(-0.5, +0.5, 1000).astype(np.float32),
        np.random.uniform(-0.5, +0.5, 1000).astype(np.float32)]



@c.connect
def on_resize(event):
    gloo.set_viewport(0, 0, *event.size)

@c.connect    
def on_draw(event):
    gloo.clear((0,0,0,1))
    program.draw('points')

c.show()
app.run();
4

0 回答 0