Example #1
0
    def __init__(self):
        app.Canvas.__init__(self, keys='interactive')

        ps = self.pixel_scale

        # Create boids
        n = 1000
        self.particles = np.zeros(2 + n, [('position', 'f4', 3),
                                          ('position_1', 'f4', 3),
                                          ('position_2', 'f4', 3),
                                          ('velocity', 'f4', 3),
                                          ('color', 'f4', 4),
                                          ('size', 'f4', 1*ps)])
        self.boids = self.particles[2:]
        self.target = self.particles[0]
        self.predator = self.particles[1]

        self.boids['position'] = np.random.uniform(-0.25, +0.25, (n, 3))
        self.boids['velocity'] = np.random.uniform(-0.00, +0.00, (n, 3))
        self.boids['size'] = 4*ps
        self.boids['color'] = 1, 1, 1, 1

        self.target['size'] = 16*ps
        self.target['color'][:] = 1, 1, 0, 1
        self.predator['size'] = 16*ps
        self.predator['color'][:] = 1, 0, 0, 1
        self.target['position'][:] = 0.25, 0.0, 0

        # Time
        self._t = time.time()
        self._pos = 0.0, 0.0
        self._button = None

        width, height = self.physical_size
        gloo.set_viewport(0, 0, width, height)

        # Create program
        self.program = gloo.Program(VERT_SHADER, FRAG_SHADER)

        # Create vertex buffers
        self.vbo_position = gloo.VertexBuffer(self.particles['position']
                                              .copy())
        self.vbo_color = gloo.VertexBuffer(self.particles['color'].copy())
        self.vbo_size = gloo.VertexBuffer(self.particles['size'].copy())

        # Bind vertex buffers
        self.program['color'] = self.vbo_color
        self.program['size'] = self.vbo_size
        self.program['position'] = self.vbo_position

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

        self._timer = app.Timer('auto', connect=self.update, start=True)

        self.show()
Example #2
0
    def __init__(self):
        app.Canvas.__init__(self, position=(300, 100),
                            size=(800, 800), keys='interactive')

        self.program = gloo.Program(vertex, fragment)
        self.program['a_position'] = [(-1., -1.), (-1., +1.),
                                      (+1., -1.), (+1., +1.)]
        
        self.program['u_time'] = 0.0
        self.timer = app.Timer('auto', connect=self.on_timer, start=True)
Example #3
0
    def __init__(self, n=50):
        app.Canvas.__init__(self)
        self.program = gloo.Program(vertex, fragment, n)
        gl.glClearColor(1, 1, 1, 1)
        self.program['x'] = np.linspace(-1.0, +1.0, n)
        self.program['y'] = np.random.uniform(-0.5, +0.5, n)

        self._timer = app.Timer(1.0 / 60)
        self._timer.connect(self.on_timer)
        self._timer.start()
Example #4
0
 def __init__(self):
     app.Canvas.__init__(self, size=(640, 480), keys='interactive')
     self.program = gloo.Program(vertex, fragment, count=4)
     self.program['position'] = [(-1, -1), (-1, +1), (+1, -1), (+1, +1)]
     self.program['texcoord'] = [(1, 1), (1, 0), (0, 1), (0, 0)]
     self.program['texture'] = np.zeros((480, 640, 3)).astype(np.uint8)
     self.cap = cv2.VideoCapture(0)
     if not self.cap.isOpened():
         raise Exception("There's no available camera.")
     self._timer = app.Timer('auto', connect=self.on_timer, start=True)
