本文整理汇总了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)
示例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()
示例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)
示例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)
示例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()
示例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()
示例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()
示例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))
示例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()
示例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()
示例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()
示例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)
示例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
示例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()
示例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()