コード例 #1
0
ファイル: exercise-4.py プロジェクト: rougier/loops-tutorial
import numpy as np
from vispy import app
from vispy import gloo
from vispy.gloo import gl

app.use('glfw')


vertex = """
attribute float x;
attribute float y;
attribute float a;

varying float v_a;
void main (void)
{
    v_a = a;
    gl_Position = vec4(x, y, 0.0, 1.0);
}
"""

fragment = """
varying float v_a;
void main()
{
    gl_FragColor = vec4(1.0-v_a);
}
"""

class Window(app.Canvas):
    def __init__(self, n=50):
コード例 #2
0
ファイル: app-glut.py プロジェクト: MatthieuDartiailh/vispy
This example shows how to actively select and test the glut backend.

You should see a black window and any mouse or keyboard event should be
detected. A timer is also run every second and it should print "tick !"
every second.

Notes
-----
Depending on on your glut implementation (native or freeglut), the mouse wheel
event may or may not be detected. Furthermore, glut has no utf-8 support and
non ascii-key will most likely produces garbage.
"""

from vispy import app
from vispy.gloo import gl
app.use('glut')


class Canvas(app.Canvas):

    def __init__(self, *args, **kwargs):
        app.Canvas.__init__(self, *args, **kwargs)
        timer = app.Timer(1.0)
        timer.connect(self.on_timer)
        timer.start()

    def on_initialize(self, event):
        gl.glClearColor(0, 0, 0, 1)
        print('on_initialize')

    def on_close(self, event):
コード例 #3
0
This example shows how to actively select and test the glut backend.

You should see a black window and any mouse or keyboard event should be
detected. A timer is also ran every second and it should print "tick !"
every second.

Note:
====
Depending on on your glut implementation (native or freeglut), the mouse wheel
event may or may not be detected. Furthermore, glut has no utf-8 support and
non ascii-key will most likely produces garbage.
"""

from vispy import app
from vispy.gloo import gl
app.use('glut')


class Canvas(app.Canvas):
    def __init__(self, *args, **kwargs):
        app.Canvas.__init__(self, *args, **kwargs)
        timer = app.Timer(1.0)
        timer.connect(self.on_timer)
        timer.start()

    def on_initialize(self, event):
        gl.glClearColor(0, 0, 0, 1)
        print('on_initialize')

    def on_close(self, event):
        print('on_close')
コード例 #4
0
# !/usr/bin/env python
# -*- coding: utf-8 -*-
"""
This example shows how to actively select and test the qt backend.

You should see a black window and any mouse or keyboard event should be
detected. A timer is also run every second and it should print "tick !"
every second.
"""

from vispy import app
from vispy.gloo import gl
app.use('qt')


class Canvas(app.Canvas):

    def __init__(self, *args, **kwargs):
        app.Canvas.__init__(self, *args, **kwargs)
        timer = app.Timer(1.0)
        timer.connect(self.on_timer)
        timer.start()

    def on_initialize(self, event):
        gl.glClearColor(0, 0, 0, 1)
        print('on_initialize')

    def on_close(self, event):
        print('on_close')

    def on_resize(self, event):
コード例 #5
0
ファイル: app-pyglet.py プロジェクト: ds604/vispy
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
This example shows how to actively select and test the pyglet backend.

You should see a black window and any mouse or keyboard event should be
detected. A timer is also ran every second and it should print "tick !"
every second.
"""

from vispy import app
from vispy.gloo import gl
app.use('pyglet')

class Canvas(app.Canvas):
    def __init__(self, *args, **kwargs):
        app.Canvas.__init__(self, *args, **kwargs)
        timer = app.Timer(1.0)
        timer.connect(self.on_timer)
        timer.start()

    def on_initialize(self, event):
        gl.glClearColor(0,0,0,1)
        print('on_initialize')

    def on_close(self, event):
        print('on_close')

    def on_resize(self, event):
        print('on_resize (%dx%d)' % event.size)
コード例 #6
0
import numpy as np
from vispy import app
from vispy import gloo
from vispy.gloo import gl

app.use('glfw')

vertex = """
attribute float x;
attribute float y;
void main (void)
{
    gl_Position = vec4(x, y, 0.0, 1.0);
}
"""

fragment = """
void main()
{
    gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);
}
"""


class Window(app.Canvas):
    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)
コード例 #7
0
ファイル: app-pyglet.py プロジェクト: ds604/vispy
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
This example shows how to actively select and test the pyglet backend.

You should see a black window and any mouse or keyboard event should be
detected. A timer is also ran every second and it should print "tick !"
every second.
"""

from vispy import app
from vispy.gloo import gl
app.use('pyglet')


class Canvas(app.Canvas):
    def __init__(self, *args, **kwargs):
        app.Canvas.__init__(self, *args, **kwargs)
        timer = app.Timer(1.0)
        timer.connect(self.on_timer)
        timer.start()

    def on_initialize(self, event):
        gl.glClearColor(0, 0, 0, 1)
        print('on_initialize')

    def on_close(self, event):
        print('on_close')

    def on_resize(self, event):
        print('on_resize (%dx%d)' % event.size)
コード例 #8
0
ファイル: glsl-sandbox-cube.py プロジェクト: per42/vispy
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
A GLSL sandbox application based on the spinning cube. Requires PySide
or PyQt4.
"""

import numpy as np
from vispy import app, gloo, dataio
from vispy.util.transforms import perspective, translate, rotate

# Force using qt and take QtCore+QtGui from backend module,
# since we do not know whether PySide or PyQt4 is used
app.use("qt")
QtCore = (app.default_app.backend_module.QtCore,)
QtGui = app.default_app.backend_module.QtGui


VERT_CODE = """
uniform   mat4 u_model;
uniform   mat4 u_view;
uniform   mat4 u_projection;

attribute vec3 a_position;
attribute vec2 a_texcoord;

varying vec2 v_texcoord;

void main()
{
    v_texcoord = a_texcoord;