pip install vispy
import numpy as np
import vispy
from vispy import app, gloo
from vispy.util.transforms import perspective, translate, rotate
from vispy.scene import visuals
python
class MyCanvas(app.Canvas):
def __init__(self):
app.Canvas.__init__(self, size=(800, 600), title='My VisPy Canvas')
def on_draw(self, event):
gloo.clear(color='black')
canvas = MyCanvas()
canvas.show()
vispy.app.run()
python
class MyCanvas(app.Canvas):
def __init__(self):
app.Canvas.__init__(self, size=(800, 600), title='My VisPy Canvas')
def on_draw(self, event):
gloo.clear(color='black')
program = gloo.Program("""
attribute vec2 position;
attribute vec3 color;
varying vec3 v_color;
void main() {
gl_Position = vec4(position, 0.0, 1.0);
v_color = color;
}
""",
"""
varying vec3 v_color;
void main() {
gl_FragColor = vec4(v_color, 1.0);
}
canvas = MyCanvas()
canvas.show()
vispy.app.run()
python
class MyCanvas(app.Canvas):
def __init__(self):
app.Canvas.__init__(self, size=(800, 600), title='My VisPy Canvas')
def on_draw(self, event):
gloo.clear(color='black')
def on_mouse_move(self, event):
if event.is_dragging:
dx, dy = event.delta
self.rotation[0] += dx
self.rotation[1] += dy
self.update()
def on_mouse_wheel(self, event):
self.scale *= 1.1 ** event.delta[1]
self.update()
def view(self):
rx, ry = self.rotation
return view
def projection(self):
width, height = self.size
canvas = MyCanvas()
canvas.show()
vispy.app.run()