当前位置: 首页>>代码示例>>Python>>正文


Python transforms.translate函数代码示例

本文整理汇总了Python中vispy.util.transforms.translate函数的典型用法代码示例。如果您正苦于以下问题:Python translate函数的具体用法?Python translate怎么用?Python translate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了translate函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

    def __init__(self):
        app.Canvas.__init__(self, keys='interactive')
        self.size = 800, 800
        self.title = "Atom [zoom with mouse scroll"

        self.program = gloo.Program(vert, frag)
        self.view = np.eye(4, dtype=np.float32)
        self.model = np.eye(4, dtype=np.float32)
        self.projection = np.eye(4, dtype=np.float32)
        self.translate = 6.5
        translate(self.view, 0, 0, -self.translate)

        self.program.bind(gloo.VertexBuffer(data))
        self.program['u_model'] = self.model
        self.program['u_view'] = self.view
        self.program['u_size'] = 5 / self.translate

        self.theta = 0
        self.phi = 0
        self.clock = 0
        self.stop_rotation = False

        gloo.set_state('translucent', depth_test=False)
        self.program['u_clock'] = 0.0

        self._timer = app.Timer('auto', connect=self.on_timer, start=True)
开发者ID:almarklein,项目名称:vispy,代码行数:26,代码来源:atom.py

示例2: __init__

    def __init__(self):
        app.Canvas.__init__(self, size=(512, 512), title='Rotating cube',
                            keys='interactive')
        self.timer = app.Timer('auto', self.on_timer)

        # Build cube data
        V, I, O = create_cube()
        vertices = VertexBuffer(V)
        self.faces = IndexBuffer(I)
        self.outline = IndexBuffer(O)

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

        # Build view, model, projection & normal
        # --------------------------------------
        view = np.eye(4, dtype=np.float32)
        model = np.eye(4, dtype=np.float32)
        translate(view, 0, 0, -5)
        self.program['u_model'] = model
        self.program['u_view'] = view
        self.phi, self.theta = 0, 0

        # OpenGL initalization
        # --------------------------------------
        gloo.set_state(clear_color=(0.30, 0.30, 0.35, 1.00), depth_test=True,
                       polygon_offset=(1, 1), line_width=0.75,
                       blend_func=('src_alpha', 'one_minus_src_alpha'))
        self.timer.start()
开发者ID:almarklein,项目名称:vispy,代码行数:31,代码来源:outlined_cube.py

示例3: __init__

    def __init__(self, **kwargs):
        
        self.program = gloo.Program(VERT_SHADER, FRAG_SHADER)
        self.view       = np.eye(4,dtype=np.float32)
        self.model      = np.eye(4,dtype=np.float32)
        self.projection = np.eye(4,dtype=np.float32)
        self.translate = 3
        translate(self.view, 0,0, -self.translate)
        
        self.vbo = gloo.VertexBuffer(data)
        self.program.set_vars(self.vbo )
        self.program['u_model'] = self.model
        self.program['u_view'] = self.view
        self.program['u_size'] = u_size

        self.theta = 0
        self.phi = 0
        self.index = 0

        self.timer = app.Timer(1.0/400)
        self.timer.connect(self.on_timer)
        self.timer.start()
        
        # Initialize for real
        app.Canvas.__init__(self, **kwargs)
开发者ID:ds604,项目名称:vispy,代码行数:25,代码来源:atom.py

示例4: __init__

    def __init__(self):
        app.Canvas.__init__(self, keys='interactive')
        self.size = 800, 800
        self.title = "D'oh ! A big donut"

        self.program = gloo.Program(vert, frag)
        self.view = np.eye(4, dtype=np.float32)
        self.model = np.eye(4, dtype=np.float32)
        self.projection = np.eye(4, dtype=np.float32)
        self.translate = 5
        translate(self.view, 0, 0, -self.translate)

        self.program.bind(gloo.VertexBuffer(data))
        self.program['u_linewidth'] = u_linewidth
        self.program['u_antialias'] = u_antialias
        self.program['u_model'] = self.model
        self.program['u_view'] = self.view
        self.program['u_size'] = 5 / self.translate

        self.theta = 0
        self.phi = 0
        self.clock = 0
        self.stop_rotation = False

        gloo.set_state('translucent', clear_color='white')
        self.program['u_clock'] = 0.0

        self._timer = app.Timer('auto', connect=self.on_timer, start=True)
开发者ID:almarklein,项目名称:vispy,代码行数:28,代码来源:donut.py

示例5: __init__

    def __init__(self):
        app.Canvas.__init__(self, keys='interactive')
        self.size = 800, 600
        self.title = "A very fake galaxy [mouse scroll to zoom]"

        self.program = gloo.Program(VERT_SHADER, FRAG_SHADER)
        self.view = np.eye(4, dtype=np.float32)
        self.model = np.eye(4, dtype=np.float32)
        self.projection = np.eye(4, dtype=np.float32)
        self.theta, self.phi = 0, 0

        self.translate = 5
        translate(self.view, 0, 0, -self.translate)

        self.program.bind(gloo.VertexBuffer(data))
        self.program['u_colormap'] = gloo.Texture2D(cmap)
        self.program['u_size'] = 5. / self.translate
        self.program['u_model'] = self.model
        self.program['u_view'] = self.view

        gloo.set_state(depth_test=False, blend=True,
                       blend_func=('src_alpha', 'one'), clear_color='black')

        # Start the timer upon initialization.
        self.timer = app.Timer('auto', connect=self.on_timer)
        self.timer.start()
