本文整理汇总了Python中visual.sphere函数的典型用法代码示例。如果您正苦于以下问题:Python sphere函数的具体用法?Python sphere怎么用?Python sphere使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sphere函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: show_ladybug
def show_ladybug(self, H=None):
'''Show Ladybug in Visual Python at origin or at the translated position
if parameter is given.
TODO: Implement an additional translation H and show at new position.'''
# vis.ellipsoid(width=0.12, length=0.08, height=0.08,
# color=vis.color.red, opacity=0.2)
vis.arrow(axis=(0.04, 0, 0), color=(1,0,0) )
vis.arrow(axis=(0, 0.04, 0), color=(0,1,0) )
vis.arrow(axis=(0, 0, 0.04), color=(0,0,1) )
colors = [vis.color.red, vis.color.green, vis.color.blue,
vis.color.cyan, vis.color.yellow, vis.color.magenta]
for P in self.LP:
R = P[:3,:3]
pos = dot(P[:3],r_[0,0,0,1])
pos2 = dot(P[:3],r_[0,0,0.01,1])
vis.sphere(pos=pos, radius=0.002, color=colors.pop(0))
vis.box(pos=pos2, axis=dot(R, r_[0,0,1]).flatten(),
size=(0.001,0.07,0.09), color=vis.color.red,
opacity=0.1)
vis.arrow(pos=pos,
axis=dot(R, r_[0.02,0,0]).flatten(),
color=(1,0,0), opacity=0.5 )
vis.arrow(pos=pos,
axis=dot(R, r_[0,0.02,0]).flatten(),
color=(0,1,0), opacity=0.5 )
vis.arrow(pos=pos,
axis=dot(R, r_[0,0,0.02]).flatten(),
color=(0,0,1), opacity=0.5 )
示例2: show_protective
def show_protective(nparticles):
# create scene
scene = visual.display(title='Protective zones', width=600, height=400, center=(0,0,0))
scene.select()
# read in positions, state and protective zones
positions = (numpy.genfromtxt('position.dat'))[:nparticles]
state = (numpy.genfromtxt('state.dat'))[:nparticles]
zones = (numpy.genfromtxt('fpt.dat'))[:nparticles]
# go through particles and display them
for i in range(nparticles):
# color the spheres according to state
cball = visual.color.green
if (state[i,0]==1):
cball = visual.color.red
else:
cball = visual.color.blue
if (state[i,3]==1):
cball = visual.color.yellow
if (state[i,3]==2):
cball = visual.color.orange
visual.sphere(pos=(positions[i,0], positions[i,1], positions[i,2]), radius=zones[i], color=cball)
visual.label(pos=(positions[i,0], positions[i,1], positions[i,2]), text='{0:d}'.format(i))
示例3: set_scene
def set_scene(r): # r = position of test body
vp.display(title='Restricted 3body', background=(1,1,1))
body = vp.sphere(pos=r, color=(0,0,1), radius=0.03, make_trail=1)
sun = vp.sphere(pos=(-a,0), color=(1,0,0), radius=0.1)
jupiter = vp.sphere(pos=(b, 0), color=(0,1,0), radius=0.05)
circle = vp.ring(pos=(0,0), color=(0,0,0), thickness=0.005,
axis=(0,0,1), radius=1) # unit circle
return body
示例4: sphere
def sphere():
from visual import sphere,color
L = 5
R = 0.3
for i in range(-L,L+1):
for j in range(-L,L+1):
for k in range(-L,L+1):
sphere(pos=[i,j,k],radius=R,color=color.blue)
示例5: draw_node_list
def draw_node_list(self, radius=2.0):
if self._nodes == None:
print "ERROR: you have to set/load node list before drawing them."
exit(1)
for i in range(1,len(self._nodes)):
x, y = self._nodes[i][0], self._nodes[i][1]
vs.sphere(display=self.route_window, pos=vs.vector(x,y,0),
radius=radius, color=vs.color.blue)
示例6: 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()
示例7: set_scene
def set_scene(R, r): # create bodies, velocity arrows
vp.display(title='Three-body motion', background=(1,1,1))
body, vel = [], [] # bodies, vel arrows
c = [(1,0,0), (0,1,0), (0,0,1), (0,0,0)] # RGB colors
for i in range(3):
body.append(vp.sphere(pos=r[i],radius=R,color=c[i],make_trail=1))
vel.append(vp.arrow(pos=body[i].pos,shaftwidth=R/2,color=c[i]))
line, com = vp.curve(color=c[3]), vp.sphere(pos=(0,0), radius=R/4.)
return body, vel, line
示例8: marks
def marks(self):
marks_list = []
new_time = self.time
while new_time >= 5:
marks_list.append(int(new_time))
new_time = new_time - 5.0
marks_list.append(int(0))
for marks in marks_list:
sphere(pos=(marks, marks * 1.1, 0), radius=0, label=str(marks) + " seconds")
示例9: __init__
def __init__(self, joint, num, length, height=LEGS_HEIGHT, width=LEGS_WIDTH):
"""
"""
super(Tars3D, self).__init__(joint, num, length, height, width, (0, 0, 1))
visual.cylinder(frame=self, pos=(0, 0, -(width+5)/2), radius=(height+1)/2, axis=(0, 0, 1), length=width+5, color=visual.color.cyan)
visual.box(frame=self, pos=((length-5)/2, 0, 0), length=length-5/2, height=height, width=width , color=visual.color.yellow)
visual.sphere(frame=self, pos=(length-5/2, 0, 0), radius=5)
self.rotate(angle=math.radians(180), axis=self._axis)
示例10: __init__
def __init__(self, color=None, *args, **kwargs):
""" Init CoordinatesSystem3D object
"""
super(CoordinatesSystem3D, self).__init__(*args, **kwargs)
if color is None:
visual.sphere(frame=self, radius=3, color=visual.color.gray(0.5))
visual.arrow(frame=self, axis=(1, 0, 0), length=30, color=visual.color.cyan)
visual.arrow(frame=self, axis=(0, 0, -1), length=30, color=visual.color.magenta)
visual.arrow(frame=self, axis=(0, 1, 0), length=30, color=visual.color.yellow)
示例11: create_color_cube
def create_color_cube():
visual.scene.range=(256,256,256)
visual.scene.center=(128,128,128)
color_dict,rgbs=color_list.read_colors()
for rgb in color_dict.values():
r=int(rgb[1:3],16)
g=int(rgb[3:5],16)
b=int(rgb[5:7],16)
pos=(r,g,b)
color=(r/255.0,g/255.0,b/255.0)
visual.sphere(pos=pos,radius=10,color=color)
示例12: create_cube
def create_cube():
visual.scene.range=(256,256,256)
visual.scene.center=(128,128,128)
t=range(0,256,51)
for x in t:
for y in t:
for z in t:
pos=x,y,z
color=(x/255.0,y/255.0,z/255.0)
visual.sphere(pos=pos,radius=10,color=color)
示例13: addSphere
def addSphere(self, sphere, colour=None, opacity=1., material=None):
"""docstring for addSphere"""
if not Visualiser.VISUALISER_ON:
return
if isinstance(sphere, geo.Sphere):
if colour == None:
colour = visual.color.red
if np.allclose(np.array(colour), np.array([0,0,0])):
visual.sphere(pos=sphere.centre, radius=sphere.radius, opacity=opacity, material=material)
else:
visual.sphere(pos=sphere.centre, radius=sphere.radius, color=geo.norm(colour), opacity=opacity, material=material)
示例14: PlotElevator
def PlotElevator(filename):
try:
f = open(filename,'r')
data = json.loads(f.read())
f.close()
except Exception as e:
return str(e)
print(data["L0"])
pos = []
for i in range(data["SavedSteps"]):
if not None in [elem for s1 in data["Position"][i] for elem in s1]:
pos.append(data["Position"][i])
else:
break
pos = array(pos)
vel = array(data["Velocity"])
scene = vs.display(title='3D representation', x=500, y=0, width=1920, height=1080, background=(0,0,0), center=pos[0][-1])
string = vs.curve(pos=pos[0], radius=50)
earth = vs.sphere(radius=R_earth_equator)
asteroid = vs.sphere(pos=pos[0][-1],radius=1e3, color=vs.color.red)
anchor = vs.sphere(pos=pos[0][0],radius=1e2, color=vs.color.green)
label_avg_l0 = vs.label(pos=pos[0][-1], text="t: %3.1f" % (data["Time"][0],))
body = 1
nt = 0
while True:
vs.rate(60)
if scene.kb.keys: # event waiting to be processed?
s = scene.kb.getkey() # get keyboard info
if s == "d":
if body == -1:
body = 0
elif body == 0:
body = 1
else:
body = -1
if body == 1:
scene.center = (0,0,0)
else:
scene.center = pos[nt][body]
string.pos=pos[nt]
asteroid.pos=pos[nt][-1]
anchor.pos=pos[nt][0]
label_avg_l0.pos = asteroid.pos
label_avg_l0.text = "t: %3.1f" % (data["Time"][nt],)
if nt + 1 >= pos.shape[0]:
nt = 0
else:
nt += 1
示例15: set_scene
def set_scene(r): # r = init position of planet
# draw scene, mercury, sun, info box, Runge-Lenz vector
scene = vp.display(title='Precession of Mercury',
center=(.1*0,0), background=(.2,.5,1))
planet= vp.sphere(pos=r, color=(.9,.6,.4), make_trail=True,
radius=0.05, material=vp.materials.diffuse)
sun = vp.sphere(pos=(0,0), color=vp.color.yellow,
radius=0.02, material=vp.materials.emissive)
sunlight = vp.local_light(pos=(0,0), color=vp.color.yellow)
info = vp.label(pos=(.3,-.4), text='Angle') # angle info
RLvec = vp.arrow(pos=(0,0), axis=(-1,0,0), length = 0.25)
return planet, info, RLvec