本文整理汇总了Python中visual.rate函数的典型用法代码示例。如果您正苦于以下问题:Python rate函数的具体用法?Python rate怎么用?Python rate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rate函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
开发者ID:askiba,项目名称:optimal-gigant,代码行数:33,代码来源:simulation.py
示例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
开发者ID:iamdafu,项目名称:adolphus,代码行数:30,代码来源:interface.py
示例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
开发者ID:Milias,项目名称:ModellingSimulation,代码行数:32,代码来源:graphs.py
示例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
开发者ID:jared-vanausdal,项目名称:computational,代码行数:30,代码来源:golfball.py
示例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)
开发者ID:LG95,项目名称:Path-planning-animation,代码行数:32,代码来源:pedestrians.py
示例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)
开发者ID:adilevin,项目名称:hanoy-python,代码行数:7,代码来源:hanoi.py
示例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)
开发者ID:Milias,项目名称:ModellingSimulation,代码行数:26,代码来源:graphs.py
示例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]
开发者ID:com-py,项目名称:compy,代码行数:7,代码来源:Program_4.7_r3body.py
示例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
开发者ID:jared-vanausdal,项目名称:computational,代码行数:33,代码来源:Ex2-4-3d.py
示例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()
开发者ID:galou,项目名称:drawbot,代码行数:8,代码来源:create_window.py
示例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)])
开发者ID:adilevin,项目名称:hanoy-python,代码行数:8,代码来源:hanoi.py
示例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()
开发者ID:xerebus,项目名称:ph22,代码行数:8,代码来源:multibody.py
示例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
开发者ID:nkhuyu,项目名称:htc2015,代码行数:8,代码来源:main.py
示例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()
开发者ID:m4r35n357,项目名称:BlackHole4DPython,代码行数:58,代码来源:plotBH.py
示例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
开发者ID:dc25,项目名称:puzzler,代码行数:9,代码来源:ratbot.py
示例16: simulate
def simulate(self):
# Do the simulation...
self.total_time = 0.0
self.dt = 0.04
self.stop = False
while not self.stop:
rate(self.dt*1000)
self.step()
self.total_time += self.dt
开发者ID:rafen,项目名称:quad-simulator,代码行数:9,代码来源:sim.py
示例17: draw_efield
def draw_efield(V, scale): # draw electric field
Ex, Ey = np.gradient(-V)
Emag = np.sqrt(Ex*Ex + Ey*Ey)
for i in range(2, M-1, 2):
for j in range(2, N-1, 2):
vp.arrow(pos=(i,j), axis=(Ex[i,j], Ey[i,j]),
length=Emag[i,j]*scale)
vp.rate(100)
return Ex, Ey
开发者ID:com-py,项目名称:compy,代码行数:9,代码来源:Program_7.2_laplace.py
示例18: interactiveLoop
def interactiveLoop(self):
while True:
visual.rate(50)
if visual.scene.kb.keys: # event waiting to be processed?
key = visual.scene.kb.getkey() # get keyboard info
if len(key) == 1:
if key == " ":
demo.refresh()
elif key == "a":
demo.adjustFrames = not demo.adjustFrames
demo.refresh()
elif key == "c":
demo.sampleCount = max(3, int(demo.sampleCount * self.sampleCountIncreaseFactor))
print "Curve sample count: " + str(demo.sampleCount)
demo.refresh()
elif key == "C":
demo.sampleCount = int(demo.sampleCount * (1 / self.sampleCountIncreaseFactor))
print "Curve sample count: " + str(demo.sampleCount)
demo.refresh()
elif key == "f":
demo.showFrames = not demo.showFrames
demo.refresh()
elif key == "n":
break
elif key == "p":
demo.printInfo()
elif key == "h" or key == "?":
demo.printHelp()
elif key == "r":
# select next curve from the list of example curves
# wrapping around the list
selectedCurveIndex = 0
try:
selectedCurveIndex = demo.exampleCurves.index(demo.curve)
except ValueError:
print "Warning: Cannot find current curve, using the first one instead."
selectedCurveIndex += 1
selectedCurveIndex %= len(demo.exampleCurves)
demo.curve = demo.exampleCurves[selectedCurveIndex]
demo.refresh()
elif key == "s":
demo.showSweepSurface = not demo.showSweepSurface
demo.refresh()
elif key == "t":
demo.twistCount += 1
print "Twist count: " + str(demo.twistCount)
demo.refresh()
elif key == "T":
demo.twistCount -= 1
print "Twist count: " + str(demo.twistCount)
demo.refresh()
elif key == "w":
demo.showWorldFrame = not demo.showWorldFrame
demo.refresh()
else:
if key == "f11":
self.toggleFullscreen()
开发者ID:bzamecnik,项目名称:gpg,代码行数:57,代码来源:rmf.py
示例19: main
def main(n):
origin = (0, 0)
goal = (WIDTH, LENGTH)
obstacles = generate_obstacles(n)
# heatmap(obstacles)
for intermediate in minimize(origin, goal, obstacles):
rate(LENGTH / 10)
origin = animate(origin, intermediate)
开发者ID:LG95,项目名称:Path-planning-animation,代码行数:9,代码来源:obstacles.py
示例20: animate_motion
def animate_motion(x, k):
# Animate using Visual-Python
CO = zeros((n, 3))
B2 = zeros((n, 3))
C1 = zeros((n, 3))
C3 = zeros((n, 3))
CN = zeros((n, 3))
for i, state in enumerate(x[:,:5]):
CO[i], B2[i], C1[i], C3[i] = rd.anim(state, r)
# Make the out of plane axis shorter since this is what control the height
# of the cone
B2[i] *= 0.001
C1[i] *= r
C3[i] *= r
CN[i, 0] = state[3]
CN[i, 1] = state[4]
from visual import display, rate, arrow, curve, cone, box
black = (0,0,0)
red = (1, 0, 0)
green = (0, 1, 0)
blue = (0, 0, 1)
white = (1, 1, 1)
NO = (0,0,0)
scene = display(title='Rolling disc @ %0.2f realtime'%k, width=800,
height=800, up=(0,0,-1), uniform=1, background=white, forward=(1,0,0))
# Inertial reference frame arrows
N = [arrow(pos=NO,axis=(.001,0,0),color=red),
arrow(pos=NO,axis=(0,.001,0),color=green),
arrow(pos=NO,axis=(0,0,.001),color=blue)]
# Two cones are used to look like a thin disc
body1 = cone(pos=CO[0], axis=B2[0], radius=r, color=blue)
body2 = cone(pos=CO[0], axis=-B2[0], radius=r, color=blue)
# Body fixed coordinates in plane of disc, can't really be seen through cones
c1 = arrow(pos=CO[0],axis=C1[0],length=r,color=red)
c3 = arrow(pos=CO[0],axis=C3[0],length=r,color=green)
trail = curve()
trail.append(pos=CN[0], color=black)
i = 1
while i<n:
rate(k/ts)
body1.pos = CO[i]
body1.axis = B2[i]
body2.pos = CO[i]
body2.axis = -B2[i]
c1.pos = body1.pos
c3.pos = body1.pos
c1.axis = C1[i]
c3.axis = C3[i]
c1.up = C3[i]
c3.up = C1[i]
trail.append(pos=CN[i])
i += 1
开发者ID:certik,项目名称:pydy,代码行数:54,代码来源:plot_rollingdisc.py
注:本文中的visual.rate函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论