Пример #1
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
Пример #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
Пример #3
0
    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()
Пример #4
0
#!/usr/bin/env python
"""A simple example demonstrating the creation of actors and animating
the in a scene using visual modeule."""
# Author: Raashid Baig <*****@*****.**>
# License: BSD Style.

from math import sqrt

from enthought.tvtk.tools.visual import sphere, iterate, show, vector, curve

#Creating the actors for the scene
giant = sphere(pos=(-1.0e11, 0, 0), radius=2e10, color=(1, 0, 0), mass=2e30)

dwarf = sphere(pos=(1.5e11, 0, 0), radius=1e10, color=(1, 1, 0), mass=1e30)

giant.p = vector(0, 0, -1e4) * giant.mass
dwarf.p = -1 * giant.p

# creating the curve which will trace the paths of actors
for a in [giant, dwarf]:
    a.orbit = curve(radius=2e9, color=a.color)

dt = 86400


def anim():
    #Creating the animation function which will be called at
    #uniform timeperiod through the iterate function
    dist = dwarf.pos - giant.pos
    force = 6.7e-11 * giant.mass * dwarf.mass * \
        dist/(sqrt(dist[0]**2 + dist[1]**2 + dist[2]**2))**3
Пример #5
0
#!/usr/bin/env python
"""A simple example demonstrating the creation of actors and animating
the in a scene using visual modeule."""
# Author: Raashid Baig <*****@*****.**>
# License: BSD Style.

from math import sqrt

from enthought.tvtk.tools.visual import sphere, iterate, show, vector, curve

#Creating the actors for the scene
giant = sphere(pos=(-1.0e11, 0, 0),
               radius=2e10,
               color=(1, 0, 0),
               mass=2e30)

dwarf = sphere(pos=(1.5e11, 0, 0),
               radius=1e10,
               color=(1, 1, 0),
               mass=1e30)

giant.p = vector(0, 0, -1e4) * giant.mass
dwarf.p = -1*giant.p

# creating the curve which will trace the paths of actors
for a in [giant, dwarf]:
    a.orbit = curve(radius=2e9, color=a.color)

dt = 86400

def anim():
Пример #6
0
                if i == j:
                    self.score_matrix[(i,j)] = 0
                elif j == i+1 or j == i-1:
                    self.score_matrix[(i,j)] = 0
                else:
                    self.score_matrix[(i,j)] = 1  ## fix it to actually score: 0 if distance > 1; otherwise use score dict
        print self.score_matrix
        self.score = np.sum(self.score_matrix)
                

class Peptide:
    def __init__(self):
        self.seq = []
    def addAA(self,aa):
        self.seq.append(aa)
    def index(self,aa):
        return self.seq.index(aa)
        

class AA:
    def __init__(self,HorP):
        self.name = HorP
        
s = visual.sphere()
t = visual.sphere()
s.color = (0.0,0.5,1.0)
t.axis = (10,10,10)

s.edit_traits()
##visual.show()
Пример #7
0
#CONSTANTES
#Ancho de la mesa
ancho = 1.2
#Largo de la mesa
largo = 2.4
#Grosor de los muros del billar
grosor = 0.1
#Radio bola 1
r1 = 0.05
#Radio bola 2
r2 = 0.05
#Radio bola 3
r3 = 0.05

#Creando bola 1
bola1 = visual.sphere(radius=r1, color=(1.0, 1.0, 1.0))
bola1.pos = [0., 0., 0.]
bola1.t = 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
Пример #8
0
# 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)
                 )

# Run simulation

print 'Starting simulation...'

# Put a little delay to give all the OpenGL stuff time to initialize nicely.
#time.sleep(1)

while (arrow.y >= 0 and target.y >=0) and \
Пример #9
0
    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()
Пример #10
0
#CONSTANTES
#Ancho de la mesa
ancho = 1.2
#Largo de la mesa
largo = 2.4
#Grosor de los muros del billar
grosor = 0.1
#Radio bola 1
r1 = 0.05
#Radio bola 2
r2 = 0.05
#Radio bola 3
r3 = 0.05

#Creando bola 1
bola1 = visual.sphere( radius=r1, color=(1.0, 1.0, 1.0) )
bola1.pos = [ 0., 0., 0. ]
bola1.t = 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
Пример #11
0
#Gravedad
g = 9.8
#Longitud pendulo 1
l1 = 1.0
#Longitud pendulo 2
l2 = 2.0
#Longitud pendulo 3
l3 = 3.0
#Longitud pendulo 4
l4 = 2.0
#Radio de cada esfera
radio = 0.2

#Creando pendulo 1
pendulo1 = visual.sphere( radius=radio, \
color=(0.0, 0.0, 1.0) )
pendulo1.pos = [1, -l1, 0]
pendulo1.t = 0
pendulo1.dt = 1
cuerda1 = visual.curve( points=[(1,0,0), (1,-l1,0)], \
radius=0.02 )

#Creando pendulo 2
pendulo2 = visual.sphere( radius=radio, \
color=(0.0, 0.0, 1.0) )
pendulo2.pos = [2, -l2, 0]
pendulo2.t = 0
pendulo2.dt = 1
cuerda2 = visual.curve( points=[(2,0,0), (2,-l2,0)], \
radius=0.02 )
#Gravedad
g = 9.8
#Longitud pendulo 1
l1 = 1.0
#Longitud pendulo 2
l2 = 2.0
#Longitud pendulo 3
l3 = 3.0
#Longitud pendulo 4
l4 = 2.0
#Radio de cada esfera
radio = 0.2

#Creando pendulo 1
pendulo1 = visual.sphere( radius=radio, \
color=(0.0, 0.0, 1.0) )
pendulo1.pos = [ 1, -l1, 0 ]
pendulo1.t = 0
pendulo1.dt = 1
cuerda1 = visual.curve( points=[(1,0,0), (1,-l1,0)], \
radius=0.02 )

#Creando pendulo 2
pendulo2 = visual.sphere( radius=radio, \
color=(0.0, 0.0, 1.0) )
pendulo2.pos = [ 2, -l2, 0 ]
pendulo2.t = 0
pendulo2.dt = 1
cuerda2 = visual.curve( points=[(2,0,0), (2,-l2,0)], \
radius=0.02 )