예제 #1
0
    def draw_a_layer(self, layer, polylist=None, title=None):
        from vpython import canvas, vector, curve, color, sphere

        scene = canvas(title=title,
                       width=800,
                       height=800,
                       center=vector(self.shape[0] / 2, self.shape[1] / 2,
                                     self.shape[2] / 2),
                       background=color.white)
        self.draw_box()
        nums = self.get_num_of_polymers()
        for i in range(nums):
            chain = self.get_polymer(i)

            c = curve(color=color.yellow, radius=0.1)
            if chain:
                point2 = chain.get_list()["chain"][0].copy()['position']

                type = chain.get_list()["chain"][0].copy()["type"]
                if type == 1:
                    this_color = color.yellow
                elif type == 2:
                    # continue
                    this_color = color.blue
                elif type == 3:
                    continue
                    this_color = color.red

                c = curve(color=this_color, radius=0.1)
            else:
                continue

            for pointinfo in chain.get_list()["chain"]:
                point = pointinfo['position']
                type = pointinfo["type"]
                if type == 1:
                    this_color = color.yellow
                elif type == 2:
                    # continue
                    this_color = color.blue
                elif type == 3:
                    continue
                    this_color = color.red
                if point[0] != layer:
                    continue
                else:
                    sphere(pos=vector(point[0], point[1], point[2]),
                           color=this_color,
                           radius=0.2)
                    if (self.if_out_of_range(point2, point)):
                        pass
                    else:
                        c = curve(color=this_color, radius=0.1)

                    c.append(vector(point[0], point[1], point[2]))

                    point2 = point.copy()
        return scene
예제 #2
0
    def __init__(self, scene, colour=None):

        # Save the scene the grid is placed in
        self.__scene = scene
        self.__is_3d = True

        self.__relative_cam = True
        self.__num_squares = 10
        self.__scale = 1

        # Save the current camera settings
        self.camera_pos = self.__scene.camera.pos
        self.camera_axes = self.__scene.camera.axis
        self.__focal_point = [
            round(self.__scene.center.x),
            round(self.__scene.center.y),
            round(self.__scene.center.z)
        ]

        if colour is None:
            colour = [0, 0, 0]
        self._colour = colour

        # Initialise a grid object
        line_thickness = min(max(self.__scale / 25, 0.01), 5)  # 0.01 -> 5

        self.grid_object = GridMMap({
            'xy_plane':
            curve(vector(0, 0, 0),
                  color=vector(self._colour[0], self._colour[1],
                               self._colour[2]),
                  radius=line_thickness,
                  origin=vector(0, 0, 0)),
            'xz_plane':
            curve(vector(0, 0, 0),
                  color=vector(self._colour[0], self._colour[1],
                               self._colour[2]),
                  radius=line_thickness,
                  origin=vector(0, 0, 0)),
            'yz_plane':
            curve(vector(0, 0, 0),
                  color=vector(self._colour[0], self._colour[1],
                               self._colour[2]),
                  radius=line_thickness,
                  origin=vector(0, 0, 0)),
            'labels': [],
        })
        self.__init_grid()

        # Bind mouse releases to the update_grid function
        self.__scene.bind('mouseup keyup', self.update_grid)
예제 #3
0
def representer(xs, ys, name, clock, orienter):
    escena = vpython.canvas(width=1200, height=600)
    escena.title = name
    escena.background = vpython.color.cyan

    pos = vpython.vector(xs[0], 2, -ys[0])
    escena.range = 100
    escena.center = vpython.vector(0, 0, 0)
    escena.forward = vpython.vector(1, -2, 1)
    #suelo = vpython.box(pos = vpython.vector(0,-1,0),size=vpython.vector(10,0.01,200),color=vpython.color.white)
    suelo = vpython.box(pos=vpython.vector(250, -1, 0),
                        size=vpython.vector(500, 0.01, 200),
                        color=vpython.color.white,
                        texture=vpython.textures.wood)
    vehicle = vpython.box(pos=pos,
                          color=vpython.color.red,
                          size=vpython.vector(8, 4, 6))
    trayectoria = vpython.curve(color=vpython.color.yellow)
    road = vpython.curve(color=vpython.color.black)
    muro = vpython.box(pos=vpython.vector(0, 20, 10),
                       color=vpython.color.blue,
                       size=vpython.vector(20, 40.99, 2),
                       texture=vpython.textures.stucco)
    piedra1 = vpython.sphere(pos=vpython.vector(150, -1, -ys[150]),
                             color=vpython.color.black,
                             radius=1)
    piedra2 = vpython.sphere(pos=vpython.vector(xs[400], -1, -ys[400]),
                             color=vpython.color.black,
                             radius=1)
    time.sleep(clock)
    #escena.range = 45
    escena.range = 20
    for i in range(len(xs)):
        if i > 0:
            vehicle.rotate(axis=vpython.vector(0, 1, 0),
                           angle=-orienter[i - 1])
        pos = vpython.vector(xs[i], 2, -ys[i])
        #suelo.pos=vpython.vector(i/2.0,-1,0)
        #suelo.size = vpython.vector(i,0.01,200)

        muro.pos = vpython.vector(i / 2, 20, 10)
        muro.size = vpython.vector(i, 40.99, 2)

        vehicle.pos = pos
        escena.center = vpython.vector(xs[i], 5, -ys[i])
        trayectoria.append(pos)
        vehicle.rotate(axis=vpython.vector(0, -1, 0), angle=-orienter[i])
        road.append(vpython.vector(i, 2, 0))
        vpython.rate(40)
