示例#1
0
文件: bounce.py 项目: B-Rich/mayavi
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
示例#2
0
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 start_animation(self):
     self.animator = visual.iterate(240, self.animate)
     visual.show()
     return self.animator
示例#4
0
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)
frame2.axis = (0.0, -1.0, 0.0)
frame2.rotate(axis = (0,0,1), angle = 180.0*theta2/pi)

dt = 0.001

def anim():
    global theta1, theta2, theta1dot, theta2dot
    atheta1 = ((E*C/B)*sin(theta1)-F*sin(theta2))/(D-E*A/B)
    atheta2 = -(A*atheta1+C*sin(theta1))/B

    theta1dot = theta1dot + atheta1*dt
    theta2dot = theta2dot + atheta2*dt

    dtheta1 = theta1dot*dt
    dtheta2 = theta2dot*dt
    theta1 = theta1 + dtheta1
    theta2 = theta2 + dtheta2

    frame1.rotate(axis = (0,0,1), angle = 180.0*dtheta1/pi)

    frame2.pos = top + frame1.axis*L1
    frame2.rotate(axis = (0,0,1), angle = 180*dtheta2/pi)

a = iterate(20, anim)
a.edit_traits()
show()
示例#5
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) )


#ITERACION DEL SISTEMA
def anim():
    #Evolucion de la bola 1
    bola1.t = bola1.t + bola1.dt
    i = bola1.t
    bola1.pos = visual.vector(x1_t[i], y1_t[i], r1)

    #Evolucion de la bola 2
    bola2.t = bola2.t + bola2.dt
    i = bola2.t
    bola2.pos = visual.vector(x2_t[i], y2_t[i], r2)

    #Evolucion de la bola 3
    bola3.t = bola3.t + bola3.dt
    i = bola3.t
    bola3.pos = visual.vector(x3_t[i], y3_t[i], r3)


a = visual.iterate(10, anim)
visual.show()
 def start_animation(self):
     a = visual.iterate(20, self.anim)
     visual.show()
     return a
示例#7
0
from 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:
        lorenz.extend(pts)
        pts[:] = []

show()
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) )


#ITERACION DEL SISTEMA
def anim(): 
    #Evolucion de la bola 1
    bola1.t = bola1.t + bola1.dt
    i = bola1.t
    bola1.pos = visual.vector( x1_t[i], y1_t[i], r1 )
    
    #Evolucion de la bola 2
    bola2.t = bola2.t + bola2.dt
    i = bola2.t
    bola2.pos = visual.vector( x2_t[i], y2_t[i], r2 )
    
    #Evolucion de la bola 3
    bola3.t = bola3.t + bola3.dt
    i = bola3.t
    bola3.pos = visual.vector( x3_t[i], y3_t[i], r3 )

a = visual.iterate(10, anim)
visual.show()
示例#9
0
def main():
    dt = 0.1

    x = arange(-50,50)
    wpoints1 = zeros((100,3), float)
    wpoints2 = zeros((100,3), float)
    wpoints3 = zeros((100,3), float)
    wpoints4 = zeros((100,3), float)

    for i in range (0,100,1):
        wpoints1[i] = [x[i], -30, 0]
        wpoints2[i] = [x[i], -15, 0]
        wpoints3[i] = [x[i], 0, 0]
        wpoints4[i] = [x[i], 15, 0]

    band1 = Curve(points = wpoints1, k = 6.0, color = (1,0,0),
                  mass = 2.0, radius = 0.5, momentum = zeros((100, 3), float))

    band2 = Curve(points = wpoints2, k = 6.0, color = (1,1,0),
                  mass = 2.0, radius = 0.5, momentum = zeros((100, 3), float))

    band3 = Curve(points = wpoints3, k = 6.0, color = (0,1,0),
                  mass = 2.0, radius = 0.5, momentum = zeros((100, 3), float))

    band4 = Curve(points = wpoints4, k = 6.0, color = (0,0,1),
                  mass = 2.0, radius = 0.5, momentum = zeros((100, 3), float))

    for i in range(0,25,1):
        band1.momentum[i,1] = sin(x[i]*pi/25.0)*3   # half-wave pulse

    for i in range(0,25,1):
        band2.momentum[i,1] = sin(x[i]*2*pi/25.0)*5   # full-wave pulse

    for i in range(0,25,1):
        band3.momentum[i,0] = sin(x[i]*pi/25.0)*5   # compresion pulse

    for i in range(0,100,1):
        band4.momentum[i,1] = sin(x[i]*4*pi/100.0)*2   # standing wave

    def anim():
        band1.momentum[0] = band1.momentum[-1] = MVector(0,0,0)
        band2.momentum[0] = band2.momentum[-1] = MVector(0,0,0)
        band3.momentum[0] = band3.momentum[-1] = MVector(0,0,0)
        band4.momentum[0] = band4.momentum[-1] = MVector(0,0,0)

        band1.points = band1.points + (band1.momentum/band1.mass*dt)
        band2.points = band2.points + (band2.momentum/band2.mass*dt)
        band3.points = band3.points + (band3.momentum/band3.mass*dt)
        band4.points = band4.points + (band4.momentum/band4.mass*dt)

        force1 = band1.k * (band1.points[1:] - band1.points[:-1])
        force2 = band2.k * (band2.points[1:] - band2.points[:-1])
        force3 = band3.k * (band3.points[1:] - band3.points[:-1])
        force4 = band4.k * (band4.points[1:] - band4.points[:-1])

        band1.momentum[:-1] = band1.momentum[:-1] + force1 * dt
        band2.momentum[:-1] = band2.momentum[:-1] + force2 * dt
        band3.momentum[:-1] = band3.momentum[:-1] + force3 * dt
        band4.momentum[:-1] = band4.momentum[:-1] + force4 * dt

        band1.momentum[1:] = band1.momentum[1:] - force1 * dt
        band2.momentum[1:] = band2.momentum[1:] - force2 * dt
        band3.momentum[1:] = band3.momentum[1:] - force3 * dt
        band4.momentum[1:] = band4.momentum[1:] - force4 * dt

    a = iterate(20, anim)
    show()
    return a
示例#10
0
 def start_animation(self):
     a = visual.iterate(20, self.anim)
     visual.show()
     return a
 def start_animation(self):
     self.animator = visual.iterate(60, self.animate)
     visual.show()
     return self.animator