Example #5
0
    def on_initialize(self, event):
        # Build & activate program
        self.program = gl.glCreateProgram()
        vertex = gl.glCreateShader(gl.GL_VERTEX_SHADER)
        fragment = gl.glCreateShader(gl.GL_FRAGMENT_SHADER)
        gl.glShaderSource(vertex, vertex_code)
        gl.glShaderSource(fragment, fragment_code)
        gl.glCompileShader(vertex)
        gl.glCompileShader(fragment)
        gl.glAttachShader(self.program, vertex)
        gl.glAttachShader(self.program, fragment)
        gl.glLinkProgram(self.program)
        gl.glDetachShader(self.program, vertex)
        gl.glDetachShader(self.program, fragment)
        gl.glUseProgram(self.program)

        # Build vertex buffer
        n = 10000
        self.data = np.zeros(n,
                             dtype=[('lifetime', np.float32),
                                    ('start', np.float32, 3),
                                    ('end', np.float32, 3)])
        vbuffer = gl.glCreateBuffer()
        gl.glBindBuffer(gl.GL_ARRAY_BUFFER, vbuffer)
        gl.glBufferData(gl.GL_ARRAY_BUFFER, self.data, gl.GL_DYNAMIC_DRAW)

        # Bind buffer attributes
        stride = self.data.strides[0]

        offset = 0
        loc = gl.glGetAttribLocation(self.program, "lifetime")
        gl.glEnableVertexAttribArray(loc)
        gl.glVertexAttribPointer(loc, 1, gl.GL_FLOAT, False, stride, offset)

        offset = self.data.dtype["lifetime"].itemsize
        loc = gl.glGetAttribLocation(self.program, "start")
        gl.glEnableVertexAttribArray(loc)
        gl.glVertexAttribPointer(loc, 3, gl.GL_FLOAT, False, stride, offset)

        offset = self.data.dtype["start"].itemsize
        loc = gl.glGetAttribLocation(self.program, "end")
        gl.glEnableVertexAttribArray(loc)
        gl.glVertexAttribPointer(loc, 3, gl.GL_FLOAT, False, stride, offset)

        # OpenGL initalization
        self.elapsed_time = 0
        gl.glClearColor(0, 0, 0, 1)
        gl.glDisable(gl.GL_DEPTH_TEST)
        gl.glEnable(gl.GL_BLEND)
        gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE)
        gl.glEnable(34370)  # gl.GL_VERTEX_PROGRAM_POINT_SIZE
        gl.glEnable(34913)  # gl.GL_POINT_SPRITE
        gl.glViewport(0, 0, *self.physical_size)
        self.new_explosion()
        self.timer = app.Timer('auto', self.on_timer, start=True)
Example #6
0
    def __init__(self, program: gloo.Program):
        app.Canvas.__init__(self, size=(800, 600), keys='interactive')
        self.program = program

        self.apply_zoom()

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

        self._timer = app.Timer('auto', connect=self.on_timer_event,
                                start=True)
Example #7
0
    def __init__(self):
        app.Canvas.__init__(self,
                            title="Conway game of life",
                            size=(512, 512),
                            keys='interactive')

        # Build programs
        # --------------
        self.comp_size = self.size
        size = self.comp_size + (4, )
        Z = np.zeros(size, dtype=np.float32)
        Z[...] = np.random.randint(0, 2, size)
        Z[:256, :256, :] = 0
        gun = """
        ........................O...........
        ......................O.O...........
        ............OO......OO............OO
        ...........O...O....OO............OO
        OO........O.....O...OO..............
        OO........O...O.OO....O.O...........
        ..........O.....O.......O...........
        ...........O...O....................
        ............OO......................"""
        x, y = 0, 0
        for i in range(len(gun)):
            if gun[i] == '\n':
                y += 1
                x = 0
            elif gun[i] == 'O':
                Z[y, x] = 1
            x += 1

        self.pingpong = 1
        self.compute = Program(compute_vertex, compute_fragment, 4)
        self.compute["texture"] = Z
        self.compute["position"] = [(-1, -1), (-1, +1), (+1, -1), (+1, +1)]
        self.compute["texcoord"] = [(0, 0), (0, 1), (1, 0), (1, 1)]
        self.compute['dx'] = 1.0 / size[1]
        self.compute['dy'] = 1.0 / size[0]
        self.compute['pingpong'] = self.pingpong

        self.render = Program(render_vertex, render_fragment, 4)
        self.render["position"] = [(-1, -1), (-1, +1), (+1, -1), (+1, +1)]
        self.render["texcoord"] = [(0, 0), (0, 1), (1, 0), (1, 1)]
        self.render["texture"] = self.compute["texture"]
        self.render['pingpong'] = self.pingpong

        self.fbo = FrameBuffer(self.compute["texture"],
                               RenderBuffer(self.comp_size))
        set_state(depth_test=False, clear_color='black')

        self._timer = app.Timer('auto', connect=self.update, start=True)

        self.show()
