How to use the vispy.gloo.set_state function in vispy

To help you get started, we’ve selected a few vispy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github strfry / OpenNFB / blocks / waterfall.py View on Github external
self.program['line'] = [(x,) * num_bins for x in range(num_lines)]
        self.program['map_offset'] = 0

        self.program['num_bins'] = num_bins
        self.program['num_lines'] = num_lines

        heightmap = np.random.random(size=(num_lines, num_bins)).astype('float32')

        self.program['heightmap'] = gloo.Texture2D(data=heightmap, internalformat='r32f')
        #print (dir(self.program['heightmap']))

        self.program['colormap'] = Colormap(['r', 'g', 'b']).map(np.linspace(0, 1, 64)).astype('float32')

        gloo.set_viewport(0, 0, *self.physical_size)

        gloo.set_state(clear_color='black', blend=True,
                       blend_func=('src_alpha', 'one_minus_src_alpha'))

        self.show()
github Denvi / FlatCAM / VisPyVisuals.py View on Github external
if data['visible'] and 'line_pts' in data:
                try:
                    line_pts[data['layer']] += data['line_pts']
                    line_colors[data['layer']] += data['line_colors']
                    mesh_tris[data['layer']] += [x + len(mesh_vertices[data['layer']])
                                                 for x in data['mesh_tris']]

                    mesh_vertices[data['layer']] += data['mesh_vertices']
                    mesh_colors[data['layer']] += data['mesh_colors']
                except Exception as e:
                    print "Data error", e

        # Updating meshes
        for i, mesh in enumerate(self._meshes):
            if len(mesh_vertices[i]) > 0:
                set_state(polygon_offset_fill=False)
                mesh.set_data(np.asarray(mesh_vertices[i]), np.asarray(mesh_tris[i], dtype=np.uint32)
                              .reshape((-1, 3)), face_colors=np.asarray(mesh_colors[i]))
            else:
                mesh.set_data()

            mesh._bounds_changed()

        # Updating lines
        for i, line in enumerate(self._lines):
            if len(line_pts[i]) > 0:
                line.set_data(np.asarray(line_pts[i]), np.asarray(line_colors[i]), self._line_width, 'segments')
            else:
                line.clear_data()

            line._bounds_changed()
github vispy / vispy / examples / tutorial / gloo / colored_cube.py View on Github external
# Build cube data
        V, I, _ = create_cube()
        vertices = VertexBuffer(V)
        self.indices = IndexBuffer(I)

        # Build program
        self.program = Program(vertex, fragment)
        self.program.bind(vertices)

        # Build view, model, projection & normal
        view = translate((0, 0, -5))
        model = np.eye(4, dtype=np.float32)
        self.program['model'] = model
        self.program['view'] = view
        self.phi, self.theta = 0, 0
        gloo.set_state(clear_color=(0.30, 0.30, 0.35, 1.00), depth_test=True)

        self.activate_zoom()

        self.timer = app.Timer('auto', self.on_timer, start=True)

        self.show()
github vispy / vispy / examples / collections / path_collection.py View on Github external
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# vispy: testskip

import numpy as np
from vispy import app, gloo
from vispy.visuals.collections import PathCollection

c = app.Canvas(size=(800, 800), show=True, keys='interactive')
gloo.set_viewport(0, 0, c.size[0], c.size[1])
gloo.set_state("translucent", depth_test=False)


def star(inner=0.5, outer=1.0, n=5):
    R = np.array([inner, outer] * n)
    T = np.linspace(0, 2 * np.pi, 2 * n, endpoint=False)
    P = np.zeros((2 * n, 3))
    P[:, 0] = R * np.cos(T)
    P[:, 1] = R * np.sin(T)
    return P


n = 2500
S = star(n=5)
P = np.tile(S.ravel(), n).reshape(n, len(S), 3)
P *= np.random.uniform(5, 10, n)[:, np.newaxis, np.newaxis]
P[:, :, :2] += np.random.uniform(0, 800, (n, 2))[:, np.newaxis, :]
github vispy / vispy / examples / demo / gloo / signals.py View on Github external
def __init__(self):
        app.Canvas.__init__(self, keys='interactive')
        self.program = gloo.Program(VERT_SHADER, FRAG_SHADER)
        self.program.bind(gloo.VertexBuffer(data))

        self.program['u_pan'] = (0., 0.)
        self.program['u_scale'] = (1., 1.)

        gloo.set_viewport(0, 0, *self.physical_size)

        gloo.set_state(clear_color=(1, 1, 1, 1), blend=True,
                       blend_func=('src_alpha', 'one_minus_src_alpha'))

        self.show()
github vispy / vispy / examples / demo / gloo / show_markers.py View on Github external
Program(markers.vert, markers.frag + markers.vbar),
            Program(markers.vert, markers.frag + markers.hbar),
            Program(markers.vert, markers.frag + markers.clobber),
            Program(markers.vert, markers.frag + markers.ring)]

        for program in self.programs:
            program.bind(self.vbo)
            program["u_antialias"] = u_antialias,
            program["u_size"] = 1
            program["u_model"] = self.model
            program["u_view"] = self.view
            program["u_projection"] = self.projection
        self.index = 0
        self.program = self.programs[self.index]

        gloo.set_state(depth_test=False, blend=True, clear_color='white',
                       blend_func=('src_alpha', 'one_minus_src_alpha'))
github vispy / vispy / examples / basics / gloo / split_screen.py View on Github external
def on_initialize(self, event):
        gloo.set_state(clear_color='black', blend=True,
                       blend_func=('src_alpha', 'one'))
github p5py / p5 / p5 / sketch / renderer3d.py View on Github external
def _comm_toggles(self, state=True):
		gloo.set_state(blend=state)
		gloo.set_state(depth_test=state)

		if state:
			gloo.set_state(blend_func=('src_alpha', 'one_minus_src_alpha'))
			gloo.set_state(depth_func='equal')
github p5py / p5 / p5 / sketch / renderer3d.py View on Github external
def _comm_toggles(self, state=True):
		gloo.set_state(blend=state)
		gloo.set_state(depth_test=state)

		if state:
			gloo.set_state(blend_func=('src_alpha', 'one_minus_src_alpha'))
			gloo.set_state(depth_func='equal')
github p5py / p5 / p5 / sketch / renderer2d.py View on Github external
def _comm_toggles(self, state=True):
		gloo.set_state(blend=state)
		gloo.set_state(depth_test=state)

		if state:
			gloo.set_state(blend_func=('src_alpha', 'one_minus_src_alpha'))
			gloo.set_state(depth_func='lequal')