本文整理汇总了Python中visual.rate函数的典型用法代码示例。如果您正苦于以下问题:Python rate函数的具体用法?Python rate怎么用?Python rate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rate函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
def run(self):
'''
Run the simulation with racers that had been previously added to the world
by add_racer method.
'''
# create the scene with the plane at the top
visual.scene.center = visual.vector(0,-25,0)
visual.box(pos=(0,0,0), size=(12,0.2,12), color=visual.color.green)
# create the visual objects that represent the racers (balls)
balls = [ visual.sphere(pos=(index,0,0), radius=0.5) for index in xrange(len(self.racers))]
for ball, racer in zip(balls, self.racers):
color = visual.color.blue
try:
# try to set the color given by a string
color = getattr(visual.color, racer.color)
except AttributeError:
pass
ball.trail = visual.curve(color=color)
while not reduce(lambda x, y: x and y, [racer.result for racer in self.racers]):
# slow down the looping - allow only self.time_calibration
# number of loop entries for a second
visual.rate(self.time_calibration)
# move the racers
for racer in self.racers:
self.__move_racer(racer)
for ball, racer in zip(balls, self.racers):
ball.pos.y = -racer.positions[-1][1]
ball.pos.x = racer.positions[-1][0]
ball.trail.append(pos=ball.pos)
self.current_time += self.interval
self.timeline.append(self.current_time)
示例2: prompt
def prompt(self, initial=""):
"""\
Display a prompt and process the command entered by the user.
@return: The command string to be processed by the parent object.
@rtype: C{str}
"""
self.userspin = False
self.message(initial + " ")
cmd = ""
process_cmd = False
while True:
visual.rate(VISUAL_SETTINGS["rate"] * 2)
if self.kb.keys:
k = self.kb.getkey()
if k == "\n":
process_cmd = True
self.message()
break
elif k == "backspace":
if len(cmd) > 0:
cmd = cmd[:-1]
else:
self.message()
break
elif k.isalnum() or k in " -_(),.[]+*%=|&:<>'~/\\":
cmd += k
self.message(initial + " " + cmd)
self.userspin = True
return cmd if process_cmd else None
示例3: PlotSphereEvolution3
def PlotSphereEvolution3(f):
data = json.loads(open(f, "r").read())
center = (
(data["SystemSize"][1][0]+data["SystemSize"][0][0])*0.5,
(data["SystemSize"][1][1]+data["SystemSize"][0][1])*0.5,
(data["SystemSize"][1][2]+data["SystemSize"][0][2])*0.5
)
scene = vs.display(title='3D representation',
x=0, y=0, width=1920, height=1080,
center=center,background=(0,0,0)
)
vs.box(pos=center,
length=data["SystemSize"][1][0]-data["SystemSize"][0][0],
height=data["SystemSize"][1][1]-data["SystemSize"][0][1],
width= data["SystemSize"][1][2]-data["SystemSize"][0][2],
opacity=0.2,
color=vs.color.red)
spheres = [vs.sphere(radius=data["SphereSize"],pos=(data["Data"][0][0][i], data["Data"][1][0][i], data["Data"][2][0][i])) for i in range(data["SpheresNumber"])]
nt = 0
while True:
vs.rate(60)
for i in range(data["SpheresNumber"]):
spheres[i].pos = (data["Data"][0][nt][i], data["Data"][1][nt][i], data["Data"][2][nt][i])
if nt + 1 >= data["SavedSteps"]:
nt = 0
else:
nt += 1
示例4: golf_ball_calc
def golf_ball_calc(x,y,z,vx,vy,vz,dt,m,g,B2,S0,w,w_vector):
t = 0.0
x_list = [x]
y_list = [y]
z_list = [z]
vx_list = [vx]
vy_list = [vy]
vz_list = [vz]
t_list = [t]
v_vector = visual.vector(vx,vy,vz)
tee = visual.box(pos=(0,0,0), length=0.05, width=0.05, height=0.5,color=visual.color.white)
ball = visual.sphere(pos=(x,y,z), radius = 0.25, color = visual.color.white)
ball.trail = visual.curve(color = visual.color.red)
while y > 0.0:
visual.rate(100)
t,x,y,z,vx,vy,vz = golfball_step(t,x,y,z,vx,vy,vz,m,g,B2,S0,w,dt,w_vector,v_vector)
x_list.append(x)
y_list.append(y)
z_list.append(z)
vx_list.append(vx)
vy_list.append(vy)
vz_list.append(vz)
t_list.append(t)
v_vector = visual.vector(vx,vy,vz)
ball.pos = (x,y,z)
ball.trail.append(pos=ball.pos)
return t_list,x_list,y_list,z_list,vx_list,vy_list,vz_list
示例5: main
def main(n):
pedestrians = generate_pedestrians(n)
aux = [False] * n * 4
minimizers = []
done = False
i = 0
draw(pedestrians)
for i, p in enumerate(pedestrians):
start, end, img = p
control = map(lambda p: p[0], pedestrians[:i] + pedestrians[i + 1:])
minimizers.append( (minimize(start, end, control), control) )
while not done:
for i, p in enumerate(pedestrians):
try:
rate(WIDTH / 5)
pedestrians[i] = (minimizers[i][0].next(), p[1], p[2])
draw(pedestrians)
for j, m in enumerate(minimizers):
minimizer, control = m
if j > i:
control[i] = pedestrians[i][0]
elif j < i:
control[-i] = pedestrians[i][0]
except StopIteration:
aux[i] = True
done = reduce(lambda x, y: x and y, aux)
示例6: solve_one
def solve_one(from_rod,to_rod):
moves = calc_hanoi_sequence(num_of_disks,from_rod,to_rod)
visual.rate(1.0)
for move in moves:
winsound.Beep(880,50)
g.animate_disk_move(disk=move.disk_to_move,to_rod=move.to_rod,to_z_order=state.num_of_disks_per_rod[move.to_rod])
state.move_disk_to_rod(disk=move.disk_to_move,to_rod=move.to_rod)
示例7: PlotSpheres3
def PlotSpheres3(f):
data = json.loads(open(f, "r").read())
scene = vs.display(title='3D representation',
x=0, y=0, width=1920, height=1080,
autocenter=True,background=(0,0,0))
vs.box(pos=(
(data["SystemSize"][1][0]+data["SystemSize"][0][0])*0.5,
(data["SystemSize"][1][1]+data["SystemSize"][0][1])*0.5,
(data["SystemSize"][1][2]+data["SystemSize"][0][2])*0.5
),
length=data["SystemSize"][1][0]-data["SystemSize"][0][0],
height=data["SystemSize"][1][1]-data["SystemSize"][0][1],
width= data["SystemSize"][1][2]-data["SystemSize"][0][2],
opacity=0.2,
color=vs.color.red)
spheres = [vs.sphere(radius=data["SphereSize"],pos=(data["Data"][0][i], data["Data"][1][i], data["Data"][2][i])) for i in range(data["SpheresNumber"])]
vs.arrow(pos=data["SystemSize"][0], axis=(1,0,0), shaftwidth=0.1, color=vs.color.red)
vs.arrow(pos=data["SystemSize"][0], axis=(0,1,0), shaftwidth=0.1, color=vs.color.green)
vs.arrow(pos=data["SystemSize"][0], axis=(0,0,1), shaftwidth=0.1, color=vs.color.blue)
while True:
vs.rate(60)
示例8: restricted_3body
def restricted_3body(y): # y = [r, v] expected
testbody = set_scene(y[0])
t, h = 0.0, 0.001
while True:
vp.rate(2000)
y = ode.RK4(r3body, y, t, h)
testbody.pos = y[0]
示例9: calculate
def calculate(x, y, z, vx, vy, vz, dt, m, g, B2, S0, omega):
""" Calculate the trajectory of a baseball including air resistance and spin by
repeatedly calling the do_time_step function. Also draw the trajectory using visual python. """
t = 0.0
# Establish lists with initial position and velocity components and time.
x_list = [x]
y_list = [y]
z_list = [z]
vx_list = [vx]
vy_list = [vy]
vz_list = [vz]
t_list = [t]
# Set up visual elements.
mound = visual.box(pos=(0,0,0), length=0.1, width=0.5, height=0.03, color=visual.color.white)
plate = visual.box(pos=(18,0,0), length=0.5, width=0.5, height=0.03, color=visual.color.white)
ball = visual.sphere(pos=(x,y,z), radius=0.05, color=visual.color.white)
ball.trail = visual.curve(color=ball.color)
while y >= 0.0:
visual.rate(100) # Limit to no more than 100 iterations per second.
t, x, y, z, vx, vy, vz = do_time_step(t, dt, x, y, z, vx, vy, vz, m, B2, g, S0, omega)
x_list.append(x)
y_list.append(y)
z_list.append(z)
vx_list.append(vx)
vy_list.append(vy)
vz_list.append(vz)
t_list.append(t)
ball.pos = (x,y,z)
ball.trail.append(pos=ball.pos)
return t_list, x_list, y_list, z_list, vx_list, vy_list, vz_list
示例10: _close_final
def _close_final(): # There is a window, or an activated display
global _do_loop
if _do_loop:
_do_loop = False # make sure we don't trigger this twice
while True: # at end of user program, wait for user to close the program
rate(1000)
_Interact()
_wx.Exit()
示例11: animate_motion_to_pos
def animate_motion_to_pos(self,shape,new_pos):
pos0 = shape.pos
pos1 = new_pos
num_steps = 10
for i in xrange(num_steps):
visual.rate(40)
x = (i-1)*1.0/(num_steps-1)
shape.pos = tuple([pos0[i]*(1-x) + pos1[i]*x for i in range(3)])
示例12: vs_run
def vs_run(self, dt, tx):
'''Continuously evolve and update the visual simulation
with timestep dt and visual speed tx relative to real-time.'''
while True:
self.evolve(dt)
vs.rate(tx / dt)
self.vs_update()
示例13: get_next_mouseclick_coords
def get_next_mouseclick_coords(self):
visual.scene.mouse.events = 0
while True:
visual.rate(30)
if visual.scene.mouse.clicked:
pick = visual.scene.mouse.getclick().pick
if pick.__class__ == visual.box:
return pick.board_pos
示例14: main
def main():
if len(argv) < 3:
raise Exception('>>> ERROR! Please supply values for black hole mass [>= 1.0] and spin [0.0 - 1.0] <<<')
m = float(argv[1])
a = float(argv[2])
horizon = m * (1.0 + sqrt(1.0 - a * a))
cauchy = m * (1.0 - sqrt(1.0 - a * a))
# set up the scene
scene.center = (0.0, 0.0, 0.0)
scene.width = scene.height = 1024
scene.range = (20.0, 20.0, 20.0)
inner = 2.0 * sqrt(cauchy**2 + a**2)
ellipsoid(pos = scene.center, length = inner, height = inner, width = 2.0 * cauchy, color = color.blue, opacity = 0.4) # Inner Horizon
outer = 2.0 * sqrt(horizon**2 + a**2)
ellipsoid(pos = scene.center, length = outer, height = outer, width = 2.0 * horizon, color = color.blue, opacity = 0.3) # Outer Horizon
ergo = 2.0 * sqrt(4.0 + a**2)
ellipsoid(pos = scene.center, length = ergo, height = ergo, width = 2.0 * horizon, color = color.gray(0.7), opacity = 0.2) # Ergosphere
if fabs(a) > 0.0:
ring(pos=scene.center, axis=(0, 0, 1), radius = a, color = color.white, thickness=0.01) # Singularity
else:
sphere(pos=scene.center, radius = 0.05, color = color.white) # Singularity
ring(pos=scene.center, axis=(0, 0, 1), radius = sqrt(isco(a)**2 + a**2), color = color.magenta, thickness=0.01) # ISCO
curve(pos=[(0.0, 0.0, -15.0), (0.0, 0.0, 15.0)], color = color.gray(0.7))
#cone(pos=(0,0,12), axis=(0,0,-12), radius=12.0 * tan(0.15 * pi), opacity=0.2)
#cone(pos=(0,0,-12), axis=(0,0,12), radius=12.0 * tan(0.15 * pi), opacity=0.2)
#sphere(pos=(0,0,0), radius=3.0, opacity=0.2)
#sphere(pos=(0,0,0), radius=12.0, opacity=0.1)
# animate!
ball = sphere() # Particle
counter = 0
dataLine = stdin.readline()
while dataLine: # build raw data arrays
rate(60)
if counter % 1000 == 0:
ball.visible = False
ball = sphere(radius = 0.2) # Particle
ball.trail = curve(size = 1) # trail
data = loads(dataLine)
e = float(data['v4e'])
if e < -120.0:
ball.color = color.green
elif e < -90.0:
ball.color = color.cyan
elif e < -60.0:
ball.color = color.yellow
elif e < -30.0:
ball.color = color.orange
else:
ball.color = color.red
r = float(data['r'])
th = float(data['th'])
ph = float(data['ph'])
ra = sqrt(r**2 + a**2)
sth = sin(th)
ball.pos = (ra * sth * cos(ph), ra * sth * sin(ph), r * cos(th))
ball.trail.append(pos = ball.pos, color = ball.color)
counter += 1
dataLine = stdin.readline()
示例15: advance
def advance(self):
self.x = self.x + self.direction[0]
self.y = self.y + self.direction[1]
dx = 1.0 * self.direction[0] / self.frames_per_move
dy = 1.0 * self.direction[1] / self.frames_per_move
for i in range(self.frames_per_move):
visual.rate(self.framerate)
self.rat.x = self.rat.x + dx
self.rat.y = self.rat.y + dy