Example #8
0
    def __init__(self,
                 field,
                 spacing=10,
                 segments=3,
                 seg_len=0.5,
                 color=(1, 1, 1, 0.3)):
        self._time = 0.0
        self._last_time = ptime.time()
        rows = int(field.shape[0] / spacing)
        cols = int(field.shape[1] / spacing)
        index = np.empty((rows * cols, int(segments) * 2, 2), dtype=np.float32)

        # encodes starting position within vector field
        index[:, :, 0] = np.arange(rows * cols)[:, np.newaxis]
        # encodes distance along length of line
        index[:, ::2, 1] = np.arange(segments)[np.newaxis, :]
        index[:, 1::2, 1] = np.arange(segments)[np.newaxis, :] + 1
        self._index = gloo.VertexBuffer(index)
        if not isinstance(color, np.ndarray):
            color = np.array([[list(color)]], dtype='float32')
        self._color = gloo.Texture2D(color)

        offset = np.random.uniform(256, size=(rows, cols, 3)).astype(np.ubyte)
        self._offset = gloo.Texture2D(offset, format='rgb')
        self._field = gloo.Texture2D(field,
                                     format='rg',
                                     internalformat='rg32f',
                                     interpolation='linear')
        self._field_shape = field.shape[:2]

        visuals.Visual.__init__(self, vcode=self.vertex, fcode=self.fragment)
        self.timer = app.Timer(interval='auto',
                               connect=self.update_time,
                               start=False)
        self.freeze()

        self.shared_program['field'] = self._field
        self.shared_program['field_shape'] = self._field.shape[:2]
        self.shared_program['shape'] = (rows, cols)
        self.shared_program['index'] = self._index
        self.shared_program['spacing'] = spacing
        self.shared_program['t'] = self._time
        self.shared_program['offset'] = self._offset
        self.shared_program['speed'] = 1
        self.shared_program['color'] = self._color
        self.shared_program['seg_len'] = seg_len
        self.shared_program['nseg'] = segments
        self.shared_program['n_iter'] = 1
        self.shared_program['attractor'] = (0, 0)
        self.shared_program['time'] = 0
        self._draw_mode = 'lines'
        self.set_gl_state('translucent', depth_test=False)

        self.timer.start()
Example #9
0
    def __init__(self):

        app.Canvas.__init__(self, title='Symulacja modelu', size=(800, 800))

        # Some initialization constants that won't change
        self.center = np.asarray((500, 250))
        self.visuals = []

        # Set up a timer to update the image and give a real-time rendering
        self._timer = app.Timer('auto', connect=self.on_timer, start=True)
        self.show()
Example #10
0
    def __init__(self, pause=False):
        app.Canvas.__init__(self, size=(800, 600), keys='interactive')
        self.program = gloo.Program(VERT_SHADER, FRAG_SHADER)
        self.program["u_global_time"] = 0
        self.program['a_position'] = [(-1, -1), (-1, +1), (+1, -1), (+1, +1)]

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

        self._timer = app.Timer('auto',
                                connect=self.on_timer_event,
                                start=True)
