def on_key_press(event): if event.text == '1': for cam in cams: flip = cam.flip cam.flip = not flip[0], flip[1], flip[2] elif event.text == '2': for cam in cams: flip = cam.flip cam.flip = flip[0], not flip[1], flip[2] elif event.text == '3': for cam in cams: flip = cam.flip cam.flip = flip[0], flip[1], not flip[2] elif event.text == '4': up = next(ups) print('up: ' + up) for cam in cams: cam.up = up if event.text == '5': cam_toggle = {cam1: cam2, cam2: cam3, cam3: cam4, cam4: cam1} view.camera = cam_toggle.get(view.camera, cam2) print(view.camera.name + ' camera') elif event.text == '0': for cam in cams: cam.set_range()
def __init__(self): vispy.scene.SceneCanvas.__init__(self, keys='interactive', size=(400, 200), show=True) # Create a visual that updates the line with different colormaps color = next(colormaps) self.line = visuals.Line(pos=pos, color=color, mode='gl') self.line.transform = STTransform(translate=[0, 140]) # redraw the canvas if the visual requests an update self.line.parent = self.central_widget self.text = visuals.Text(color, bold=True, font_size=24, color='w', pos=(200, 40), parent=self.central_widget) self._timer = app.Timer(2.0, connect=self.on_timer, start=True)
def on_key_press(event): if event.text == "1": for cam in cams: flip = cam.flip cam.flip = not flip[0], flip[1], flip[2] elif event.text == "2": for cam in cams: flip = cam.flip cam.flip = flip[0], not flip[1], flip[2] elif event.text == "3": for cam in cams: flip = cam.flip cam.flip = flip[0], flip[1], not flip[2] elif event.text == "4": up = next(ups) print("up: " + up) for cam in cams: cam.up = up if event.text == "5": cam_toggle = {cam1: cam2, cam2: cam3, cam3: cam4, cam4: cam1} view.camera = cam_toggle.get(view.camera, "fly") elif event.text == "0": for cam in cams: cam.set_range()
def update(event): global n for i in range(n_buses): bus = busses[i] bus_repr = bus_representations[i] bus_position = bus_positions[i] try: x, v = next(bus_position) new_color = citymap.color_from_position(x) bus_repr.repr.color = new_color # adapt the direction and position of the bus bus_repr.translate_rotate((x[0], x[1]), bus.phi / 2 / np.pi * 360) except StopIteration: random_x = np.random.random(2) * np.array(citymap.size) bus_positions[i] = bus.drive(random_x, dt=0.1) x = bus.position citymap.canvas.update() #image = citymap.canvas.render() #vispy.io.write_png('movie/shot{0}.png'.format(n), image) n += 1
def on_timer(event): global colormaps, line, text, pos color = next(colormaps) line.set_data(pos=pos, color=color) text.text = color
from vispy.visuals.transforms import STTransform from vispy.ext.six import next colormaps = itertools.cycle(get_colormaps()) # vertex positions of data to draw N = 200 pos = np.zeros((N, 2), dtype=np.float32) pos[:, 0] = np.linspace(10, 390, N) pos[:, 1] = np.random.normal(size=N, scale=20, loc=0) canvas = scene.SceneCanvas(keys='interactive', size=(400, 200), show=True) # Create a visual that updates the line with different colormaps color = next(colormaps) line = scene.Line(pos=pos, color=color, method='gl') line.transform = STTransform(translate=[0, 140]) line.parent = canvas.central_widget text = scene.Text(color, bold=True, font_size=24, color='w', pos=(200, 40), parent=canvas.central_widget) def on_timer(event): global colormaps, line, text, pos color = next(colormaps) line.set_data(pos=pos, color=color) text.text = color timer = app.Timer(.5, connect=on_timer, start=True)
from vispy.color import colormaps from vispy.visuals.transforms import STTransform from vispy.ext.six import next colormaps = itertools.cycle(colormaps) # vertex positions of data to draw N = 200 pos = np.zeros((N, 2), dtype=np.float32) pos[:, 0] = np.linspace(10, 390, N) pos[:, 1] = np.random.normal(size=N, scale=20, loc=0) canvas = scene.SceneCanvas(keys='interactive', size=(400, 200), show=True) # Create a visual that updates the line with different colormaps color = next(colormaps) line = scene.Line(pos=pos, color=color, mode='gl') line.transform = STTransform(translate=[0, 140]) line.parent = canvas.central_widget text = scene.Text(color, bold=True, font_size=24, color='w', pos=(200, 40), parent=canvas.central_widget) def on_timer(event): global colormaps, line, text, pos color = next(colormaps)
def on_timer(self, event): color = next(colormaps) self.line.set_data(pos=pos, color=color) self.text.text = color self.update()