def go(): r = np.array([1.017, 0.0]) # initial x,y position for earth v = np.array([0.0, 6.179]) # initial vx, vy # draw the scene, planet earth/path, sun/sunlight scene = vp.display( title='Planetary motion', # scene start background=(.2, .5, 1), forward=(0, 2, -1)) planet = vp.sphere(pos=r, radius=0.1, make_trail=True, material=vp.materials.earth, up=(0, 0, 1)) sun = vp.sphere(pos=(0, 0), radius=0.2, color=vp.color.yellow, material=vp.materials.emissive) sunlight = vp.local_light(pos=(0, 0), color=vp.color.yellow) #scn end t, h = 0.0, 0.001 while True: vp.rate(200) # limit animation speed r, v = ode.leapfrog(earth, r, v, t, h) # integrate planet.pos = r # move planet if (scene.kb.keys): scene.kb.getkey(), scene.kb.getkey() #pause
def __init__(self, radius, **kwargs): self.container = visual.frame(**kwargs) self.ledsphere = visual.sphere( frame=self.container, pos=(0, 0, 0), radius=radius, color=visual.color.white, material=visual.materials.emissive ) self.ledlight = visual.local_light(frame=self.container, pos=(0, 0, 0), color=visual.color.white)
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
def __init__(self, body, pos, radius, color=vs.color.white, material=None, texture=None, makeTrail=True, rings=False): Agglomerate.__init__(self, body, pos, radius, vs.color.white, material, texture, makeTrail, rings) # TO DO: the color must be replaced through a function, which determines the color of the star out of its effective temperatur (black body) # In order to make the sun shine, we place light sources around it. distance = radius + 0.5 pos = (-distance, +distance) for x in pos: for y in pos: for z in pos: # debug # print("x={:2}, y={:2}, z={:2}".format(x, y, z)) vs.local_light(pos=(x, y, z), color=color)
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
def go(): r = np.array([1.017, 0.0]) # initial x,y position for earth v = np.array([0.0, 6.179]) # initial vx, vy # draw the scene, planet earth/path, sun/sunlight scene = vp.display(title='Planetary motion', # scene start background=(.2,.5,1), forward=(0,2,-1)) planet= vp.sphere(pos=r, radius=0.1, make_trail=True, material=vp.materials.earth, up=(0,0,1)) sun = vp.sphere(pos=(0,0), radius=0.2, color=vp.color.yellow, material=vp.materials.emissive) sunlight = vp.local_light(pos=(0,0), color=vp.color.yellow) #scn end t, h = 0.0, 0.001 while True: vp.rate(200) # limit animation speed r, v = ode.leapfrog(earth, r, v, t, h) # integrate planet.pos = r # move planet if (scene.kb.keys): scene.kb.getkey(), scene.kb.getkey() #pause
def go(): y = [1.0, 0.0, 0.0, ma.pi*1.8] # initial x,y and vx,vy # draw the scene, planet earth/path, sun/sunlight scene = vp.display(title='Planetary motion', background=(.2,.5,1), forward=(0,2,-1)) planet= vp.sphere(pos=(y[0],y[1]), radius=0.1, material=vp.materials.earth,up=(0,0,1)) path = vp.points(pos=(y[0],y[1]), size=2) sun = vp.sphere(pos=(0,0),radius=0.2,color=vp.color.yellow, material=vp.materials.emissive) sunlight = vp.local_light(pos=(0,0), color=vp.color.yellow) t, h = 0.0, 0.002 while True: vp.rate(200) # limit animation speed y = dansode.RK4n(earth, 4, y, t, h) # integrate t = t + h planet.pos=(y[0],y[1]) # move planet path.append(pos=(y[0],y[1])) # draw path
from __future__ import print_function, division import visual as vp print(__doc__) R = 3 A1 = A2 = A3 = 0.0 vp.arrow(pos=(0, 4, 0), axis=(0, 1, 0), color=vp.color.red) BOXY = vp.box(size=(3, 3, 3), color=(0.5, 0.5, 0.5), material=vp.materials.rough) B1 = vp.sphere(radius=0.3, pos=(R, 0, 0), color=vp.color.magenta, material=vp.materials.emissive) B2 = vp.sphere(radius=0.3, pos=(0, 0, R), color=vp.color.yellow, material=vp.materials.emissive) B3 = vp.arrow(radius=0.3, pos=(0, 0, R), color=vp.color.green, material=vp.materials.emissive) L1 = vp.local_light(pos=B1.pos, color=B1.color) L2 = vp.local_light(pos=B2.pos, color=B2.color) L3 = vp.distant_light(direction=B3.pos, color=B3.color) while True: vp.rate(100) L1.pos = B1.pos = R*vp.vector(vp.cos(A1), vp.sin(A1), B1.z) A1 += 0.02 L2.pos = B2.pos = (R+0.4)*vp.vector(B2.x, vp.sin(A2), vp.cos(A2)) A2 += 0.055 L3.direction = B3.pos = (R+3)*vp.vector(vp.sin(A3), B3.y, vp.cos(A3)) B3.axis = B3.pos * -0.3 A3 += 0.033
#Plot equipotential surfaces for a charged sphere. #Next to do: #Plot equipotential surfaces for two point charges placed at random locations. from visual import sphere, color, arrow, local_light, materials from math import sqrt, pi, cos, sin from const import E0 # E0 = 8.854187817e-12 If you are using glowscript you must define E0 and pi # If you use glowscript you have to modify this code slightly: # http://www.glowscript.org/docs/GlowScriptDocs/VPython-vs-GlowScript.html k = 1.0 / (4 * pi * E0) lamp = local_light(pos=(30, 30, 40), color=color.yellow) charge = sphere(pos=(0, 0, 0), radius=0.2, color=color.red, material=materials.shiny) surface = range(10) for j in surface: sphere(pos=(0, 0, 0), radius=0.4 + 0.1 * j, color=color.yellow, opacity=0.05, material=materials.diffuse)
vp.arrow(pos=(0, 4, 0), axis=(0, 1, 0), color=vp.color.red) BOXY = vp.box(size=(3, 3, 3), color=(0.5, 0.5, 0.5), material=vp.materials.rough) B1 = vp.sphere(radius=0.3, pos=(R, 0, 0), color=vp.color.magenta, material=vp.materials.emissive) B2 = vp.sphere(radius=0.3, pos=(0, 0, R), color=vp.color.yellow, material=vp.materials.emissive) B3 = vp.arrow(radius=0.3, pos=(0, 0, R), color=vp.color.green, material=vp.materials.emissive) L1 = vp.local_light(pos=B1.pos, color=B1.color) L2 = vp.local_light(pos=B2.pos, color=B2.color) L3 = vp.distant_light(direction=B3.pos, color=B3.color) while True: vp.rate(100) L1.pos = B1.pos = R * vp.vector(vp.cos(A1), vp.sin(A1), B1.z) A1 += 0.02 L2.pos = B2.pos = (R + 0.4) * vp.vector(B2.x, vp.sin(A2), vp.cos(A2)) A2 += 0.055 L3.direction = B3.pos = (R + 3) * vp.vector(vp.sin(A3), B3.y, vp.cos(A3)) B3.axis = B3.pos * -0.3 A3 += 0.033
USAGE: solar_system.py """ from __future__ import division, print_function from visual import sphere, color, rate, shapes, extrusion, local_light, scene, materials import numpy as np c1 = 1500 # Radius multiplier c2 = 50 # Rate # Create the sun sphere(pos=(0, 0, 0), radius=1e7, material=materials.emissive, color=color.yellow) # Make the sun the light source scene.lights = [] # Turn off the ambient lighting lamp = local_light(pos=(0, 0, 0), color=color.yellow) # Columns are: radius (km), orbital radius (km), and orbital period. planetData = np.array([[2.4400e3, 5.7900e7, 88.0], [6.0520e3, 1.0820e8, 224.7], [6.3710e3, 1.4960e8, 365.3], [3.3860e3, 2.2790e8, 687.0], [6.9173e4, 7.7850e8, 4331.6], [5.7316e4, 1.4334e9, 10759.2]], dtype=float) # RGB values for the planet colors colors = np.array([[0.59, 0.57, 0.50], [1.00, 1.00, 0.54], [0.38, 0.76, 0.97], [0.87, 0.45, 0.16], [1.00, 0.60, 0.00],
def build_keyboard(self): print 'Building Keyboard..' nts = ("C", "D", "E", "F", "G", "A", "B") tol = 0.12 keybsize = 16.5 #cm, span of one octave wb = keybsize / 7. nr_octaves = 7 span = nr_octaves * wb * 7. self.scene = vp.display(title='Piano Keyboard', x=0, y=0, width=1400. / 1., height=600. / 1., center=(75, 0, 0), forward=(0., -2, -1.), background=(0., 0.25, 0.0)) #wooden top and base vp.box(pos=(span / 2 + keybsize, -1., -3), length=span + 1, height=1, width=17, material=vp.materials.wood) vp.box(pos=(span / 2 + keybsize, 1, -8), length=span + 1, height=3, width=7, material=vp.materials.wood) text(pos=(28, 2.2, -8), string=version, width=2, height=2, up=(0, 0, -1), color=vp.color.orange, depth=0.3, justify='center') #leggio leggio = vp.box(pos=(75, 8., -12.), length=span / 2, height=span / 8, width=0.08, color=(1, 1, 0.9)) leggio.rotate(angle=-0.4) for ioct in range(nr_octaves): for ik in range(7): #white keys x = ik * wb + (ioct + 1.) * keybsize + wb / 2. tb = vp.box(pos=(x, 0., 0), length=wb - tol, height=1, width=10, up=(0, 1, 0), color=(1, 1, 1)) self.KB.update({nts[ik] + str(ioct + 1): tb}) if not nts[ik] in ("E", "B"): #black keys tn = vp.box(pos=(x + wb / 2, wb / 2, -2), length=wb * .6, height=1, width=6, up=(0, 1, 0), color=(0, 0, 0)) self.KB.update({nts[ik] + "#" + str(ioct + 1): tn}) self.scene.lights = [] vp.local_light(pos=(0, 100, 0), color=vp.color.white) #source1 vp.local_light(pos=(-10, -40, 20), color=vp.color.white) #source2