Example #11
0
    def __init__(self, parent, master):
        '''

        In der __init__ Methode wird gloo konfiguriert und der pyqt Kontext festgelegt. Des Weiteren werden alle
        self.(...) Variablen und der Timer (siehe on_timer) initiiert.

        Parameter:  parent wird benoetigt zur Festsetzung des Kontextes
                    master wird zu Interaktion mit der GUI benötigt (z.B. Errors)
        Rückgabewerte: -

        '''

        print('[* Canvas: initializing *]')

        app.use_app(backend_name='pyqt4', call_reuse=True)
        app.Canvas.__init__(self,
                            size=(1465, 850),
                            title='GraphicMolecule Vizualizer',
                            keys='interactive',
                            parent=parent)
        gloo.set_state(clear_color=(0.1, 0.14, 0.23, 1.00),
                       depth_test=True,
                       blend=True,
                       blend_func=('src_alpha', 'one_minus_src_alpha'))
        gloo.wrappers.set_depth_range(near=0.9, far=1)

        #initializing all self._____ variables
        self._master = master

        self._molName = ''
        self._molecule = None
        self._programs = []

        self._decreaseDrawHorizon = False
        self._increaseDrawHorizon = False
        self._drawHorizon = 0

        self._rotSpeed = 0
        self._zoom = -7
        self._rotation = 0
        self._rotationVec = [0, 0, 0]

        self._atomSizes = 0
        self._atomColors = (0, 0, 0)
        self._bondSize = 0
        self._bondColor = (0, 0, 0)
        self._atomDT = ''
        self._bondDT = ''

        #als observer anmelden
        self._master.registerObserver(self)

        self.timer = app.Timer('auto', self.on_timer, start=True)
Example #12
0
 def __init__(self):
     app.Canvas.__init__(self, title='Use your wheel to zoom!', 
                         keys='interactive')
     self.program = gloo.Program(VERT_SHADER, FRAG_SHADER)
     self.program['a_position'] = y.reshape(-1, 1)
     self.program['a_color'] = color
     self.program['a_index'] = index
     self.program['u_scale'] = (1., 1.)
     self.program['u_size'] = (nrows, ncols)
     self.program['u_n'] = n
     
     self._timer = app.Timer('auto', connect=self.on_timer, start=True)
Example #13
0
 def __init__(self):
     """ initialize the canvas """
     app.Canvas.__init__(self,
                         size=(512, 512),
                         title='SR Voronoi Visualizer',
                         keys='interactive')
     self.tri = 16  # 16 edges for each point
     self.shrinkage = width / 2
     # define vertices, indices, color
     V, I, C = genVIC(pointz, self.tri, color)
     self.BarStart = V.shape[0]
     # set initial scale and center point
     self.centerpos = [0, 0]
     self.scale = 1
     # hard-coded bar coordinates in the mean time
     self.BarCenter = [0.9, -0.9]
     self.BarDim = [
         barWidth / pix2nm / self.shrinkage, 0.05 / np.sqrt(self.scale)
     ]
     bV, bI, bC = genScaleBar(self.BarDim, self.BarCenter)
     bI = bI + self.BarStart
     # bind to data
     V = np.vstack((V, bV))
     I = np.vstack((I, bI))
     C = np.vstack((C, bC))
     # shader program
     tet = gloo.Program(vert=vertex, frag=fragment)  #, count=V.shape[0])
     self.I = gloo.IndexBuffer(I)
     self.V = gloo.VertexBuffer(V)
     self.C = gloo.VertexBuffer(C)
     tet['a_position'] = self.V
     tet['a_color'] = self.C
     # intialize transformation matrix
     self.view = np.eye(4, dtype=np.float32)
     self.model = np.eye(4, dtype=np.float32)
     self.projection = np.eye(4, dtype=np.float32)
     # set view
     self.view = translate((0, 0, -3))
     tet['u_model'] = self.model
     tet['u_view'] = self.view
     tet['u_projection'] = self.projection
     # bind program
     self.program = tet
     # config and set viewport
     gloo.set_viewport(0, 0, *self.physical_size)
     gloo.set_clear_color('black')
     gloo.set_state('opaque')
     gloo.set_polygon_offset(1.0, 1.0)
     # bind a timer
     self.timer = app.Timer('auto', self.on_timer)
     self.timer.start()
     # show the canvas
     self.show()
