File: rescalingmarkers.py

package info (click to toggle)
python-vispy 0.15.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,868 kB
  • sloc: python: 59,799; javascript: 6,800; makefile: 69; sh: 6
file content (63 lines) | stat: -rw-r--r-- 2,006 bytes parent folder | download | duplicates (2)
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
# -*- coding: utf-8 -*-
# vispy: gallery 30
# -----------------------------------------------------------------------------
# Copyright (c) Vispy Development Team. All Rights Reserved.
# Distributed under the (new) BSD License. See LICENSE.txt for more info.
# -----------------------------------------------------------------------------
""" Display markers at different sizes and line thicknessess.
"""

import numpy as np
import vispy.scene as scene
from vispy.scene import visuals
from vispy import app

n = 500
pos = np.zeros((n, 2))
colors = np.ones((n, 4), dtype=np.float32)
radius, theta, dtheta = 1.0, 0.0, 5.5 / 180.0 * np.pi
for i in range(500):
    theta += dtheta
    x = radius * np.cos(theta)
    y = radius * np.sin(theta)
    r = 10.1 - i * 0.02
    radius -= 0.45
    pos[i] = x/512.+.5, 1.-(y/512.+.5)
pos *= 512


class Canvas(scene.SceneCanvas):

    def __init__(self):
        scene.SceneCanvas.__init__(
            self,
            keys='interactive', size=(512, 512),
            title="Marker demo [press space to change marker]",
            bgcolor='white'
        )
        self.unfreeze()
        self.index = 0
        self.markers = visuals.Markers(scaling=False)
        self.markers.set_data(pos, face_color=(0, 1, 0))
        self.markers.symbol = self.markers.symbols[self.index]
        self.text = visuals.Text(self.markers.symbols[self.index],
                                 pos=(80, 15), font_size=14,
                                 color='black', parent=self.scene)
        self.freeze()

    def on_key_press(self, event):
        if event.text == ' ':
            self.index = (self.index + 1) % (len(self.markers.symbols))
            self.markers.symbol = self.markers.symbols[self.index]
            self.text.text = self.markers.symbols[self.index]
            self.update()


canvas = Canvas()
grid = canvas.central_widget.add_grid()
vb1 = grid.add_view(row=0, col=0)
vb1.add(canvas.markers)

if __name__ == '__main__':
    canvas.show()
    app.run()