def random_box(): xx = randrange(-55,54) yy = randrange(-55,54) zz = randrange(-55,54) x = randrange(0,21) y = randrange(0,21) z = randrange(0,21) red = random() green = random() blue = random() box (pos = (xx,yy,zz), length=x, height=y, width=z, color=(red,green,blue))
def random_box(): xx = randrange(-55, 54) yy = randrange(-55, 54) zz = randrange(-55, 54) x = randrange(0, 21) y = randrange(0, 21) z = randrange(0, 21) red = random() green = random() blue = random() box(pos=(xx, yy, zz), length=x, height=y, width=z, color=(red, green, blue))
def main(): # Creating parameters for box size side = 4.0 thk = 0.3 s2 = 2 * side - thk s3 = 2 * side + thk # Creating the 6 walls wallR = box(pos=(side, 0, 0), size=(thk, s3, s2), color=(1, 0, 0)) wallL = box(pos=(-side, 0, 0), size=(thk, s3, s2), color=(1, 0, 0)) wallB = box(pos=(0, -side, 0), size=(s3, thk, s3), color=(0, 0, 1)) wallT = box(pos=(0, side, 0), size=(s3, thk, s3), color=(0, 0, 1)) wallBK = box(pos=(0, 0, -side), size=(s2, s2, thk), color=(0.7, 0.7, 0.7)) # Creating the ball ball = sphere(radius=0.4, color=(0, 1, 0)) ball.vector = vector(-0.15, -0.23, 0.27) side = side - thk * 0.5 - ball.radius ball.t = 0.0 ball.dt = 0.5 def anim(): #Creating the animation function which will be called at #uniform timeperiod through the iterate function ball.t = ball.t + ball.dt ball.pos = ball.pos + ball.vector * ball.dt if not (side > ball.x > -side): ball.vector.x = -ball.vector.x if not (side > ball.y > -side): ball.vector.y = -ball.vector.y if not (side > ball.z > -side): ball.vector.z = -ball.vector.z a = iterate(20, anim) show() return a
def main(): # Creating parameters for box size side = 4.0 thk = 0.3 s2 = 2 * side - thk s3 = 2 * side + thk # Creating the 6 walls wallR = box(pos=(side, 0, 0), size=(thk, s3, s2), color=(1, 0, 0)) wallL = box(pos=(-side, 0, 0), size=(thk, s3, s2), color=(1, 0, 0)) wallB = box(pos=(0, -side, 0), size=(s3, thk, s3), color=(0, 0, 1)) wallT = box(pos=(0, side, 0), size=(s3, thk, s3), color=(0, 0, 1)) wallBK = box(pos=(0, 0, -side), size=(s2, s2, thk), color=(0.7, 0.7, 0.7)) # Creating the ball ball = sphere(radius=0.4, color=(0, 1, 0)) ball.vector = vector(-0.15, -0.23, 0.27) side = side - thk * 0.5 - ball.radius ball.t = 0.0 ball.dt = 0.5 def anim(): # Creating the animation function which will be called at # uniform timeperiod through the iterate function ball.t = ball.t + ball.dt ball.pos = ball.pos + ball.vector * ball.dt if not (side > ball.x > -side): ball.vector.x = -ball.vector.x if not (side > ball.y > -side): ball.vector.y = -ball.vector.y if not (side > ball.z > -side): ball.vector.z = -ball.vector.z a = iterate(20, anim) show() return a
blue = random() box (pos = (xx,yy,zz), length=x, height=y, width=z, color=(red,green,blue)) def wirecube(s): c = curve(color = (1,1,1), radius=1) pts = [(-s, -s, -s),(-s, -s, s), (-s, s, s), (-s, s, -s), (-s, -s, -s), (s, -s, -s), (s, s, -s), (-s, s, -s), (s, s, -s), (s, s, s), (-s, s, s), (s, s, s), (s, -s, s), (-s, -s, s), (s, -s, s),(s, -s, -s)] for pt in pts: c.append(pt) side = 150.0 cube = box(size = (side,side,side), representation = 'w' ) i = 0 while i < 100: random_box() i = i + 1 arrow(axis=(0,12,0), radius_shaft=3.5, color = (1,0,0)) ball = sphere(pos=(-side/2.,-side/2.,-side/2.),color=(1,1,0),radius=3) disk = cylinder(pos=(side/2.,side/2.,-side/2.),color=(.3,.3,1),axis=(1,1,0),radius=5) xx = arange(0,4*pi,pi/10.) spring=curve(color=(1,.7,.1), radius=0.4) for y in xx: spring.append([20+cos(2*y), y/2.-30, -20+sin(2*y)+30]) show()
bola1.dt = 1 #Creando bola 2 bola2 = visual.sphere(radius=r2, color=(1.0, 1.0, 1.0)) bola2.pos = [0., 0., 0.] bola2.t = 0 bola2.dt = 1 #Creando bola 1 bola3 = visual.sphere(radius=r3, color=(1.0, 1.0, 1.0)) bola3.pos = [0., 0., 0.] bola3.t = 0 bola3.dt = 1 #Creando mesa mesa = visual.box( pos=(ancho/2., largo/2., -grosor/2.), \ size=(ancho, largo, grosor), color=(0.0, 0.3, 0.0) ) muro_l = visual.box( pos=(-grosor/2., largo/2., 0.0), \ size=(grosor, largo + 2*grosor, grosor), \ color=(0.6, 0.3, 0.0) ) muro_r = visual.box( pos=(ancho+grosor/2., largo/2., 0.0), \ size=(grosor, largo + 2*grosor, grosor), \ color=(0.6, 0.3, 0.0) ) muro_d = visual.box( pos=(ancho/2., -grosor/2., 0.0), \ size=(ancho + 2*grosor, grosor, grosor), \ color=(0.6, 0.3, 0.0) ) muro_u = visual.box( pos=(ancho/2., largo+grosor/2., 0.0), \ size=(ancho + 2*grosor, grosor, grosor), \ color=(0.6, 0.3, 0.0) )
# Initialize arguments try: v0 = float(sys.argv[1]) except: v0 = v0_default print 'Using default v0 =',v0,'m/s.' # Build 3d world # Define the line of sight sight = V.vector(math.cos(theta),math.sin(theta),0) # The floor is just a thin box #floor = V.box(pos=(D/2.,0,0), length=D, height=0.5, width=D, color=V.color.blue) floor = V.box(pos=(D/2.,0,0), length=D, height=0.5, width=D) # Use a cone for our 'arrow' #arrow = V.cone(pos=(0,0,0), radius=0.9, axis=sight,color=V.color.red) arrow = V.cone(pos=(0,0,0), radius=0.9, axis=sight) arrow.velocity = v0*sight # The target is a sphere #target = V.sphere(pos=(D,H,0), radius=1, color=V.color.yellow) target = V.sphere(pos=(D,H,0), radius=1) target.velocity = V.vector(0,0,0) # The 'dart gun' is just a cylinder. gun = V.cylinder(pos=(0,0,0), axis=gun_len*sight, radius=1, # color = V.color.green) )
E = (1./12.)*M2*L2**2+(1./4.)*M2*L2**2 F = g*L2*M2/2. hpedestal = 1.3*(L1+L2) # height of pedestal wpedestal = 0.1 # width of pedestal tbase = 0.05 # thickness of base wbase = 8.*gap # width of base offset = 2.*gap # from center of pedestal to center of U-shaped upper assembly top = vector(0,0,0) # top of inner bar of U-shaped upper assembly theta1 = 1.3*pi/2. # initial upper angle (from vertical) theta1dot = 0 # initial rate of change of theta1 theta2 = 0 # initial lower angle (from vertical) theta2dot = 0 # initial rate of change of theta2 pedestal = box(pos = (top - vector(0, hpedestal/2.0, offset)),size = (wpedestal, 1.1*hpedestal, wpedestal), color = (0.4,0.4,0.5)) base = box(pos = (top - vector(0,hpedestal + tbase/2.0, offset)),size=(wbase, tbase, wbase),color = (0.4,0.4,0.5)) bar1 = box(pos=(L1display/2.0 - d/2.0, 0, -(gap+d)/2.0), size=(L1display, d, d), color=(1,0,0)) bar1b = box(pos=(L1display/2.0 - d/2.0, 0, (gap+d)/2.0), size=(L1display, d, d), color=(1,0,0)) frame1 = frame(bar1, bar1b) frame1.pos = (0.0, 0.0, 0.0) frame1.axis = (0.0, -1.0, 0.0) frame1.rotate(axis=(0,0,1), angle = 180.0*theta1/pi) bar2 = box(pos = (L2display/2.0 - d/2.0, 0, 0), size = (L2display, d, d), color = (0,1,0)) frame2 = frame(bar2) frame2.pos = (0.0, -1.0*L1, 0.0)
g = 9.8 Fgrav = vector(0, -M * g, 0) top = vector(0, 0, 0) # top of pedestal theta = pi / 3. # initial polar angle of shaft (from vertical) thetadot = 0 # initial rate of change of polar angle alpha = 0 # initial spin angle alphadot = 15 # initial rate of change of spin angle (spin ang. velocity) phi = -pi / 2. # initial azimuthal angle phidot = 0 # initial rate of change of azimuthal angle # Comment in following line to get pure precession ##phidot = (-alphadot+sqrt(alphadot**2+2*M*g*r*cos(theta)/I))/cos(theta) pedestal = box(pos=top - vector(0, hpedestal / 2., 0), height=hpedestal, length=wpedestal, width=wpedestal, color=(0.4, 0.4, 0.5)) base = box(pos=top - vector(0, hpedestal + tbase / 2., 0), height=tbase, length=wbase, width=wbase, color=pedestal.color) shaft = cylinder(axis=(Lshaft, 0, 0), length=Lshaft, radius=Rshaft, color=(0, 1, 0)) rotor = cylinder(pos=(Lshaft / 2 - Drotor / 2, 0, 0), axis=(Drotor, 0, 0), length=Drotor,
#!/usr/bin/env python # Author: Raashid Baig <*****@*****.**> # License: BSD Style. from enthought.tvtk.tools.visual import curve, box, vector, show from numpy import arange, array lorenz = curve( color = (1,1,1), radius=0.3 ) # Draw grid for x in xrange(0,51,10): curve(points = [[x,0,-25],[x,0,25]], color = (0,0.5,0), radius = 0.3 ) box(pos=(x,0,0), axis=(0,0,50), height=0.4, width=0.4, length = 50) for z in xrange(-25,26,10): curve(points = [[0,0,z], [50,0,z]] , color = (0,0.5,0), radius = 0.3 ) box(pos=(25,0,z), axis=(50,0,0), height=0.4, width=0.4, length = 50) dt = 0.01 y = vector(35.0, -10.0, -7.0) pts = [] for i in xrange(2000): # Integrate a funny differential equation dydt = vector( -8.0/3*y[0] + y[1]*y[2], - 10*y[1] + 10*y[2], - y[1]*y[0] + 28*y[1] - y[2]) y = y + dydt * dt pts.append(y)
# Author: Prabhu Ramachandran <prabhu [at] aero.iitb.ac.in> # Copyright (c) 2009, Enthought, Inc. # License: BSD Style. from enthought.mayavi import mlab from enthought.tvtk.tools import visual # Create a figure f = mlab.figure(size=(500,500)) # Tell visual to use this as the viewer. visual.set_viewer(f) # A silly visualization. mlab.test_plot3d() # Even sillier animation. b1 = visual.box() b2 = visual.box(x=4., color=visual.color.red) b3 = visual.box(x=-4, color=visual.color.red) b1.v = 5.0 @mlab.show @mlab.animate(delay=250) def anim(): """Animate the b1 box.""" while 1: b1.x = b1.x + b1.v*0.1 if b1.x > 2.5 or b1.x < -2.5: b1.v = -b1.v yield # Run the animation.
wbase = 3.*wpedestal # width of base g = 9.8 Fgrav = vector(0,-M*g,0) top = vector(0,0,0) # top of pedestal theta = pi/3. # initial polar angle of shaft (from vertical) thetadot = 0 # initial rate of change of polar angle alpha = 0 # initial spin angle alphadot = 15 # initial rate of change of spin angle (spin ang. velocity) phi = -pi/2. # initial azimuthal angle phidot = 0 # initial rate of change of azimuthal angle # Comment in following line to get pure precession ##phidot = (-alphadot+sqrt(alphadot**2+2*M*g*r*cos(theta)/I))/cos(theta) pedestal = box(pos=top-vector(0,hpedestal/2.,0), height=hpedestal, length=wpedestal, width=wpedestal, color=(0.4,0.4,0.5)) base = box(pos=top-vector(0,hpedestal+tbase/2.,0), height=tbase, length=wbase, width=wbase, color=pedestal.color) shaft = cylinder(axis=(Lshaft,0,0), length = Lshaft, radius=Rshaft, color=(0,1,0)) rotor = cylinder(pos=(Lshaft/2 - Drotor/2, 0, 0), axis=(Drotor, 0, 0), length = Drotor, radius=Rrotor, color=(1,0,0)) gyro = frame(shaft, rotor) gyro.axis = (sin(theta)*sin(phi),cos(theta),sin(theta)*cos(phi)) trail = curve(radius=Rshaft/8., color=(1,1,0))
bola1.dt = 1 #Creando bola 2 bola2 = visual.sphere( radius=r2, color=(1.0, 1.0, 1.0) ) bola2.pos = [ 0., 0., 0. ] bola2.t = 0 bola2.dt = 1 #Creando bola 1 bola3 = visual.sphere( radius=r3, color=(1.0, 1.0, 1.0) ) bola3.pos = [ 0., 0., 0. ] bola3.t = 0 bola3.dt = 1 #Creando mesa mesa = visual.box( pos=(ancho/2., largo/2., -grosor/2.), \ size=(ancho, largo, grosor), color=(0.0, 0.3, 0.0) ) muro_l = visual.box( pos=(-grosor/2., largo/2., 0.0), \ size=(grosor, largo + 2*grosor, grosor), \ color=(0.6, 0.3, 0.0) ) muro_r = visual.box( pos=(ancho+grosor/2., largo/2., 0.0), \ size=(grosor, largo + 2*grosor, grosor), \ color=(0.6, 0.3, 0.0) ) muro_d = visual.box( pos=(ancho/2., -grosor/2., 0.0), \ size=(ancho + 2*grosor, grosor, grosor), \ color=(0.6, 0.3, 0.0) ) muro_u = visual.box( pos=(ancho/2., largo+grosor/2., 0.0), \ size=(ancho + 2*grosor, grosor, grosor), \ color=(0.6, 0.3, 0.0) )
cuerda3 = visual.curve( points=[(3,0,0), (3,-l3,0)], \ radius=0.02 ) #Creando pendulo 4 pendulo4 = visual.sphere( radius=radio, \ color=(1.0, 0.0, 0.0) ) pendulo4.pos = [4, -l4*np.cos(theta4_t[0]), \ l4*np.sin(theta4_t[0])] pendulo4.t = 0 pendulo4.dt = 1 cuerda4 = visual.curve( points=[(4,0,0), \ (4, -l4*np.cos(theta4_t[0]), l4*np.sin(theta4_t[0]))], \ radius=0.02 ) #Creando caja contenedora y cuerda de suspension muro1 = visual.box( pos=(0., -1., 0.), size=(0.3, 5, 1), \ color=(0.6, 0.3, 0.0) ) muro2 = visual.box( pos=(5., -1., 0.), size=(0.3, 5, 1), \ color=(0.6, 0.3, 0.0) ) visual.curve(points=[(0, 0, 0), (5, 0, 0)], radius=0.02) #ITERACION DEL SISTEMA def anim(): #Evolucion del pendulo 1 pendulo1.t = pendulo1.t + pendulo1.dt i = pendulo1.t pendulo1.pos = visual.vector( 1, \ -l1*np.cos(theta1_t[i]), l1*np.sin(theta1_t[i]) ) delta_thetha1 = theta1_t[i - 1] - theta1_t[i] cuerda1.rotate(180 * delta_thetha1 / np.pi, [1., 0., 0])
cuerda3 = visual.curve( points=[(3,0,0), (3,-l3,0)], \ radius=0.02 ) #Creando pendulo 4 pendulo4 = visual.sphere( radius=radio, \ color=(1.0, 0.0, 0.0) ) pendulo4.pos = [4, -l4*np.cos(theta4_t[0]), \ l4*np.sin(theta4_t[0])] pendulo4.t = 0 pendulo4.dt = 1 cuerda4 = visual.curve( points=[(4,0,0), \ (4, -l4*np.cos(theta4_t[0]), l4*np.sin(theta4_t[0]))], \ radius=0.02 ) #Creando caja contenedora y cuerda de suspension muro1 = visual.box( pos=(0., -1., 0.), size=(0.3, 5, 1), \ color=(0.6, 0.3, 0.0) ) muro2 = visual.box( pos=(5., -1., 0.), size=(0.3, 5, 1), \ color=(0.6, 0.3, 0.0) ) visual.curve( points=[(0,0,0), (5,0,0)], radius=0.02 ) #ITERACION DEL SISTEMA def anim(): #Evolucion del pendulo 1 pendulo1.t = pendulo1.t + pendulo1.dt i = pendulo1.t pendulo1.pos = visual.vector( 1, \ -l1*np.cos(theta1_t[i]), l1*np.sin(theta1_t[i]) ) delta_thetha1 = theta1_t[i-1] - theta1_t[i] cuerda1.rotate( 180*delta_thetha1/np.pi, [1.,0.,0] ) #Evolucion del pendulo 2
#!/usr/bin/env python # Author: Raashid Baig <*****@*****.**> # License: BSD Style. from enthought.tvtk.tools.visual import curve, box, vector, show from numpy import arange, array lorenz = curve(color=(1, 1, 1), radius=0.3) # Draw grid for x in xrange(0, 51, 10): curve(points=[[x, 0, -25], [x, 0, 25]], color=(0, 0.5, 0), radius=0.3) box(pos=(x, 0, 0), axis=(0, 0, 50), height=0.4, width=0.4, length=50) for z in xrange(-25, 26, 10): curve(points=[[0, 0, z], [50, 0, z]], color=(0, 0.5, 0), radius=0.3) box(pos=(25, 0, z), axis=(50, 0, 0), height=0.4, width=0.4, length=50) dt = 0.01 y = vector(35.0, -10.0, -7.0) pts = [] for i in xrange(2000): # Integrate a funny differential equation dydt = vector(-8.0 / 3 * y[0] + y[1] * y[2], -10 * y[1] + 10 * y[2], -y[1] * y[0] + 28 * y[1] - y[2]) y = y + dydt * dt pts.append(y) if len(pts) > 20:
width=z, color=(red, green, blue)) def wirecube(s): c = curve(color=(1, 1, 1), radius=1) pts = [(-s, -s, -s), (-s, -s, s), (-s, s, s), (-s, s, -s), (-s, -s, -s), (s, -s, -s), (s, s, -s), (-s, s, -s), (s, s, -s), (s, s, s), (-s, s, s), (s, s, s), (s, -s, s), (-s, -s, s), (s, -s, s), (s, -s, -s)] for pt in pts: c.append(pt) side = 150.0 cube = box(size=(side, side, side), representation='w') i = 0 while i < 100: random_box() i = i + 1 arrow(axis=(0, 12, 0), radius_shaft=3.5, color=(1, 0, 0)) ball = sphere(pos=(-side / 2., -side / 2., -side / 2.), color=(1, 1, 0), radius=3) disk = cylinder(pos=(side / 2., side / 2., -side / 2.), color=(.3, .3, 1), axis=(1, 1, 0), radius=5) xx = arange(0, 4 * pi, pi / 10.)
# Author: Prabhu Ramachandran <prabhu [at] aero.iitb.ac.in> # Copyright (c) 2009, Enthought, Inc. # License: BSD Style. from enthought.mayavi import mlab from enthought.tvtk.tools import visual # Create a figure f = mlab.figure(size=(500, 500)) # Tell visual to use this as the viewer. visual.set_viewer(f) # A silly visualization. mlab.test_plot3d() # Even sillier animation. b1 = visual.box() b2 = visual.box(x=4., color=visual.color.red) b3 = visual.box(x=-4, color=visual.color.red) b1.v = 5.0 @mlab.show @mlab.animate(delay=250) def anim(): """Animate the b1 box.""" while 1: b1.x = b1.x + b1.v * 0.1 if b1.x > 2.5 or b1.x < -2.5: b1.v = -b1.v yield