开发者ID:almarklein,项目名称:vispy,代码行数:26,代码来源:galaxy.py

示例6: on_initialize

    def on_initialize(self, event):
        # Build cube data
        V, I, O = create_cube()
        vertices = VertexBuffer(V)
        self.faces = IndexBuffer(I)
        self.outline = IndexBuffer(O)

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

        # Build view, model, projection & normal
        # --------------------------------------
        view = np.eye(4, dtype=np.float32)
        model = np.eye(4, dtype=np.float32)
        translate(view, 0, 0, -5)
        self.program['u_model'] = model
        self.program['u_view'] = view
        self.phi, self.theta = 0, 0

        # OpenGL initalization
        # --------------------------------------
        gloo.set_state(clear_color=(0.30, 0.30, 0.35, 1.00), depth_test=True,
                       polygon_offset=(1, 1), line_width=0.75,
                       blend_func=('src_alpha', 'one_minus_src_alpha'))
        self.timer.start()
开发者ID:gbaty,项目名称:vispy,代码行数:27,代码来源:outlined_cube.py

示例7: on_initialize

    def on_initialize(self, event):
        # Build cube data
        V, F, O = create_cube()
        vertices = VertexBuffer(V)
        self.faces = IndexBuffer(F)
        self.outline = IndexBuffer(O)

        # Build view, model, projection & normal
        # --------------------------------------
        self.view = np.eye(4, dtype=np.float32)
        model = np.eye(4, dtype=np.float32)
        translate(self.view, 0, 0, -5)
        normal = np.array(np.matrix(np.dot(self.view, model)).I.T)

        # Build program
        # --------------------------------------
        self.program = Program(vertex, fragment)
        self.program.bind(vertices)
        self.program["u_light_position"] = 2, 2, 2
        self.program["u_light_intensity"] = 1, 1, 1
        self.program["u_model"] = model
        self.program["u_view"] = self.view
        self.program["u_normal"] = normal
        self.phi, self.theta = 0, 0

        # OpenGL initalization
        # --------------------------------------
        gloo.set_state(clear_color=(0.30, 0.30, 0.35, 1.00), depth_test=True,
                       polygon_offset=(1, 1),
                       blend_func=('src_alpha', 'one_minus_src_alpha'),
                       line_width=0.75)
        self.timer.start()
开发者ID:gbaty,项目名称:vispy,代码行数:32,代码来源:lighted_cube.py

示例8: test_transforms

def test_transforms():
    """Test basic transforms"""
    xfm = np.random.randn(4, 4).astype(np.float32)

    for rot in [xrotate, yrotate, zrotate]:
        new_xfm = rot(rot(xfm, 90), -90)
        assert_allclose(xfm, new_xfm)

    new_xfm = rotate(rotate(xfm, 90, 1, 0, 0), 90, -1, 0, 0)
    assert_allclose(xfm, new_xfm)

    new_xfm = translate(translate(xfm, 1, -1), 1, -1, 1)
    assert_allclose(xfm, new_xfm)

    new_xfm = scale(scale(xfm, 1, 2, 3), 1, 1. / 2., 1. / 3.)
    assert_allclose(xfm, new_xfm)

    # These could be more complex...
    xfm = ortho(-1, 1, -1, 1, -1, 1)
    assert_equal(xfm.shape, (4, 4))

    xfm = frustum(-1, 1, -1, 1, -1, 1)
    assert_equal(xfm.shape, (4, 4))

    xfm = perspective(1, 1, -1, 1)
    assert_equal(xfm.shape, (4, 4))
开发者ID:almarklein,项目名称:vispy,代码行数:26,代码来源:test_transforms.py

示例9: __init__

    def __init__(self):
        app.Canvas.__init__(self)
        self.size = 800, 800
        self.title = "D'oh ! A big donut"

        self.program = gloo.Program(vert, frag)
        self.view = np.eye(4, dtype=np.float32)
        self.model = np.eye(4, dtype=np.float32)
        self.projection = np.eye(4, dtype=np.float32)
        self.translate = 5
        translate(self.view, 0, 0, -self.translate)

        self.program.bind(gloo.VertexBuffer(data))
        self.program['u_linewidth'] = u_linewidth
        self.program['u_antialias'] = u_antialias
        self.program['u_model'] = self.model
        self.program['u_view'] = self.view
        self.program['u_size'] = 5 / self.translate

        self.theta = 0
        self.phi = 0
        self.clock = 0
        self.stop_rotation = False

        self.timer = app.Timer(1.0 / 60)
        self.timer.connect(self.on_timer)
        self.timer.start()
开发者ID:LiloD,项目名称:vispy,代码行数:27,代码来源:donut.py

