-
-
Notifications
You must be signed in to change notification settings - Fork 99
/
Copy patharrow.py
68 lines (61 loc) · 2.26 KB
/
arrow.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# -----------------------------------------------------------------------------
# Python & OpenGL for Scientific Visualization
# www.labri.fr/perso/nrougier/python+opengl
# Copyright (c) 2017, Nicolas P. Rougier
# Distributed under the 2-Clause BSD License.
# -----------------------------------------------------------------------------
import numpy as np
from glumpy import app, gl, gloo
from glumpy.transforms import Position, OrthographicProjection, PanZoom
# Create window
window = app.Window(width=2*512, height=512, color=(1,1,1,1))
# What to draw when necessary
@window.event
def on_draw(dt):
window.clear()
program.draw(gl.GL_POINTS)
program['orientation'] += np.pi/1024.0
# Setup some markers
n = 500+1
data = np.zeros(n, dtype=[('position', np.float32, 2),
('fg_color', np.float32, 4),
('bg_color', np.float32, 4),
('size', np.float32, 1),
('head', np.float32, 1),
('orientation', np.float32, 1),
('linewidth', np.float32, 1)])
data = data.view(gloo.VertexBuffer)
data['linewidth'] = 1
data['fg_color'] = 0, 0, 0, 1
data['bg_color'] = 0, 0, 0, 1
data['orientation'] = 0
data['head'] = 0.25
radius, theta, dtheta = 245.0, 0.0, 6.5 / 180.0 * np.pi
for i in range(500):
theta += dtheta
x = 256 + radius * np.cos(theta)
y = 256 + radius * np.sin(theta)
r = 10.1 - i * 0.01
radius -= 0.4
data['orientation'][i] = theta + np.pi
data['position'][i] = x, y
data['size'][i] = 2 * r
data['linewidth'][i] = 1.5 - 0.5*i/500.
data['position'][-1] = 512+256, 256
data['size'][-1] = 512/np.sqrt(2)
data['linewidth'][-1] = 16.0
data['fg_color'][-1] = 0, 0, 0, 1
data['bg_color'][-1] = .95, .95, .95, 1
data['orientation'][-1] = 0
program = gloo.Program("arrows/arrow.vert", "arrows/arrow.frag")
program.bind(data)
program['antialias'] = 1.00
# "stealth", "curved", "angle_30", "angle_60", "angle_90",
# "triangle_30", "triangle_60", "triangle_90"
program['arrow'] = "stealth"
# "stroke", "filled" or "outline"
program['paint'] = "filled"
transform = OrthographicProjection(Position("position"))
program['transform'] = transform
window.attach(transform)
app.run()