예제 #4
0
 def penDown(self):
     self.isDrawing = True
     # Start a new curve when we restart drawing
     keys = ['pos', 'color', 'radius']
     values = [self.position, self.currentColor, self.width]
     new_pos = dict(zip(keys, values))
     self.c = curve(new_pos)
예제 #5
0
파일: camera.py 프로젝트: Nabiz/PoolGame
 def __init__(self, cue_ball_pos, scene):
     self.scene = scene
     self.camera = scene.camera
     self.cue_ball_pos = cue_ball_pos
     self.fi = pi
     self.c = curve(color=color.red, radius=5)
     self.set_aim_camera()
예제 #6
0
def normalize():
    """
    Normalize the wavefunction.
    """
    asum = 0
    for i in range(0, n):
        if i > im:
            ul[i] = ur[n-i-1]
            asum = asum+ul[i]*ul[i]
    asum = np.sqrt(h*asum)
    evp.label = vp.label(pos=(700, 500), text="e=", box=0, display=psigr)
    evp.label.text = "e=%10.8f" %e
    ivp.label = vp.label(pos=(700, 400), text="istep=", box=0, display=psigr)
    ivp.label. text = "istep=%4s" %istep
    proten.pos = [(-1500,,200), (-1000,200), (-1000, -200), (0, -200), (0, 200), (1000,200)]
    autoen.pos = [(-1000,e*400000+200), (0, e*400000+200)]
    vp.label(pos=(-1150, -240), text=".001", box=0, display=energr)
    vp.label(pos=(-1000, 300), text="0", box=0, display=energr)
    vp.label(pos=(-900, 180), text="-500", box=0, display=energr)
    vp.label(pos=(-100, 180), text="500", box=0, display=energr)
    vp.label(pos=(-500, 180), text="0", box=0, display=energr)
    vp.label(pos=(900, 120), text="r", box=0, display=energr)

    j = 0
    for i in range(0, n, m):
        xl = xl0 + i*h
        ul[i] = ul[i]/asum
        psi.x[j] = xl - 500
        psi.y[j] = 10000.0*ul[i]
        line = vp.curve(pos=[(-830, -500), (-830, 500)], color=color.red, display=psigr)
        psio.x[j] = xl - 500
        psio.y[j] = 1e5*ul[i]**2
        j += 1
예제 #7
0
 def __init__(self, n, state, center, color, radius=1.0):
     self.n = n
     self.state = state
     self.center = center
     self.color = color
     self.radius = radius 
     
     self.vsphere = vpython.sphere(pos=vpython.vector(*self.center),\
                                   radius=self.radius,\
                                   color=self.color,\
                                   opacity=0.4)
     
     self.eigenvalues, self.eigenvectors = self.state.eigenstates()
     self.vstars = [vpython.sphere(pos=self.vsphere.pos+\
                                       self.radius*vpython.vector(*state_xyz(self.eigenvectors[i], self.n)),\
                                   radius=self.radius*0.1,\
                                   color=vpython.color.hsv_to_rgb(vpython.vector(sigmoid(self.eigenvalues[i]),1,1)),\
                                   opacity=0.3)\
                                       for i in range(len(self.eigenvectors))]
     self.varrows = [vpython.curve(pos=[self.vsphere.pos,\
                                        self.vstars[i].pos],\
                                   color=self.color)\
                                        for i in range(len(self.eigenvectors))]
     self.other = None
     self.local_other = None
