本文整理汇总了Python中vispy.app.run函数的典型用法代码示例。如果您正苦于以下问题:Python run函数的具体用法?Python run怎么用?Python run使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了run函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
def run(self, rom_path):
# Firstly load the ROM
self.cpu.memory.read_rom(rom_path)
# Setup a canvas
canvas = GameBoy.GBCanvas()
app.run()
while self.running:
# Increment the PC
if self.debug:
print("Exec PC: " + str(hex(self.cpu.r["pc"])))
# Firstly execute an instruction
self.cpu.executeOpcode(self.cpu.memory.read(self.cpu.r["pc"]))
# Sync the GPU with the CPU
self.gpu.sync(self.cpu.last_clock_inc)
# Get a frame if it is ready
frame = self.gpu.get_frame()
if frame is not None:
# Place the frame into the current
canvas.set_frame(frame)
self.cpu.incPC()
示例2: traces
def traces(args):
from vispy.app import run
from phy.plot.traces import TraceView
from phy.io.h5 import open_h5
from phy.io.traces import read_kwd, read_dat
path = args.file
if path.endswith('.kwd'):
f = open_h5(args.file)
traces = read_kwd(f)
elif path.endswith(('.dat', '.bin')):
if not args.n_channels:
raise ValueError("Please specify `--n-channels`.")
if not args.dtype:
raise ValueError("Please specify `--dtype`.")
if not args.sample_rate:
raise ValueError("Please specify `--sample-rate`.")
n_channels = int(args.n_channels)
dtype = np.dtype(args.dtype)
traces = read_dat(path, dtype=dtype, n_channels=n_channels)
start, end = map(int, args.interval.split(','))
sample_rate = float(args.sample_rate)
start = int(sample_rate * start)
end = int(sample_rate * end)
c = TraceView(keys='interactive')
c.visual.traces = .01 * traces[start:end, ...]
c.show()
run()
return None, None
示例3: visualise_path
def visualise_path(path):
canvas = scene.SceneCanvas(show=True, keys='interactive')
grid = canvas.central_widget.add_grid()
vb = grid.add_view(name='vb')
vb.parent = canvas.scene
vb.clip_method='viewport'
vb.camera = scene.TurntableCamera(elevation=30, azimuth=30, up='+z')
a = []
col = True
for i in range(len(path)):
if i == 0:
a += [(0.0, 0.0, 1.0, 1.0)]
elif col:
a += [(1.0, 0.0, 0.0, 1.0)]
else:
a += [(0.0, 1.0, 0.0, 1.0)]
col = not col
line1 = scene.visuals.Line(pos = path.copy(),
method = 'gl',
antialias=True,
name='line1',
color=a,
parent=vb.scene,
connect='strip')
ax = scene.visuals.XYZAxis(name='test', parent=vb)
app.run()
示例4: tetplot
def tetplot(points, simplices, vertex_color=None,
edge_color=None, alpha=1.0, axis=True):
""" main function for tetplot """
TetPlot = scene.visuals.create_visual_node(TetPlotVisual)
# convert data types for OpenGL
pts_float32 = points.astype(np.float32)
sim_uint32 = simplices.astype(np.uint32)
# The real-things : plot using scene
# build canvas
canvas = scene.SceneCanvas(keys='interactive', show=True)
# Add a ViewBox to let the user zoom/rotate
view = canvas.central_widget.add_view()
view.camera = 'turntable'
view.camera.fov = 50
view.camera.distance = 5
# toggle drawing mode
TetPlot(pts_float32, sim_uint32, vertex_color,
color=None, alpha=alpha, mode='triangles', parent=view.scene)
if edge_color is not None:
TetPlot(pts_float32, sim_uint32, vertex_color,
color=edge_color, alpha=alpha, mode='lines',
parent=view.scene)
# show axis
if axis:
scene.visuals.XYZAxis(parent=view.scene)
# run
if sys.flags.interactive != 1:
app.run()
示例5: show
def show(self):
if self._points is None:
raise ValueError("Points is empty, please call imgToPoints() first.")
# centralize
self.centralize()
# colors
colors = np.array(np.abs(self._points[:,:3]),dtype=np.float32)
mx = np.max(colors[:,0])
my = np.max(colors[:,1])
mz = np.max(colors[:,2])
brighter = 0.05
colors[:,0]/=mx+brighter
colors[:,1]/=my+brighter
colors[:,2]/=mz+brighter
alpha = np.empty((len(colors[:,0]),1))
alpha.fill(0.8)
colors = np.hstack([colors,alpha])
# sizes
sizes = self.histogramEqualize()
# visualize
c = Canvas(self._points[:,:3],colors,sizes)
app.run()
示例6: main
def main(argv):
argParser = argparse.ArgumentParser()
argParser.add_argument('-s', '--start_frame', action='store', type=int, default=0,
help='starting frame for viewing the sequence')
argParser.add_argument("path", action="store", type=str,
help="path to either .sima folder or imaging sequence")
args = argParser.parse_args(argv)
canvas = Canvas(args.path, start=args.start_frame)
canvas.show()
app.run()
示例7: __init__
def __init__(self, h):
self.h = h
app.Canvas.__init__(self, keys='interactive', size=(800, 550))
hcyl = mplcyl.TruncatedCone()
print('1')
#plot_tc(p0=np.array([1, 3, 2]), p1=np.array([8, 5, 9]), R=[5.0, 2.0])
verts, edges = h.get_geometry()
self.meshes = []
self.rotation = MatrixTransform()
sec_ids = []
s = 1.0
x, y = 0., 0.
for edge in edges:
ends = verts['pos'][edge] # xyz coordinate of one end [x,y,z]
dia = verts['dia'][edge] # diameter at that end
sec_id = verts['sec_index'][edge[0]] # save the section index
dif = ends[1]-ends[0] # distance between the ends
length = (dif**2).sum() ** 0.5
# print length
# print dia
#C, T, B = hcyl.make_truncated_cone(p0=ends[0], p1=ends[1], R=[dia[0]/2., dia[1]/2.])
mesh_verts = create_cylinder(8, 8, radius=[dia[0]/2., dia[1]/2.], length=length, offset=False)
#mesh_verts = create_grid_mesh(C[0], C[1], C[2])
# sec_id_array = np.empty(mesh_verts.shape[0]*3, dtype=int)
# # sec_id_array[:] = sec_id
# meshes.append(mesh_verts)
# sec_ids.append(sec_id_array)
self.meshes.append(visuals.MeshVisual(meshdata=mesh_verts, color='r'))
# transform = ChainTransform([STTransform(translate=(x, y),
# scale=(s, s, s)),
# self.rotation])
#
# for i, mesh in enumerate(self.meshes):
# # x = 800. * (i % grid[0]) / grid[0] + 40
# mesh.transform = transform
# mesh.transforms.scene_transform = STTransform(scale=(1, 1, 0.01))
gloo.set_viewport(0, 0, *self.physical_size)
gloo.clear(color='white', depth=True)
for mesh in self.meshes:
mesh.draw()
print('running')
self.show()
if sys.flags.interactive != 1:
app.run()
示例8: drawShadows
def drawShadows(inputFile='/Users/rachel/Downloads/cloud_frac_padded_623_812_70_4096_4096.png',
outputFile='/Users/rachel/Downloads/newshadow.png',
lightPosition=(20, 0, 0),
dataShape=(623, 812, 70),
textureShape=(4096, 4096),
tileLayout=(6,5),
steps=81,
alphaScale=2):
'''
Given a tiled data PNG file and a light position, computes the shadows
on the data and writes them to a second PNG.
@param inputFile: path to the input PNG
@type inputFile: string
@param outputFile: path to write out the results
@type outputFile: string
@param lightPosition: position of the point light
@type lightPosition: 3-tuple
@param dataShape: 3D shape of the data field
@type dataShape: 3-tuple
@param textureShape: shape of the input image
@type textureShape: 2-tuple
@param tileLayout: (cols, rows) arrangement of tiles in the input PNG
@type tileLayout: 2-tuple
@param steps: how many steps to take through the data in calculations
@type steps: int
@param alphaScale: factor to scale the light absorption
@type alphaScale: number
'''
width = textureShape[0]
height = textureShape[1]
c = app.Canvas(show=False, size=(width, height))
cloudTex = getCloudTexture(inputFile, width, height)
vertexPath = os.path.join(homeDir, 'shadow_vertex.glsl')
fragmentPath = os.path.join(homeDir, 'shadow_frag.glsl')
vertex = getShader(vertexPath)
fragment = getShader(fragmentPath)
program = mkProgram(vertex, fragment, cloudTex, dataShape=dataShape, textureShape=textureShape, tileLayout=tileLayout)
setLightPosition(program, lightPosition)
setResolution(program, steps, alphaScale)
@c.connect
def on_draw(event):
gloo.clear((1,1,1,1))
program.draw(gl.GL_TRIANGLE_STRIP)
im = gloo.util._screenshot((0, 0, c.size[0], c.size[1]))
imsave(outputFile, im)
c.close()
app.run()
示例9: __init__
def __init__(self, bubble_list, boundaries = np.asarray([[0, 10], [0, 10], [0, 10]])):
self.auto = False
self.time_step = 0.05
self.bubbles = bubble_list
self.bound = boundaries
for bble in self.bubbles:
bble.set_bound(self.bound)
canvas = vscene.SceneCanvas(show=True, title=sys.argv[0])
# canvas.measure_fps()
view = canvas.central_widget.add_view()
if self.bound is not None:
bound_pt = np.array([[self.bound[0, 0], self.bound[1, 0], self.bound[2, 0]],
[self.bound[0, 1], self.bound[1, 0], self.bound[2, 0]],
[self.bound[0, 1], self.bound[1, 1], self.bound[2, 0]],
[self.bound[0, 0], self.bound[1, 1], self.bound[2, 0]],
[self.bound[0, 0], self.bound[1, 0], self.bound[2, 0]],
[self.bound[0, 0], self.bound[1, 0], self.bound[2, 1]],
[self.bound[0, 1], self.bound[1, 0], self.bound[2, 1]],
[self.bound[0, 1], self.bound[1, 1], self.bound[2, 1]],
[self.bound[0, 0], self.bound[1, 1], self.bound[2, 1]],
[self.bound[0, 0], self.bound[1, 0], self.bound[2, 1]]],
dtype=np.float32)
bound_vi = vscene.visuals.Line(pos=bound_pt, color=(1.00, 1.00, 1.00, 0.25))
view.add(bound_vi)
view.camera = 'turntable'
for bble in self.bubbles:
bble.init_visual(view)
def update(ev):
for bble in self.bubbles:
bble.step(self.time_step)
timer = vapp.Timer()
timer.connect(update)
@canvas.events.key_press.connect
def on_key_press(event):
if event.key == 'Right':
for bble in self.bubbles:
bble.step(self.time_step)
if event.key == 'Space':
if self.auto:
timer.stop()
self.auto = False
else:
timer.start(self.time_step)
self.auto = True
if event.key == 's':
for bble in self.bubbles:
bble.shake()
vapp.run()
示例10: tetplot
def tetplot(points, simplices):
""" main function for tetplot """
colors = np.random.rand(points.shape[0], 4)
colors[:, -1] = 1.0
colors = colors.astype(np.float32)
# extract triangles and edges
triangles = sim2tri(simplices)
edges = sim2edge(simplices)
# plot
Canvas(points, colors, triangles, edges)
app.run()
示例11: tetplot
def tetplot(points, simplices, vertex_color=None,
edge_color=None, alpha=1.0, axis=True):
""" main function for tetplot """
TetPlot = scene.visuals.create_visual_node(TetPlotVisual)
# convert data types for OpenGL
pts_float32 = points.astype(np.float32)
sim_uint32 = simplices.astype(np.uint32)
# The real-things : plot using scene
# build canvas
canvas = scene.SceneCanvas(keys='interactive', show=True)
# Add a ViewBox to let the user zoom/rotate
view = canvas.central_widget.add_view()
view.camera = 'turntable'
view.camera.fov = 50
view.camera.distance = 3
if vertex_color is not None and vertex_color.ndim == 1:
vertex_color = blue_red_colormap(vertex_color)
# drawing only triangles
# 1. turn off mask_color, default = [1.0, 1.0, 1.0, alpha]
# 2. mode = 'triangles'
TetPlot(pts_float32, sim_uint32, vertex_color,
mask_color=None, alpha=alpha, mode='triangles',
parent=view.scene)
# drawing only lines
# 1. turn off vertex_color, default = [[1.0, 1.0, 1.0, 1.0]*N]
# 2. mode = 'lines'
# 3. alpha channel is specified instead of mask_color
if edge_color is not None:
TetPlot(pts_float32, sim_uint32, vertex_color=None,
mask_color=edge_color, alpha=alpha, mode='lines',
parent=view.scene)
# show axis
if axis:
scene.visuals.XYZAxis(parent=view.scene)
# run
app.run()
示例12: plot
def plot(self):
from vispy import app, scene, io
# Prepare canvas
canvas = scene.SceneCanvas(keys='interactive', size=(800, 600), show=True)
canvas.measure_fps()
# Set up a viewbox to display the image with interactive pan/zoom
view = canvas.central_widget.add_view()
for a in self.actors:
a.init_visual(scene, view.scene)
fov = 60.
cam1 = scene.cameras.FlyCamera(parent=view.scene, fov=fov, name='Fly')
view.camera = cam1
# def on_resize(self, event):
# 176 # setup the new viewport
# gloo.set_viewport(0, 0, *event.physical_size)
# w, h = event.size
# self.projection = perspective(45.0, w / float(h), 1.0, 1000.0)
# self.program['u_projection'] = self.projection
dt = 0.002
def update(event):
# update the simulation
for i in range(1):
self.integrate(dt)
# upload new state to gpu
for i in range(len(self.actors)):
actor = self.actors[i]
if isinstance(actor, MeshActor):
if not isinstance(actor, StaticActor):
actor.visual.set_data(vertices=actor.position[actor.mesh.faces])
if isinstance(actor, ParticleActor):
actor.visual.set_data(actor.position)
timer = app.Timer(interval=dt, connect=update)
timer.start()
app.run()
示例13: plot
def plot(mesh, show_k=False, show_v=False, show_f=False):
points = mesh.points
springs = mesh.springs
canvas = scene.SceneCanvas(keys='interactive', show=True)
view = canvas.central_widget.add_view()
view.camera = 'panzoom'
view.camera.aspect = 1
edges = springs[['p0', 'p1']].view(('i8', 2))
lines = scene.Line(
pos=points, connect=edges,
antialias=False,
method='gl', color='green', parent=view.scene)
markers = scene.Markers(
pos=points, face_color='blue', symbol='o', parent=view.scene,
size=0.5, scaling=True
)
view.camera.set_range()
app.run()
示例14: procShadows
def procShadows(dataArray,
dataShape=(623, 812, 70),
lightPosition=(20, 0, 0),
steps=81,
alphaScale=2,
ambience=0.3):
'''
Given a tiled data PNG file and a light position, computes the shadows
on the data and writes them to a second PNG.
Args:
* dataArray (array): data for which to calculate shadows
* dataShape (3-tuple): 3D shape of the data field
* lightPosition (3-tuple): position of the point light
* steps (int): how many steps to take through the data in calculations
* alphaScale (int): factor to scale the light absorption
'''
dataTexture = makeTexture(dataArray)
textureShape = dataArray.shape[:2]
tileLayout = (int(textureShape[0]/dataShape[0]),
int(textureShape[1]/dataShape[1]))
vertex = getShader(os.path.join(homeDir, 'shadow_vertex.glsl'))
fragment = getShader(os.path.join(homeDir, 'shadow_frag.glsl'))
program = makeProgram(vertex, fragment, dataTexture,
dataShape=dataShape,
textureShape=textureShape,
tileLayout=tileLayout)
setLightPosition(program, lightPosition)
setResolution(program, steps, alphaScale)
setAmbientLight(program, ambience)
c = Canvas(size=textureShape, program=program)
app.run()
render = c.shadowsArray[:, :, :3]
return render
示例15: run
def run(
mesh, show_k=False, show_v=False, show_f=False,
run=None, verbose=False):
points = mesh.points
springs = mesh.springs
canvas = scene.SceneCanvas(keys='interactive', show=True)
view = canvas.central_widget.add_view()
view.camera = 'panzoom'
view.camera.aspect = 1
edges = springs[['p0', 'p1']].view(('i8', 2))
lines = scene.Line(
pos=points, connect=edges,
antialias=False,
method='gl', color='green', parent=view.scene)
markers = scene.Markers(
pos=points, face_color='blue', symbol='o', parent=view.scene,
size=0.5, scaling=True
)
view.camera.set_range()
def update(ev):
t0 = time.time()
run(mesh)
t1 = time.time()
if verbose:
print("run: %s" % (t1 - t0, ))
if mesh.points.min() == numpy.nan or mesh.points.max() == numpy.nan:
return False
t0 = time.time()
markers.set_data(pos=mesh.points, size=0.5, scaling=True)
lines.set_data(pos=mesh.points)
t1 = time.time()
if verbose:
print("set_data: %s" % (t1 - t0, ))
if run is not None:
timer = app.Timer(interval=0, connect=update, start=True)
app.run()