|
| 1 | +""" |
| 2 | +Demonstration of Tube |
| 3 | +""" |
| 4 | + |
| 5 | +print('testing!') |
| 6 | +import ctypes |
| 7 | +print('imported ctypes') |
| 8 | +print(ctypes.__dict__) |
| 9 | +print('dict done') |
| 10 | +import ctypes.util |
| 11 | +print('imported util') |
| 12 | +print(ctypes.util.find_library) |
| 13 | + |
| 14 | +import sys |
| 15 | +from vispy import scene |
| 16 | +from vispy.geometry.torusknot import TorusKnot |
| 17 | + |
| 18 | +from colorsys import hsv_to_rgb |
| 19 | +import numpy as np |
| 20 | + |
| 21 | +canvas = scene.SceneCanvas(keys='interactive', bgcolor='white') |
| 22 | +canvas.view = canvas.central_widget.add_view() |
| 23 | + |
| 24 | +points1 = TorusKnot(5, 3).first_component[:-1] |
| 25 | +points1[:, 0] -= 20. |
| 26 | +points1[:, 2] -= 15. |
| 27 | + |
| 28 | +points2 = points1.copy() |
| 29 | +points2[:, 2] += 30. |
| 30 | + |
| 31 | +points3 = points1.copy() |
| 32 | +points3[:, 0] += 41. |
| 33 | +points3[:, 2] += 30 |
| 34 | + |
| 35 | +points4 = points1.copy() |
| 36 | +points4[:, 0] += 41. |
| 37 | + |
| 38 | +colors = np.linspace(0, 1, len(points1)) |
| 39 | +colors = np.array([hsv_to_rgb(c, 1, 1) for c in colors]) |
| 40 | + |
| 41 | +vertex_colors = np.random.random(8 * len(points1)) |
| 42 | +vertex_colors = np.array([hsv_to_rgb(c, 1, 1) for c in vertex_colors]) |
| 43 | + |
| 44 | +l1 = scene.visuals.Tube(points1, |
| 45 | + shading='flat', |
| 46 | + color=colors, # this is overridden by |
| 47 | + # the vertex_colors argument |
| 48 | + vertex_colors=vertex_colors, |
| 49 | + tube_points=8) |
| 50 | + |
| 51 | +l2 = scene.visuals.Tube(points2, |
| 52 | + color=['red', 'green', 'blue'], |
| 53 | + shading='smooth', |
| 54 | + tube_points=8) |
| 55 | + |
| 56 | +l3 = scene.visuals.Tube(points3, |
| 57 | + color=colors, |
| 58 | + shading='flat', |
| 59 | + tube_points=8, |
| 60 | + closed=True) |
| 61 | + |
| 62 | +l4 = scene.visuals.Tube(points4, |
| 63 | + color=colors, |
| 64 | + shading='flat', |
| 65 | + tube_points=8, |
| 66 | + mode='lines') |
| 67 | + |
| 68 | +canvas.view.add(l1) |
| 69 | +canvas.view.add(l2) |
| 70 | +canvas.view.add(l3) |
| 71 | +canvas.view.add(l4) |
| 72 | +canvas.view.camera = scene.TurntableCamera() |
| 73 | +# tube does not expose its limits yet |
| 74 | +canvas.view.camera.set_range((-20, 20), (-20, 20), (-20, 20)) |
| 75 | +canvas.show() |
| 76 | + |
| 77 | +if __name__ == '__main__': |
| 78 | + if sys.flags.interactive != 1: |
| 79 | + canvas.app.run() |
0 commit comments