예제 #8
0
    def __init__(self, ):
        self.cav = vp.canvas()
        self.cav.camera.rotate(angle=vp.radians(180), axis=self.cav.up)
        self.cav.camera.rotate(angle=vp.radians(180), axis=self.cav.forward)
        joints_radius = 10
        joints_color = vpvec([1, 1, 1])
        joints_opacity = 0.8
        line_color = vp.color.cyan
        line_radius = 5

        self.joints = [
            vp.sphere(
                canvas=self.cav,
                pos=vpvec([0, 0, 0]),
                radius=joints_radius * 0.9,
                color=joints_color,
                opacity=joints_opacity,
            ) for i in range(21)
        ]
        self.jointline = {
            c: vp.curve(
                canvas=self.cav,
                pos=[vpvec([0, 0, 0]), vpvec([0, 0, 0])],
                color=line_color,
                radius=line_radius,
            )
            for c in connections
        }
예제 #9
0
 def __init__(self, x, y, z, netcolor=vec(1, 1, 1), thick=.05):
     self.m, self.n = len(x[:, 0]), len(y[0, :])  # nx, ny points
     self.net = [
         vp.curve(color=netcolor, radius=thick)
         for i in range(self.m + self.n)
     ]
     self.move(x, y, z)
예제 #10
0
def render(pop, params):

    v_scene = params["width"] * params["height"] * params["depth"]
    r = math.floor(
        ((3 * v_scene) / (100 * 4 * 3.14 * params["nb_cities"]))**(1 / 3))
    t = r / 5

    scene = vpython.scene
    scene.center = vpython.vector(params["width"] // 2, params["height"] // 2,
                                  params["depth"] // 2)
    scene.width = params["width"]
    scene.height = params["height"]

    for city in pop.pts_list:
        vpython.sphere(pos=vpython.vector(*city),
                       radius=r,
                       color=vpython.color.green)

    pop.evolve()
    path = pop.best_individu.path
    p = vpython.curve(pos=path, radius=t)

    while True:
        vpython.rate(10)
        pop.evolve()
        path = pop.best_individu.path
        p.clear()
        p.append(path)
예제 #11
0
    def __init__(self,
                 color=vpython.color.white,
                 n_fiber_points=50,
                 parent=None):
        self.color = color
        self.n_fiber_points = n_fiber_points
        self.parent = parent

        self.state = Variable()  # 2x2 Density Matrix
        self.vector = Variable()  # spacetime 4-vector
        self.angles = Variable()  # 3 angles of 3-sphere

        self.state.tie(self.vector, qubit_to_vector)
        self.vector.tie(self.state, vector_to_qubit)
        self.vector.tie(self.angles, vector_to_angles)
        self.angles.tie(self.vector, angles_to_vector)

        self.vbase = vpython.sphere(color=self.color,\
                                    radius=0.1*self.parent.radius,\
                                    opacity=0.7,\
                                    emissive=True)
        self.varrow = vpython.arrow(pos=vpython.vector(0,0,0),\
                                    color=self.color,\
                                    shaftwidth = 0.06)
        self.vfiber = vpython.curve(pos=[vpython.vector(0,0,0) for i in range(self.n_fiber_points)],\
                                    color=self.color)
예제 #12
0
    def new_draw_box(self, point1, point2, box_color='blue'):
        from vpython import canvas, vector, curve, color
        # def into_vector(a):
        #     return vector(a[0], a[1], a[2])
        # print("draw a box")
        p1 = [0, 0, 0]
        p2 = [0, 0, 0]
        radius = 0.04
        if box_color == 'blue':
            box_color = color.black
        if box_color == 'red':
            box_color = color.red
        for a in range(2):
            for b in range(2):
                for c in range(3):
                    p1[c], p2[c] = point1[c], point2[c]

                    p1[(c + 1) % 3] = point1[(c + 1) %
                                             3] if a == 0 else point2[(c + 1) %
                                                                      3]
                    p2[(c + 1) % 3] = point1[(c + 1) %
                                             3] if a == 0 else point2[(c + 1) %
                                                                      3]
                    p1[(c + 2) % 3] = point1[(c + 2) %
                                             3] if b == 0 else point2[(c + 2) %
                                                                      3]
                    p2[(c + 2) % 3] = point1[(c + 2) %
                                             3] if b == 0 else point2[(c + 2) %
                                                                      3]
                    c = curve(vector(p1[0], p1[1], p1[2]),
                              vector(p2[0], p2[1], p2[2]),
                              color=box_color,
                              radius=radius)
예제 #13
0
def axes(frame, colour, sz, posn):  # Make axes visible (of world or frame).
    # Use None for world.
    directions = [
        vs.vector(sz, 0, 0),
        vs.vector(0, sz, 0),
        vs.vector(0, 0, sz)
    ]
    texts = ["X", "Y", "Z"]
    posn = vs.vector(posn)
    for i in range(3):  # EACH DIRECTION
        vs.curve(frame=frame, color=colour, pos=[posn, posn + directions[i]])
        vs.label(frame=frame,
                 color=colour,
                 text=texts[i],
                 pos=posn + directions[i],
                 opacity=0,
                 box=False)
예제 #14
0
 def pushCurve(self):
     self.curveStack.insert(0, self.c)
     self.widthStack.insert(0, self.width)
     self.colorStack.insert(0, self.currentColor)
     # start new curve
     keys = ['pos', 'color', 'radius']
     values = [self.position, self.currentColor, self.width]
     new_pos = dict(zip(keys, values))
     self.c = curve(new_pos)
예제 #15
0
def recreate():
    global n_qubits
    global state
    global energy
    global unitary
    global qubits
    global qubit_colors
    global vsphere
    global vstars
    global vbases
    global varrows
    global vfibers
    global vspin
    state = qutip.rand_ket(2**n_qubits)
    energy = qutip.rand_herm(2**n_qubits)
    unitary = qutip.Qobj(
        scipy.linalg.expm(-2 * math.pi * im * energy.full() * dt))
    qubits = None
    qubit_colors = [
        vpython.vector(random.random(), random.random(), random.random())
        for i in range(n_qubits)
    ]
    vsphere.visible = False
    del vsphere
    vsphere = vpython.sphere(pos=vpython.vector(0,0,0),\
                             radius=1.0,\
                             color=vpython.color.blue,\
                             opacity=0.4)
    vspin.visible = False
    del vspin
    vspin = vpython.arrow(shaftwidth=0.01, headwidth=0.001, headlength=0.001)
    for vstar in vstars:
        vstar.visible = False
        del vstar
    vstars = [vpython.sphere(radius=0.05,\
                             color=vpython.color.white,\
                             opacity=0.8,\
                             emissive=True) for i in range((2**n_qubits)-1)]
    for vbase in vbases:
        vbase.visible = False
        del vbase
    vbases = [vpython.sphere(radius=0.1,\
                           color=qubit_colors[i],\
                           opacity=0.7,\
                           emissive=True,\
                           make_trail=False) for i in range(n_qubits)]
    for varrow in varrows:
        varrow.visible = False
        del varrow
    varrows = [vpython.arrow(color=qubit_colors[i]) for i in range(n_qubits)]
    for vfiber in vfibers:
        vfiber.visible = False
        del vfiber
    vfibers = [vpython.curve(pos=[vpython.vector(0,0,0) for i in range(n_points)],\
                             color=qubit_colors[i]) for i in range(n_qubits)]
예제 #16
0
def create_bodies():
    star = vp.sphere(pos=vp.vector(0, 0, 0),
                     radius=1,
                     trail=vp.curve(),
                     vel=vp.vector(0, 0, 0),
                     mass=1000)

    satellite1 = vp.sphere(pos=vp.vector(10, -5, 0),
                           radius=0.5,
                           color=vp.color.green,
                           trail=vp.curve(),
                           vel=vp.vector(0, 6, 0),
                           mass=1.0)

    satellite2 = vp.sphere(pos=vp.vector(-8, -2, 0),
                           radius=0.5,
                           color=vp.color.red,
                           trail=vp.curve(),
                           vel=vp.vector(3, -9, 0),
                           mass=5.0)

    return [star, satellite1, satellite2]
예제 #17
0
    def _init_anim(self):
        import vpython as vp

        # Convert to float for VPython
        Lr = float(self.domain_param['Lr'])
        Lp = float(self.domain_param['Lp'])

        # Init render objects on first call
        self._anim['canvas'] = vp.canvas(width=800,
                                         height=600,
                                         title="Quanser Qube")
        scene_range = 0.2
        arm_radius = 0.003
        pole_radius = 0.0045
        self._anim['canvas'].background = vp.color.white
        self._anim['canvas'].lights = []
        vp.distant_light(direction=vp.vec(0.2, 0.2, 0.5), color=vp.color.white)
        self._anim['canvas'].up = vp.vec(0, 0, 1)
        self._anim['canvas'].range = scene_range
        self._anim['canvas'].center = vp.vec(0.04, 0, 0)
        self._anim['canvas'].forward = vp.vec(-2, 1.2, -1)
        vp.box(pos=vp.vec(0, 0, -0.07),
               length=0.09,
               width=0.1,
               height=0.09,
               color=vp.color.gray(0.5))
        vp.cylinder(axis=vp.vec(0, 0, -1),
                    radius=0.005,
                    length=0.03,
                    color=vp.color.gray(0.5))
        # Joints
        self._anim['joint1'] = vp.sphere(radius=0.005, color=vp.color.white)
        self._anim['joint2'] = vp.sphere(radius=pole_radius,
                                         color=vp.color.white)
        # Arm
        self._anim['arm'] = vp.cylinder(radius=arm_radius,
                                        length=Lr,
                                        color=vp.color.blue)
        # Pole
        self._anim['pole'] = vp.cylinder(radius=pole_radius,
                                         length=Lp,
                                         color=vp.color.red)
        # Curve
        self._anim['curve'] = vp.curve(color=vp.color.white,
                                       radius=0.0005,
                                       retain=2000)
예제 #18
0
def renderstick(positions):
    '''Draws the stick figure in 3D

    Input
      positions: 2d array of joint positions.
    '''
    vp.scene.caption = """Right button drag or Ctrl-drag to rotate "camera" to view scene.
    To zoom, drag with middle button or Alt/Option depressed, or use scroll wheel.
        On a two-button mouse, middle is left + right.
    Shift-drag to pan left/right and up/down.
    Touch screen: pinch/extend to zoom, swipe or two-finger rotate."""
    vp.scene.width = 800
    vp.scene.height = 600
    avpos = np.average(positions, axis=0)
    pos = positions - np.tile(avpos, (15, 1))
    rarm = vp.curve(
        pos=[tovec(pos[3, :]),
             tovec(pos[7, :]),
             tovec(pos[11, :])], radius=1)
    shoulders = vp.curve(pos=[tovec(pos[3, :]), tovec(pos[4, :])], radius=1)
    larm = vp.curve(
        pos=[tovec(pos[4, :]),
             tovec(pos[8, :]),
             tovec(pos[12, :])], radius=1)
    spine = vp.curve(pos=[tovec(pos[0, :]), tovec(pos[2, :])], radius=1)
    hips = vp.curve(pos=[tovec(pos[5, :]), tovec(pos[6, :])], radius=1)
    rleg = vp.curve(
        pos=[tovec(pos[5, :]),
             tovec(pos[9, :]),
             tovec(pos[13, :])], radius=1)
    lleg = vp.curve(
        pos=[tovec(pos[6, :]),
             tovec(pos[10, :]),
             tovec(pos[14, :])], radius=1)

    head = vp.sphere(pos=tovec(pos[0, :]), radius=3.)
    rshoulder = vp.sphere(pos=tovec(pos[3, :]),
                          radius=2.,
                          color=vp.color.orange)
    lshoulder = vp.sphere(pos=tovec(pos[4, :]),
                          radius=2.,
                          color=vp.color.orange)
    rhip = vp.sphere(pos=tovec(pos[5, :]), radius=2., color=vp.color.orange)
    lhip = vp.sphere(pos=tovec(pos[6, :]), radius=2., color=vp.color.orange)
    relbow = vp.sphere(pos=tovec(pos[7, :]), radius=2., color=vp.color.orange)
    lelbow = vp.sphere(pos=tovec(pos[8, :]), radius=2., color=vp.color.orange)
    rknee = vp.sphere(pos=tovec(pos[9, :]), radius=2., color=vp.color.orange)
    lknee = vp.sphere(pos=tovec(pos[10, :]), radius=2., color=vp.color.orange)
예제 #19
0
def representer(grid,path_way,clock,landmarks):
    z =len(grid)*10
    x=len(grid[0])*10
    escena = vpython.canvas(width=1200,height=600)
    escena.title = "Path Finder usando el algoritmo A*"
    escena.background = vpython.color.cyan
    escena.center = vpython.vector(x/2,-1,z/2)
    #escena.forward= vpython.vector(1,-1,0.2)
    escena.forward= vpython.vector(0,-2,-1)
    
    #ejex= vpython.curve(color=vpython.color.blue)
    #ejey=vpython.curve(color=vpython.color.red)
    #ejez=vpython.curve(color=vpython.color.green)
    #vpython.userzoom = True
    #for i in range(x):
    #    pos_x = vpython.vector(i,0,0)
    #    ejex.append(pos_x)
    #    pos_y = vpython.vector(0,i,0)
    #    ejey.append(pos_y)
    #    pos_z=vpython.vector(0,0,i)
    #    ejez.append(pos_z)
    
    suelo = vpython.box(pos=vpython.vector(x/2,-1,z/2),color=vpython.color.yellow,size=vpython.vector(x,0.1,z),texture=vpython.textures.rough)
    high_wall = 20 
    for i in range(len(landmarks)):
        z_wall=(landmarks[i][0]*10)+5
        x_wall=(landmarks[i][1]*10)+5
        muro = vpython.box(pos=vpython.vector(x_wall,10,z_wall),color=vpython.color.white,size=vpython.vector(10,high_wall,10),texture=vpython.textures.wood)
        
    robot = vpython.sphere(pos=vpython.vector(path_way[0][1]+5,3,path_way[0][0]+5),color=vpython.color.black,radius=3)
    trayectoria = vpython.curve(color=vpython.color.white)
    inicio =vpython.text(text="Inicio",align='center',color=vpython.color.green,pos=vpython.vector(5,22,5),height=5,width=12)
    meta = vpython.text(text="Meta",align='center',color=vpython.color.green,pos=vpython.vector((path_way[-1][1]*10)+5,22,(path_way[-1][0]*10)+5),height=5,width=12)
    time.sleep(clock)
    escena.range=150
    for i in range(len(path_way)):
        #escena.center = vpython.vector((path_way[i][1]*10)+5,-100,(path_way[i][0]*10)+5-20)
        escena.center = vpython.vector((path_way[i][1]*10)+5,4,(path_way[i][0]*10)+5)
        #time.sleep(0.3)
        time.sleep(0.1)
        pos = vpython.vector((path_way[i][1]*10)+5,3,(path_way[i][0]*10)+5)
        robot.pos = pos
        trayectoria.append(pos)
        #vpython.rate(100)
        vpython.rate(300)
예제 #20
0
    def __init__(self, state, field, n_fiber_points=50, emissive=False):
        self.state = state
        self.field = field

        self.n_fiber_points = n_fiber_points
        self.emissive = emissive
        self.color = vpython.vector(random.random(), random.random(),
                                    random.random())

        self.varrow = vpython.arrow(pos=vpython.vector(0,0,0),\
                                    color=self.color,\
                                    shaftwidth=0.05,\
                                    emissive=self.emissive)
        self.vbase = vpython.sphere(color=self.color,\
                                    radius=0.1,\
                                    opacity=0.7,\
                                    emissive=self.emissive)
        self.vfiber = vpython.curve(pos=[vpython.vector(0,0,0) for i in range(self.n_fiber_points)],\
                                    color=self.color,\
                                    emissive=self.emissive)
예제 #21
0
def init_bodies():
    sun = vpython.sphere(
        color=vpython.color.yellow,
        pos=vpython.vector(0, 0, 0),
        radius=0.1 * AU,
    )
    sun.mass = 1 * M_SUN
    sun.v = vpython.vector(0, 0, 0)
    earth = vpython.sphere(
        color=vpython.color.green,
        pos=vpython.vector(1 * AU, 0, 0),
        radius=0.02 * AU,
    )
    earth.mass = 1 * M_EARTH
    earth.v = V_EARTH * vpython.vector(0, 1, 0) * 0.8
    earth.path = vpython.curve(
        pos=earth.pos,
        color=vpython.color.white,
    )
    return sun, earth
예제 #22
0
 def __init__(self,
              pos=vector(0, 0, 0),
              heading=vector(0, 1, 0),
              leftDirection=vector(-1, 0, 0),
              upDirection=vector(0, 0, 1),
              width=1):
     self.position = pos
     self.heading = heading
     self.leftDirection = leftDirection
     self.upDirection = upDirection
     self.isDrawing = True
     self.curveStack = []
     self.widthStack = []
     self.colorStack = []
     self.listOfVectors = []
     self.width = width
     self.polygon = False
     self.currentColor = vector(151 / 255, 75 / 255, 0)
     keys = ['pos', 'color', 'radius']
     values = [self.position, self.currentColor, self.width]
     self.c = curve(dict(zip(keys, values)))
예제 #23
0
def genAtomView(listpost,
                listradius,
                listcolor=None,
                listbounds=None,
                boundcolor=vp.color.red):
    """
    Generate a Vpython view of a set of particles
    :param listpost: a numpy array with particles position np.array([x,y,z])
    :param listradius: a numpy array with particles radius
    :param listcolor: optional list of particles colors
    :return: vpython object of list of spheres view
    """
    # validations
    assert (type(listpost) == type(ar)), "first argument is not a numpy array"
    assert (
        type(listradius) == type(ar)), "second argument is not a numpy array"
    assert (listpost.shape[0] == listradius.size
            ), "number of position and radious differ "
    # If all is ok then make spheres view
    n = listpost.shape[0]
    listsphere = []
    defacolor = vp.color.white
    for i in range(n):
        if listcolor is not None:
            defacolor = listcolor[i]
        sph = vp.sphere(pos=NpAtoVv(listpost[i]),
                        radius=listradius[i],
                        color=defacolor)
        listsphere.append(sph)
    bx = []
    if listbounds is not None:
        for bt in listbounds:
            bx.append(
                vp.curve(NpAtoVv(listpost[bt[0]]),
                         NpAtoVv(listpost[bt[1]]),
                         color=boundcolor))

    return listsphere, bx
예제 #24
0
파일: ellipse.py 프로젝트: heyredhat/stars
	def __init__(self):
		self.state = qt.rand_ket(2)
		self.energy = qt.rand_herm(2)
		self.dt = 0.01

		self.vrod = vp.arrow(color=vp.color.red,\
							 pos=vp.vector(0,0,0),\
							 axis=vp.vector(0,0,1))
		self.vsphere = vp.sphere(color=vp.color.blue,\
								 radius=1.0,\
								 opacity=0.4)
		self.vstar = vp.sphere(pos=vp.vector(*self.spin_axis()),\
							   color=vp.color.white,\
							   radius=0.1,\
							   emissive=True) 
		self.ellipse = self.state_to_ellipse()
		self.vellipse = vp.curve(pos=self.ellipse_points(*self.ellipse))
		vp.scene.bind('keydown', self.keyboard)

		self.lit = -1
		self.evolving = True
		self.touched = False
		self.done = False
예제 #25
0
    def __init__(self):
        self._visible = False

        # There are two cases that we care about for a 2-body orbit, elliptical
        # or hyperbolic. Make a graphic for either case.
        self._ring = vpython.ring(axis=vpython.vector(0, 0, 1), visible=False)

        # Since vpython doesn't have a hyperbola primitive, we make one ourself
        # by generating a bunch of points along a hyperbola. Look at this graph
        # https://www.desmos.com/calculator/dbhsftzyjc
        # or put the following into wolframalpha.com
        # parametric graph sinh(t), cosh(t) from t = -asinh(1e2) to asinh(1e2)
        hyperbola_points: List[vpython.vector] = []
        start_t = -math.asinh(self.POINTS_IN_HYPERBOLA)
        for i in range(0, self.POINTS_IN_HYPERBOLA + 1):
            t = start_t + abs(start_t) * 2 * i / self.POINTS_IN_HYPERBOLA
            hyperbola_points.append(
                vpython.vector(math.sinh(t), math.cosh(t), 0))

        self._hyperbola = vpython.curve(hyperbola_points,
                                        axis=vpython.vector(1, 1, 0),
                                        up=vpython.vec(-1, 0, 0))
        self._hyperbola.visible = False
예제 #26
0
    def __init__(self,
                 color=vpython.color.white,
                 n_fiber_points=100,
                 parent=None,
                 gauged=False):
        self.color = color
        self.n_fiber_points = n_fiber_points
        self.parent = parent
        self.gauged = gauged

        self.state = Variable()  # 2x2 Density Matrix
        self.vector = Variable()  # spacetime 4-vector
        self.angles = Variable()  # 3 angles of 3-sphere

        self.state.tie(self.vector, qubit_to_vector)
        self.vector.tie(self.state, vector_to_qubit)
        self.vector.tie(self.angles, vector_to_angles)
        self.angles.tie(self.vector, angles_to_vector)

        self.vbase = vpython.sphere(color=self.color,\
                                    radius=0.1,\
                                    opacity=0.7,\
                                    emissive=False)
        self.varrow = vpython.arrow(pos=vpython.vector(0,0,0),\
                                    color=self.color,\
                                    shaftwidth=0.03)
        self.vfiber = vpython.curve(pos=[vpython.vector(0,0,0) for i in range(self.n_fiber_points)],\
                                    color=self.color)
        if self.gauged:
            self.gauge_charge = 1
            self.gauge_field = Qubit(color=self.color,\
                                     n_fiber_points=self.n_fiber_points,\
                                     gauged=False)
            self.gauge_field.vbase.emissive = True
            self.gauge_field.vfiber.emissive = True
            self.gauge_field.state.plug(qutip.rand_herm(2))
            self.varrow.shaftwidth = 0.06
예제 #27
0
vec_j = vp.vector(0, 1, 0)
vec_k = vp.vector(0, 0, 1)

# Axis colours
x_axis_color = vp.color.red
y_axis_color = vp.color.cyan
z_axis_color = vp.color.green

# Axes Triad
x_axis = Arrow(vec_o, 'x', x_axis_color, vec_o)
y_axis = Arrow(vec_o, 'y', y_axis_color, vec_o)
z_axis = Arrow(vec_o, 'z', z_axis_color, vec_o)

# Axes
x_axis_line = vp.curve(x_axis.cone_tip,
                       3 * vec_i,
                       radius=0.01,
                       color=x_axis_color)
y_axis_line = vp.curve(y_axis.cone_tip,
                       3 * vec_j,
                       radius=0.01,
                       color=y_axis_color)
z_axis_line = vp.curve(z_axis.cone_tip,
                       3 * vec_k,
                       radius=0.01,
                       color=z_axis_color)

# Define vector A
vec_A = vp.vector(1, 2, 1)
pos_A = vp.vector(0.5, 0.5, 0.5)
col_A = vp.color.magenta
A = Arrow(vec_A, 'A(1, 2, 1)', col_A, pos_A)
예제 #28
0
 def __init__(self, x, y, z, linecolor=vec(1, 1, 1), thick=.05):
     self.line = vp.curve(color=linecolor, radius=thick)
     self.line.append(pos=np.column_stack((x, y, z)).tolist())
attach_trail(polline, radius=0.006, retain=70, pps=4, type='points')

for index in range(N):
    particella = sphere()
    particella.mass = 0.01
    particella.radius = 0.015
    particella.pos = vector.random()
    particella.velocity = vector.random()
    particella.color = color.orange
    particelle.append(particella)

# Disegna un cubo di lato 2d
d = 1  # semilato del cubo
r = 0.005
gray = color.gray(0.7)
boxbottom = curve(color=gray, radius=r)
boxbottom.append([
    vector(-d, -d, -d),
    vector(-d, -d, d),
    vector(d, -d, d),
    vector(d, -d, -d),
    vector(-d, -d, -d)
])
boxtop = curve(color=gray, radius=r)
boxtop.append([
    vector(-d, d, -d),
    vector(-d, d, d),
    vector(d, d, d),
    vector(d, d, -d),
    vector(-d, d, -d)
])
예제 #30
0
파일: vpmnb.py 프로젝트: com-py/compy
 def __init__(self, x, y, z, netcolor=vec(1,1,1), thick=.05):
     self.m, self.n = len(x[:,0]), len(y[0,:])   # nx, ny points
     self.net=[vp.curve(color=netcolor, radius=thick)
               for i in range(self.m + self.n)]
     self.move(x, y, z)
예제 #31
0
파일: vpmnb.py 프로젝트: com-py/compy
 def __init__(self, x, y, z, linecolor=vec(1,1,1), thick = .05):
     self.line = vp.curve(color=linecolor, radius=thick)
     self.line.append(pos = np.column_stack((x, y, z)).tolist())
예제 #32
0
    Rnew = R + dt*Vnew
    return Rnew, Vnew

# compute net force
def force(R, V, mass):
    return mass*G - 0.0*mass*V

# visualization stuff
#scene = vp.canvas(title='3D scene', center = vp.vector(0.0, 0.0, 0.0))
scene = vp.canvas(title='Parabolic motion')
scene.autoscale = True
ball = vp.sphere(pos=vp.vector(R0[0], R0[1], R0[2]), radius=0.01, color=vp.color.cyan) 
ball.velocity = vp.vector(V0[0], V0[1], V0[2])
vscale = 0.02
varr = vp.arrow(pos=ball.pos, axis=vscale*ball.velocity, color=vp.color.yellow)
ball.trail = vp.curve(color=ball.color)
ypos = vp.gcurve(color=vp.color.cyan, dot=True)
yvel = vp.gcurve(color=vp.color.red, dot=True)

# initial conditions
Y = np.zeros(NSTEPS); VY = np.zeros(NSTEPS) # To save only Y coordinates, as function of time
Y[0] = R0[1]; VY[0] = V0[1]
R = R0; V = V0 ; F = force(R, V, MASS) # Value which changes at each time step
V = start_integration(V, F, MASS, DT) # Move Velocity from 0 to -dt/2

# main evolution loop
it = 1
while it < NSTEPS:
    F = force(R, V, MASS)
    R, V = integration(R, V, F, MASS, DT)
    Y[it] = R[1]; VY[it] = V[1]