Example #14
0
    def __init__(self):
        app.Canvas.__init__(self, size=(1280, 960), keys='interactive')
        self.program = gloo.Program(vertex, fragment, count=4)
        self.program['position'] = [(-1, -1), (-1, +1), (+1, -1), (+1, +1)]
        self.program['texcoord'] = [(1, 1), (1, 0), (0, 1), (0, 0)]
        numaxes = joystick.get_numaxes(
        )  # return the number of axes on the controller
        axis = [joystick.get_axis(i) for i in range(numaxes)
                ]  # get the analog value of the specified axis
        global sumaxis
        #sumaxis+=axis
        self.program['axis'] = axis
        self.program['sumaxis'] = (sumaxis[0], sumaxis[1], sumaxis[3],
                                   sumaxis[4])

        #self.program['texture2'] = rtex=(1024*np.random.rand(480, 640, 3)).astype(np.uint8)#random texture

        self.program['texture3'] = clip.get_frame(6)
        self.program['texture'] = np.zeros(
            (480, 640, 3)).astype(np.uint8)  #free space for cam texture
        self.program['iMouse'] = 0, 0, 0, 0
        self.program['iGlobalTime'] = 0.
        self.program['iResolution'] = (self.physical_size[0],
                                       self.physical_size[1],
                                       self.physical_size[0] /
                                       self.physical_size[1])
        self._timer = app.Timer('auto', connect=self.on_timer, start=True)
        #print (self.program['texture2'])
        #print (self.program['texture'])
        #print (rtex)

        width, height = self.physical_size
        gloo.set_viewport(0, 0, width, height)

        self.cap = cv2.VideoCapture(0)
        if not self.cap.isOpened():
            raise Exception("There's no available camera.")
        self._timer = app.Timer('auto', connect=self.on_timer, start=True)

        self.show()
Example #15
0
 def __init__(self):
     """конструктор обьекта окна"""
     app.Canvas.__init__(self, title="step 2", size=(500, 500), vsync=True)
     gloo.set_state(clear_color=(0, 0, 0, 1), depth_test=False, blend=False)
     self.program = gloo.Program(vert, frag)
     self.surface = Surface(
     )  # обьект, который будет давать состояние поверхности
     self.program["a_position"] = self.surface.position(
     )  # xy=const шейдеру,
     self.t = 0  # t - time
     self._timer = app.Timer('auto', connect=self.on_timer, start=True)
     self.activate_zoom()
     self.show()
 def __init__(self, text, color='black', bold=False, italic=False, face='OpenSans', font_size=12, pos=[0, 0, 0], rotation=0.0, anchor_x='center', anchor_y='center', font_manager=None):
     super(TimeTextVisual, self).__init__(text, color, bold, italic, face, font_size, pos, rotation, anchor_x, anchor_y, font_manager)
     self.unfreeze()  # super class froze things. Need to unfreeze.
     visuals.Visual.__init__(self, vertex_shader, fragment_shader)
     self.timer = app.Timer(interval='auto', connect=self.update_time, start=False)
     self._time = 0.0
     self._first_time = ptime.time()
     self._last_time = ptime.time()
     self.text = text
     self.freeze()
     self.shared_program['time'] = self._time
     self.shared_program['text_scale'] = 1
     self.timer.start()
Example #17
0
    def __init__(self):
        self.rpolygon = visuals.RegularPolygon(pos=(400.0, 400.0, 0),
                                               radius=80.,
                                               color=(1, 0, 0, 1),
                                               border_color=(1, 1, 1, 1),
                                               sides=4)

        vispy.scene.SceneCanvas.__init__(self, keys='interactive')
        self.size = (800, 800)
        self.show()

        self.rfactor = 0.01
        self._timer = app.Timer('auto', connect=self.on_timer, start=True)