示例10: __init__

    def __init__(self):
        app.Canvas.__init__(self, size=(512, 512), title='Textured cube',
                            keys='interactive')
        self.timer = app.Timer('auto', self.on_timer)

        # 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 = np.eye(4, dtype=np.float32)
        model = np.eye(4, dtype=np.float32)
        translate(view, 0, 0, -5)
        self.program['model'] = model
        self.program['view'] = view
        self.program['texture'] = checkerboard()

        self.phi, self.theta = 0, 0

        # OpenGL initalization
        gloo.set_state(clear_color=(0.30, 0.30, 0.35, 1.00), depth_test=True)
        self.timer.start()
开发者ID:almarklein,项目名称:vispy,代码行数:27,代码来源:textured_cube.py

示例11: __init__

    def __init__(self):
        app.Canvas.__init__(self)
        self.size = 800, 600

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

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

        self.view = np.eye(4, dtype=np.float32)
        self.model = np.eye(4, dtype=np.float32)
        self.projection = np.eye(4, dtype=np.float32)

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

        self.theta = 0
        self.phi = 0

        self._timer = app.Timer(1.0 / 60)
        self._timer.connect(self.on_timer)
        self._timer.start()
开发者ID:LiloD,项目名称:vispy,代码行数:25,代码来源:rotate-cube.py

示例12: __init__

    def __init__(self):
        app.Canvas.__init__(self, keys='interactive')
        self.size = 800, 600

        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 = np.eye(4, dtype=np.float32)
        self.model = np.eye(4, dtype=np.float32)
        self.projection = np.eye(4, dtype=np.float32)

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

        self.theta = 0
        self.phi = 0

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

        self._timer = app.Timer('auto', connect=self.on_timer, start=True)
开发者ID:almarklein,项目名称:vispy,代码行数:27,代码来源:rotate_cube.py

示例13: __init__

    def __init__(self):
        Canvas.__init__(self, size=[800, 800], close_keys='ESCAPE', show=True,
                        title='Galaxy')
        self.galaxy = Galaxy(35000)
        self.galaxy.reset(13000, 4000, 0.0004, 0.90, 0.90, 0.5, 200, 300)
        program = gloo.Program(vertex, fragment, count=len(self.galaxy))
        view = np.eye(4, dtype=np.float32)
        translate(view, 0, 0, -5)
        program['u_view'] = view
        program['u_model'] = np.eye(4, dtype=np.float32)
        program['u_projection'] = np.eye(4, dtype=np.float32)

        from PIL import Image
        from specrend import (SMPTEsystem, spectrum_to_xyz, norm_rgb,
                              xyz_to_rgb, bb_spectrum)
        image = Image.open("particle.bmp")
        program['u_texture'] = np.array(image)/255.0
        t0 = 1000.
        t1 = 10000.
        n = 256
        dt = (t1 - t0) / n
        colors = np.zeros((1, n, 3), dtype=np.float32)
        for i in range(n):
            cs = SMPTEsystem
            temperature = t0 + i*dt
            x, y, z = spectrum_to_xyz(bb_spectrum, temperature)
            r, g, b = xyz_to_rgb(cs, x, y, z)
            colors[0, i] = norm_rgb(r, g, b)
        program['u_colormap'] = gloo.Texture2D(colors)
        program['a_size'] = self.galaxy['size']
        program['a_type'] = self.galaxy['type']
        self.program = program
开发者ID:Eric89GXL,项目名称:galaxy,代码行数:32,代码来源:view.py

示例14: on_mouse_wheel

 def on_mouse_wheel(self, event):
     self.translate += event.delta[1]
     self.translate = max(2, self.translate)
     self.view = np.eye(4, dtype=np.float32)
     translate(self.view, 0, 0, -self.translate)
     self.program['u_view'] = self.view
     self.update()
开发者ID:Peque,项目名称:vispy,代码行数:7,代码来源:display_lines.py

示例15: on_initialize

    def on_initialize(self, event):
        # create a new shader program
        self.program = gloo.Program(VERT_SHADER, FRAG_SHADER,
                                    count=len(galaxy))

        # load the star texture
        self.texture = gloo.Texture2D(load_galaxy_star_image(),
                                      interpolation='linear')
        self.program['u_texture'] = self.texture

        # construct the model, view and projection matrices
        self.view = np.eye(4, dtype=np.float32)
        transforms.translate(self.view, 0, 0, -5)
        self.program['u_view'] = self.view

        self.model = np.eye(4, dtype=np.float32)
        self.program['u_model'] = self.model

        self.program['u_colormap'] = colors

        self.projection = perspective(45.0, self.width / float(self.height),
                                      1.0, 1000.0)
        self.program['u_projection'] = self.projection

        # start the galaxy to some decent point in the future
        galaxy.update(100000)
        data = self.__create_galaxy_vertex_data()

        # setup the VBO once the galaxy vertex data has been setup
        # bind the VBO for the first time
        self.data_vbo = gloo.VertexBuffer(data)
        self.program.bind(self.data_vbo)

        # setup blending
        self.__setup_blending_mode()
开发者ID:rossant,项目名称:vispy,代码行数:35,代码来源:galaxy.py


注:本文中的vispy.util.transforms.translate函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。