-
Notifications
You must be signed in to change notification settings - Fork 0
/
quad_scale.py
53 lines (45 loc) · 1.43 KB
/
quad_scale.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
53
# -----------------------------------------------------------------------------
# Python, OpenGL & Scientific Visualization
# www.labri.fr/perso/nrougier/python+opengl
# Copyright (c) 2017, Nicolas P. Rougier
# Distributed under the 2-Clause BSD License.
# -----------------------------------------------------------------------------
import math
from glumpy import app, gloo, gl
vertex = """
uniform float scale;
attribute vec2 position;
attribute vec4 color;
varying vec4 v_color;
void main()
{
gl_Position = vec4(scale*position, 0.0, 1.0);
v_color = color;
} """
fragment = """
varying vec4 v_color;
void main()
{
gl_FragColor = v_color;
} """
# Build the program and corresponding buffers (with 4 vertices)
quad = gloo.Program(vertex, fragment, count=4)
# Upload data into GPU
quad['color'] = [ (1,0,0,1), (0,1,0,1), (0,0,1,1), (1,1,0,1) ]
quad['position'] = [ (-1,-1), (-1,+1), (+1,-1), (+1,+1) ]
quad['scale'] = 1.0
# Create a window with a valid GL context
window = app.Window(color=(1,1,1,1))
time = 0.0
# Tell glumpy what needs to be done at each redraw
@window.event
def on_draw(dt):
global time
time += 1.0 * math.pi/180.0
window.clear()
quad["scale"] = math.cos(time)
quad.draw(gl.GL_TRIANGLE_STRIP)
# We set the framecount to 360 in order to record a movie that can
# loop indefinetly. Run this program with:
# python quad-scale.py --record quad-scale.mp4
app.run(framecount=360)