Example #18
0
    def __init__(self):
        app.Canvas.__init__(self, keys='interactive')
        self.size = 800, 600

        # Create program
        self._program = gloo.Program(VERT_SHADER, FRAG_SHADER)
        self._program.bind(gloo.VertexBuffer(data))
        self._program['s_texture'] = gloo.Texture2D(im1)

        # Create first explosion
        self._new_explosion()
        
        self._timer = app.Timer('auto', connect=self.update, start=True)
Example #19
0
    def __init__(self):
        self.ellipse = visuals.Ellipse(pos=(400, 400, 0),
                                       radius=[320, 240],
                                       color=(1, 0, 0, 1),
                                       border_color=(1, 1, 1, 1),
                                       start_angle=180.,
                                       span_angle=150.)

        vispy.scene.SceneCanvas.__init__(self, keys='interactive')
        self.size = (800, 800)
        self.show()

        self._timer = app.Timer('auto', connect=self.on_timer, start=True)
Example #20
0
    def __init__(self):
        app.Canvas.__init__(self,
                            size=(512, 512),
                            title='Monkey',
                            keys='interactive')
        verts, faces, normals, texcoords = io.read_mesh(
            "../model/monkey/monkey.obj")
        obj = MeshData(verts, faces)

        self.program = gloo.Program(vert=vertex, frag=fragment)

        V = verts.astype('float32')

        F = obj.get_faces().astype('uint32')

        E = obj.get_edges().astype('uint32')

        C = np.array([(1, 1, 1, 1)])
        for i in range(len(V) - 1):
            if i % 2 != 0:
                C = np.append(C, [(1, 1, 1, 1)], axis=0)
            else:
                C = np.append(C, [(0, 0, 0, 1)], axis=0)

        self.program['a_position'] = V
        self.program['a_color'] = C.astype('float32')
        self.F = gloo.IndexBuffer(F)
        self.E = gloo.IndexBuffer(E)

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

        # intialize transformation matrix
        view = np.eye(4, dtype=np.float32)
        model = np.eye(4, dtype=np.float32)
        projection = np.eye(4, dtype=np.float32)

        # set view
        view = translate((0, 0, -5))
        self.program['u_model'] = model
        self.program['u_view'] = view
        self.program['u_projection'] = projection

        # bind a timer
        self.timer = app.Timer('auto', self.on_timer)
        self.theta = 0.0
        self.phi = 0.0
        self.timer.start()

        # show the canvas
        self.show()
Example #21
0
	def __init__(self):
		app.Canvas.__init__(self, size=(W, H), keys='interactive')
		self.program = gloo.Program(vertex, fragment_c, count=4)
		width, height = self.physical_size
		gloo.set_viewport(0, 0, width, height)
		self.program['position'] = [(-1, -1), (-1, +1), (+1, -1), (+1, +1)]
		self.program['texcoord'] = [(1, 1), (1, 0), (0, 1), (0, 0)]
		self.program['u_resolution'] = [(W, H)]
		self.program['t_1'] = control[0]
		self.program['t_2'] = control[1]
		self.program['t_3'] = control[2]
		self.program['t_4'] = control[3]
		self.timer_app = app.Timer(1.0 / FPS, connect=self.on_timer_app, start=True)
		self.show()
Example #22
0
    def __init__(self, connection, orientation):
        self.con = connection
        self.orientation = orientation
        app.Canvas.__init__(self, 'Cube', keys='interactive', size=(400, 400))
        self.cube = CubeVisual((7.0, 4.0, 0.3),
                               color=Color(color='grey', alpha=0.1,
                                           clip=False),
                               edge_color="black")

        # Create a TransformSystem that will tell the visual how to draw
        self.cube_transform = transforms.MatrixTransform()
        self.cube.transform = self.cube_transform
        self._timer = app.Timer('0.05', connect=self.on_timer, start=True)
        self.show()
