-
Notifications
You must be signed in to change notification settings - Fork 4
/
exercise-2.py
52 lines (41 loc) · 1.1 KB
/
exercise-2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import numpy as np
from vispy import app
from vispy import gloo
from vispy.gloo import gl
app.use('glfw')
vertex = """
attribute float x;
attribute float y;
void main (void)
{
gl_Position = vec4(x, y, 0.0, 1.0);
}
"""
fragment = """
void main()
{
gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);
}
"""
class Window(app.Canvas):
def __init__(self, n=50):
app.Canvas.__init__(self)
self.program = gloo.Program(vertex, fragment, n)
gl.glClearColor(1,1,1,1)
self.program['x'] = np.linspace(-1.0, +1.0, n)
self.program['y'] = np.random.uniform(-0.5, +0.5, n)
self._timer = app.Timer(1.0/60)
self._timer.connect(self.on_timer)
self._timer.start()
def on_resize(self, event):
gl.glViewport(0, 0, event.size[0], event.size[1])
def on_draw(self, event):
gl.glClear(gl.GL_COLOR_BUFFER_BIT)
self.program.draw(gl.GL_LINE_STRIP)
def on_timer(self, event):
n = self.program['y'].size
self.program['y'] = np.random.uniform(-0.5, +0.5, n)
self.update()
window = Window(n=100)
window.show()
app.run()