Example #23
0
    def __init__(self):
        app.Canvas.__init__(self, keys='interactive', size=(800, 600))

        rospy.init_node('imu_visualizer')
        #         assert_node_alive('torso_arduino')

        rospy.Subscriber('imu/data_raw', Imu, self.on_imu)

        # Cleanup when termniating the node
        rospy.on_shutdown(self.shutdown)

        self.vertices, self.filled, self.outline = cube()
        self.filled_buf = gloo.IndexBuffer(self.filled)
        self.outline_buf = gloo.IndexBuffer(self.outline)

        self.program = gloo.Program(vert, frag)
        self.program.bind(gloo.VertexBuffer(self.vertices))

        self.view = translate((0, 0, -5))
        self.model = np.eye(4, dtype=np.float32)

        gloo.set_viewport(0, 0, self.physical_size[0], self.physical_size[1])
        self.projection = perspective(45.0, self.size[0] / float(self.size[1]),
                                      2.0, 10.0)

        self.program['u_projection'] = self.projection
        self.program['u_model'] = self.model
        self.program['u_view'] = self.view

        self.yaw = 0  # yaw
        self.roll = 0  # roll
        self.pitch = 0  # pitch

        gloo.set_clear_color('white')
        #         gloo.set_clear_color('black')
        gloo.set_state('opaque')
        gloo.set_polygon_offset(1, 1)

        self.first = True
        self.yaw0 = None

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

        self.show()

        app.run()

        rospy.signal_shutdown("Shutting done.")
        self.shutdown()
        print('Node shutdown.')
Example #24
0
    def __init__(self):
        app.Canvas.__init__(self, 'Cube', keys='interactive', size=(400, 400))

        self.cube = BoxVisual(1.0, 0.5, 0.25, color='red', edge_color="k")
        self.theta = 0
        self.phi = 0

        # Create a TransformSystem that will tell the visual how to draw
        self.cube_transform = transforms.MatrixTransform()
        self.cube.transform = self.cube_transform

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

        self.show()
Example #25
0
    def __init__(self, n=50):
        app.Canvas.__init__(self)

        self.program1 = gloo.Program(vertex, fragment, n)
        self.program1['x'] = np.linspace(-1.0, +1.0, n)
        self.program1['y'] = +0.5 + np.random.uniform(-0.25, +0.25, n)

        self.program2 = gloo.Program(vertex, fragment, n)
        self.program2['x'] = np.linspace(-1.0, +1.0, n)
        self.program2['y'] = -0.5 + np.random.uniform(-0.25, +0.25, n)

        self._timer = app.Timer(1.0 / 60)
        self._timer.connect(self.on_timer)
        self._timer.start()
Example #26
0
    def __init__(self):
        self.polygon = visuals.Polygon(pos=pos,
                                       color=(1, 0, 0, 1),
                                       border_color=(1, 1, 1, 1))
        self.polygon.transform = vispy.scene.transforms.STTransform(
            scale=(500, 500), translate=(400, 400))

        vispy.scene.SceneCanvas.__init__(self, keys='interactive')
        self.pos = np.array(pos)
        self.i = 1
        self.size = (800, 800)
        self.show()

        self._timer = app.Timer('auto', connect=self.on_timer, start=True)
Example #27
0
    def __init__(self, n=50):
        app.Canvas.__init__(self)
        self.program = gloo.Program(vertex, fragment, n)
        self.data = np.zeros(n, [('x', np.float32, 1), ('y', np.float32, 1)])
        self.data['x'] = np.linspace(-1.0, +1.0, n)
        self.data['y'] = np.random.uniform(-0.5, +0.5, n).astype(np.float32)
        self.vdata = gloo.VertexBuffer(self.data)
        self.program.bind(self.vdata)

        self._timer = app.Timer(1.0 / 60)
        self._timer.connect(self.on_timer)
        self._timer.start()

        self.index = 0
Example #28
0
    def __init__(self, scale=500, filt=True):
        app.Canvas.__init__(self,
                            title='EEG - Use your wheel to zoom!',
                            keys='interactive')

        self.program = gloo.Program(VERT_SHADER, FRAG_SHADER)
        self.program['a_position'] = y.reshape(-1, 1)
        self.program['a_color'] = color
        self.program['a_index'] = index
        self.program['u_scale'] = (1., 1.)
        self.program['u_size'] = (nrows, ncols)
        self.program['u_n'] = n

        # text
        self.font_size = 48.
        self.names = []
        self.quality = []
        for ii in range(n_chan):
            text = visuals.TextVisual(ch_names[ii], bold=True, color='white')
            self.names.append(text)
            text = visuals.TextVisual('', bold=True, color='white')
            self.quality.append(text)

        self.quality_colors = color_palette("RdYlGn", 11)[::-1]

        self.scale = scale
        self.n_samples = n_samples
        self.filt = filt
        self.af = [1.0]

        self.data_f = np.zeros((n_samples, n_chan))
        self.data = np.zeros((n_samples, n_chan))

        self.bf = create_filter(self.data_f.T,
                                sfreq,
                                3,
                                40.,
                                method='fir',
                                fir_design='firwin')

        zi = lfilter_zi(self.bf, self.af)
        self.filt_state = np.tile(zi, (n_chan, 1)).transpose()

        self._timer = app.Timer('auto', connect=self.on_timer, start=True)
        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()
Example #29
0
 def __init__(self):
     app.Canvas.__init__(self,
                         size=(600, 600),
                         title="Water surface simulator 2")
     gloo.set_state(clear_color=(0, 0, 0, 1), depth_test=False, blend=False)
     self.program = gloo.Program(vert, frag)
     self.surface = Surface()
     self.program["a_position"] = self.surface.position()
     # Сохраним вершины треугольников в графическую память.
     self.triangles = gloo.IndexBuffer(self.surface.triangulation())
     self.t = 0
     self._timer = app.Timer('auto', connect=self.on_timer, start=True)
     self.activate_zoom()
     self.show()
Example #30
0
    def __init__(self, fname):
        app.Canvas.__init__(self, title='Molecular viewer')

        # self.size is not updated until after __init__ is
        # finished so must use the local `size` variable during
        # __init__
        size = 500, 300
        self.size = size
        gloo.set_viewport(0, 0, size[0], size[1])

        self.program = gloo.Program(semilight_vertex, semilight_fragment)
        self.picking_program = gloo.Program(picking_vertex, picking_fragment)

        soup = pdbatoms.Soup(fname)

        rendered_soup = RenderedSoup(soup)
        self.rendered_soup = rendered_soup

        print "Building arrows..."
        self.arrow_buffer = make_calpha_arrow_mesh(rendered_soup.trace)

        print "Building cylindrical trace..."
        self.cylinder_index_buffer, self.cylinder_vertex_buffer = \
            make_cylinder_trace_mesh(rendered_soup.pieces)

        print "Building cartoon..."
        self.cartoon_index_buffer, self.cartoon_vertex_buffer = \
            make_carton_mesh(rendered_soup.pieces)

        print "Building ball&sticks..."
        self.ballstick_index_buffer, self.ballstick_vertex_buffer = \
            make_ball_and_stick_mesh(rendered_soup)

        self.draw_style = 'sidechains'

        self.camera = Camera()
        self.camera.resize(*size)
        self.camera.set_center(rendered_soup.center)
        self.camera.rezoom(2.0 / rendered_soup.scale)

        self.new_camera = Camera()
        self.n_step_animate = 0

        self.console = Console(size)
        self.text = self.console.text

        self.timer = app.Timer(1.0 / 30)  # change rendering speed here
        self.timer.connect(self.on_timer)
        self.timer.start()