Exemple #1
0
def PlotSphereEvolution3(f):
  data = json.loads(open(f, "r").read())

  center = (
    (data["SystemSize"][1][0]+data["SystemSize"][0][0])*0.5,
    (data["SystemSize"][1][1]+data["SystemSize"][0][1])*0.5,
    (data["SystemSize"][1][2]+data["SystemSize"][0][2])*0.5
  )

  scene = vs.display(title='3D representation',
    x=0, y=0, width=1920, height=1080,
    center=center,background=(0,0,0)
  )

  vs.box(pos=center,
  length=data["SystemSize"][1][0]-data["SystemSize"][0][0],
  height=data["SystemSize"][1][1]-data["SystemSize"][0][1],
  width= data["SystemSize"][1][2]-data["SystemSize"][0][2],
  opacity=0.2,
  color=vs.color.red)

  spheres = [vs.sphere(radius=data["SphereSize"],pos=(data["Data"][0][0][i], data["Data"][1][0][i], data["Data"][2][0][i])) for i in range(data["SpheresNumber"])]

  nt = 0
  while True:
    vs.rate(60)
    for i in range(data["SpheresNumber"]):
      spheres[i].pos = (data["Data"][0][nt][i], data["Data"][1][nt][i], data["Data"][2][nt][i])
    if nt + 1 >= data["SavedSteps"]:
      nt = 0
    else:
      nt += 1
def calculate(x, y, z, vx, vy, vz, dt, m, g, B2, S0, omega):
    """ Calculate the trajectory of a baseball including air resistance and spin by
repeatedly calling the do_time_step function.  Also draw the trajectory using visual python. """
    t = 0.0
    # Establish lists with initial position and velocity components and time.
    x_list = [x]
    y_list = [y]
    z_list = [z]
    vx_list = [vx]
    vy_list = [vy]
    vz_list = [vz]
    t_list = [t]

    # Set up visual elements.
    mound = visual.box(pos=(0,0,0), length=0.1, width=0.5, height=0.03, color=visual.color.white)
    plate = visual.box(pos=(18,0,0), length=0.5, width=0.5, height=0.03, color=visual.color.white)
    ball = visual.sphere(pos=(x,y,z), radius=0.05, color=visual.color.white)
    ball.trail = visual.curve(color=ball.color)

    while y >= 0.0:
        visual.rate(100) # Limit to no more than 100 iterations per second.
        t, x, y, z, vx, vy, vz = do_time_step(t, dt, x, y, z, vx, vy, vz, m, B2, g, S0, omega)
        x_list.append(x)
        y_list.append(y)
        z_list.append(z)
        vx_list.append(vx)
        vy_list.append(vy)
        vz_list.append(vz)
        t_list.append(t)
        ball.pos = (x,y,z)
        ball.trail.append(pos=ball.pos)

    return t_list, x_list, y_list, z_list, vx_list, vy_list, vz_list
Exemple #3
0
def PlotSpheres3(f):
  data = json.loads(open(f, "r").read())

  scene = vs.display(title='3D representation',
    x=0, y=0, width=1920, height=1080,
    autocenter=True,background=(0,0,0))

  vs.box(pos=(
    (data["SystemSize"][1][0]+data["SystemSize"][0][0])*0.5,
    (data["SystemSize"][1][1]+data["SystemSize"][0][1])*0.5,
    (data["SystemSize"][1][2]+data["SystemSize"][0][2])*0.5
  ),
  length=data["SystemSize"][1][0]-data["SystemSize"][0][0],
  height=data["SystemSize"][1][1]-data["SystemSize"][0][1],
  width= data["SystemSize"][1][2]-data["SystemSize"][0][2],
  opacity=0.2,
  color=vs.color.red)

  spheres = [vs.sphere(radius=data["SphereSize"],pos=(data["Data"][0][i], data["Data"][1][i], data["Data"][2][i])) for i in range(data["SpheresNumber"])]

  vs.arrow(pos=data["SystemSize"][0], axis=(1,0,0), shaftwidth=0.1, color=vs.color.red)
  vs.arrow(pos=data["SystemSize"][0], axis=(0,1,0), shaftwidth=0.1, color=vs.color.green)
  vs.arrow(pos=data["SystemSize"][0], axis=(0,0,1), shaftwidth=0.1, color=vs.color.blue)

  while True:
    vs.rate(60)
Exemple #4
0
	def __init__(self, room_=1, beam_axis_=0, target_pos_=(0,0,0)):
		self.labScene = visual.display(title="7Be(d,n)8B Experiment", width=800, height=600, background=GetRGBcode(153,204,255))
		axisx = visual.box(pos=(0,0,0), axis=(10.0,0,0), width=0.05, height=0.05, color=visual.color.red)
		axisy = visual.box(pos=(0,0,0), axis=(0,10.0,0), width=0.05, height=0.05, color=visual.color.blue)
		axisz = visual.box(pos=(0,0,0), axis=(0,0,10.0), width=0.05, height=0.05, color=visual.color.green)
		labelx = visual.label(pos=(5.0,0,0), text="Z-Axis")
		labely = visual.label(pos=(0,5.0,0), text="Y-Axis")
		labelz = visual.label(pos=(0,0,5.0), text="X-Axis")
		self.labScene.center = target_pos_
		self.labScene.autoscale = False
		
		self.room = room_
		self.beam_axis = beam_axis_
		self.target_pos = target_pos_
		
		self.Floors = []
		self.Walls = []
		self.Columns = []
		self.Others = []		

		self.BuildRoom()

		if(self.room == 1 or self.room == 2):
			chamber_radius = 0.25
			self.Beamline1 = visual.cylinder(pos=Translate(self.target_pos,GetCartesianCoords(chamber_radius, math.pi/2.0, DegToRad(180+self.beam_axis))), axis=ConvIM3(71.75,0,-71.75*math.tan(DegToRad(180-self.beam_axis))), radius=ConvIM(1.75), color=visual.color.blue) # East beamline
			self.Beamline2 = visual.cylinder(pos=Translate(self.target_pos,GetCartesianCoords(chamber_radius, math.pi/2.0, DegToRad(self.beam_axis))), axis=ConvIM3(-217.5,0,217.5*math.tan(DegToRad(180-self.beam_axis))), radius=ConvIM(1.75), color=visual.color.blue) # West beamline
			self.OneMeterChamber = visual.cylinder(pos=self.target_pos, axis=(0,chamber_radius*2,0), radius=chamber_radius, color=visual.color.blue)
			self.OneMeterChamber.pos[1] = -0.5
    def cubic(self, latticeparameters=(1, 1, 1)):
        cube = visual.frame()

        visual.box(frame=cube,
                   pos=(0, 0, 0),
                   size=latticeparameters,
                   color=(1, 0.7, 0.2))

        visual.arrow(frame=cube,
                     pos=(latticeparameters[0] / 2, 0, 0),
                     axis=(1, 0, 0),
                     shaftwidth=0.1,
                     color=(1, 0, 0))

        visual.arrow(frame=cube,
                     pos=(0, latticeparameters[0] / 2, 0),
                     axis=(0, 1, 0),
                     shaftwidth=0.1,
                     color=(0, 1, 0))

        visual.arrow(frame=cube,
                     pos=(0, 0, latticeparameters[0] / 2),
                     axis=(0, 0, 1),
                     shaftwidth=0.1,
                     color=(0, 0, 1))

        return cube
Exemple #6
0
    def __init__(self, pos=(-20,-10,10), axis=(0,5,1), length=8, height=8,\
                                                                    width=8):
        """
        Construct it with a preset or given geometry.
        """
        # calibration (see: calibrate(value))
        self.zero = None

        # color and material
        room_color = (1, 1, 1)
        wet_color = (0, 0, 1)
        room_opacity = 0.5
        wet_opacity = 0.5
        room_material = materials.diffuse
        wet_material = materials.diffuse

        ## NOTE: do not change the order here, or self.wet will never be
        #        seen again.. (even with opaque, vpython hides the second cube)
        # visualize the humidity
        self.wet = box(pos=pos, axis=axis, length=length, height=height,\
                        width=width, opacity=wet_opacity, color=wet_color,\
                        material=wet_material)
        # visualize the empty space
        self.room = box(pos=pos, axis=axis, length=length, height=height,\
                        width=width, opacity=room_opacity, color=room_color,\
                        material=room_material)
        # add a label
        p = self.calc_label_pos(pos)
        self.label = label(pos=p, text='H: 100%')
    def show_ladybug(self, H=None):
        '''Show Ladybug in Visual Python at origin or at the translated position
        if parameter is given.

        TODO: Implement an additional translation H and show at new position.'''
#        vis.ellipsoid(width=0.12, length=0.08, height=0.08,
#                      color=vis.color.red, opacity=0.2)
        vis.arrow(axis=(0.04, 0, 0), color=(1,0,0) )
        vis.arrow(axis=(0, 0.04, 0), color=(0,1,0) )
        vis.arrow(axis=(0, 0, 0.04), color=(0,0,1) )
        colors = [vis.color.red, vis.color.green, vis.color.blue,
                  vis.color.cyan, vis.color.yellow, vis.color.magenta]
        for P in self.LP:
            R = P[:3,:3]
            pos = dot(P[:3],r_[0,0,0,1])
            pos2 = dot(P[:3],r_[0,0,0.01,1])
            vis.sphere(pos=pos, radius=0.002, color=colors.pop(0))
            vis.box(pos=pos2, axis=dot(R, r_[0,0,1]).flatten(),
                    size=(0.001,0.07,0.09), color=vis.color.red,
                    opacity=0.1)
            vis.arrow(pos=pos,
                      axis=dot(R, r_[0.02,0,0]).flatten(),
                      color=(1,0,0), opacity=0.5 )
            vis.arrow(pos=pos,
                      axis=dot(R, r_[0,0.02,0]).flatten(),
                      color=(0,1,0), opacity=0.5 )
            vis.arrow(pos=pos,
                      axis=dot(R, r_[0,0,0.02]).flatten(),
                      color=(0,0,1), opacity=0.5 )
Exemple #8
0
 def makeBoard(self):
     for i in range(8):
         for j in range(8):
             if (i+j) % 2 == 1:
                 sColor = vis.color.blue
             else: sColor = vis.color.white
             vis.box(frame = self.frame, pos=(i,-0.1,j),length=1,height=0.1,width=1,color=sColor)
Exemple #9
0
    def cubic(self, latticeparameters=(1, 1, 1)):
        cube = visual.frame()

        visual.box(frame=cube
                   , pos=(0, 0, 0)
                   , size=latticeparameters
                   , color=(1, 0.7, 0.2))

        visual.arrow(frame=cube
                     , pos=(latticeparameters[0] / 2, 0, 0)
                     , axis=(1, 0, 0)
                     , shaftwidth=0.1
                     , color=(1, 0, 0))

        visual.arrow(frame=cube
                     , pos=(0, latticeparameters[0] / 2, 0)
                     , axis=(0, 1, 0)
                     , shaftwidth=0.1
                     , color=(0, 1, 0))

        visual.arrow(frame=cube
                     , pos=(0, 0, latticeparameters[0] / 2)
                     , axis=(0, 0, 1)
                     , shaftwidth=0.1
                     , color=(0, 0, 1))

        return cube
Exemple #10
0
 def run(self):
     '''
     Run the simulation with racers that had been previously added to the world
     by add_racer method.
     '''
     # create the scene with the plane at the top
     visual.scene.center = visual.vector(0,-25,0)
     visual.box(pos=(0,0,0), size=(12,0.2,12), color=visual.color.green)
     # create the visual objects that represent the racers (balls)
     balls = [ visual.sphere(pos=(index,0,0), radius=0.5) for index in xrange(len(self.racers))]
     for ball, racer in zip(balls, self.racers):
         color = visual.color.blue
         try:
             # try to set the color given by a string
             color = getattr(visual.color, racer.color)
         except AttributeError:
             pass
         ball.trail  = visual.curve(color=color)
     while not reduce(lambda x, y: x and y, [racer.result for racer in self.racers]):
         # slow down the looping - allow only self.time_calibration
         # number of loop entries for a second
         visual.rate(self.time_calibration)
         # move the racers
         for racer in self.racers:
             self.__move_racer(racer) 
             
         for ball, racer in zip(balls, self.racers):
             ball.pos.y = -racer.positions[-1][1]
             ball.pos.x = racer.positions[-1][0]
             ball.trail.append(pos=ball.pos)
             
         self.current_time += self.interval
         self.timeline.append(self.current_time)
Exemple #11
0
    def addBox(self, box, colour=None, opacity=1.):
        if not Visualiser.VISUALISER_ON:
            return
        if isinstance(box, Box):
            if colour is None:
                colour = visual.color.red
            
            org = transform_point(box.origin, box.transform)
            ext = transform_point(box.extent, box.transform)
            print("Visualiser: box origin=%s, extent=%s" % (str(org), str(ext)))
            size = np.abs(ext - org)
            
            pos = org + 0.5*size
            print("Visualiser: box position=%s, size=%s" % (str(pos), str(size)))
            angle, direction, point = tf.rotation_from_matrix(box.transform)
            print("colour,", colour)
            pos = visual.vec(*pos.tolist())
            size = visual.vec(*size.tolist())

            try:
                colour = visual.vec(*colour)
            except:
                pass

            #visual.box(pos=pos, size=size, opacity=opacity, color=None)
            visual.box(pos=pos, size=size, color=colour, opacity=opacity)
Exemple #12
0
    def addBox(self, box, colour=None):
        if not Visualiser.VISUALISER_ON:
            return
        if isinstance(box, geo.Box):
            if colour == None:
                colour = visual.color.red
            org = geo.transform_point(box.origin, box.transform)
            ext = geo.transform_point(box.extent, box.transform)
            print "Visualiser: box origin=%s, extent=%s" % (str(org), str(ext))
            size = np.abs(ext - org)

            pos = org + 0.5 * size
            print "Visualiser: box position=%s, size=%s" % (str(pos),
                                                            str(size))
            angle, direction, point = tf.rotation_from_matrix(box.transform)
            print "colour,", colour
            if colour == [0, 0, 0]:
                visual.box(pos=pos,
                           size=size,
                           opacity=0.3,
                           material=visual.materials.plastic)
            else:
                visual.box(pos=pos,
                           size=size,
                           color=geo.norm(colour),
                           opacity=0.5)
Exemple #13
0
def drawCameraFrame():  # create frame and draw its contents
    global  cam_box, cent_plane,  cam_lab, cam_tri, range_lab, linelen, fwd_line
    global fwd_arrow, mouse_line, mouse_arrow, mouse_lab, fov, range_x, cam_dist, cam_frame
    global ray
    cam_frame = vs.frame( pos = vs.vector(0,2,2,),  axis = (0,0,1))
               # NB: contents are rel to this frame.  start with camera looking "forward"
               # origin is at simulated scene.center
    fov = vs.pi/3.0  # 60 deg 
    range_x = 6  # simulates scene.range.x  
    cam_dist = range_x / vs.tan(fov/2.0)  # distance between camera and center. 
    ray = vs.vector(-20.0, 2.5, 3.0).norm()  # (unit) direction of ray vector (arbitrary)
                                         #  REL TO CAMERA FRAME
    cam_box = vs.box(frame=cam_frame, length=1.5, height=1, width=1.0, color=clr.blue,
                                                   pos=(cam_dist,0,0)) # camera-box
    cent_plane = vs.box(frame=cam_frame, length=0.01, height=range_x*1.3, width=range_x*2,
                                                    pos=(0,0,0), opacity=0.5 )  # central plane
    cam_lab = vs.label(frame=cam_frame, text= 'U', pos= (cam_dist,0,0), height= 9, xoffset= 6)
    cam_tri = vs.faces( frame=cam_frame, pos=[(0,0,0), (0,0,-range_x), (cam_dist,0,0)])
    cam_tri.make_normals()
    cam_tri.make_twosided()
    range_lab = vs.label(frame=cam_frame, text= 'R', pos= (0, 0, -range_x), height= 9, xoffset= 6)
    linelen = scene_size + vs.mag( cam_frame.axis.norm()*cam_dist + cam_frame.pos)
                                                                   # len of lines from camera
    fwd_line = drawLine( vs.vector(cam_dist,0,0), linelen, vs.vector(-1,0,0))
    fwd_arrow = vs.arrow(frame=cam_frame, axis=(-2,0,0), pos=(cam_dist, 0, 0), shaftwidth=0.08,
                                                                            color=clr.yellow)
    vs.label(frame=cam_frame, text='C', pos=(0,0,0), height=9, xoffset=6, color=clr.yellow)
    mouse_line = drawLine ( vs.vector(cam_dist,0,0), linelen, ray ) 
    mouse_arrow = vs.arrow(frame=cam_frame, axis=ray*2, pos=(cam_dist,0,0), shaftwidth=0.08,
                                                                                   color=clr.red)
    mouse_lab = vs.label(frame=cam_frame, text= 'M', height= 9, xoffset= 10, color=clr.red, 
                                pos=  -ray*(cam_dist/vs.dot(ray,(1,0,0))) + (cam_dist,0,0))
Exemple #14
0
    def addBox(self, box, colour=None, opacity=1., material=None):
        if not VISUAL_INSTALLED:
            return
        if isinstance(box, geo.Box):
            if colour == None:
                colour = visual.color.red
            if material is None:
                material = visual.materials.plastic
            org = geo.transform_point(box.origin, box.transform)
            ext = geo.transform_point(box.extent, box.transform)
            print "Visualiser: box origin=%s, extent=%s" % (str(org), str(ext))
            size = np.abs(ext - org)

            pos = org + 0.5 * size
            print "Visualiser: box position=%s, size=%s" % (str(pos),
                                                            str(size))
            angle, direction, point = tf.rotation_from_matrix(box.transform)
            print "colour,", colour
            if np.allclose(np.array(colour), np.array([0, 0, 0])):
                visual.box(pos=pos,
                           size=size,
                           material=material,
                           opacity=opacity)
            else:
                visual.box(pos=pos,
                           size=size,
                           color=colour,
                           materials=material,
                           opacity=opacity)
Exemple #15
0
    def __init__(self, joint, num, length, height=LEGS_HEIGHT, width=LEGS_WIDTH):
        """
        """
        super(Coxa3D, self).__init__(joint, num, length, height, width, (0, 1, 0))

        visual.cylinder(frame=self, pos=(0, -(height+5)/2, 0), radius=(height+1)/2, axis=(0, 1, 0), length=height+5, color=visual.color.cyan)
        visual.box(frame=self, pos=(length/2, 0, 0), length=length, height=height, width=width , color=visual.color.red)
Exemple #16
0
    def __init__(self, joint, num, length, height=LEGS_HEIGHT, width=LEGS_WIDTH):
        """
        """
        super(Tibia3D, self).__init__(joint, num, length, height, width, (0, 0, 1))

        visual.cylinder(frame=self, pos=(0, 0, -(width+5)/2), radius=(height+1)/2, axis=(0, 0, 1), length=width+5, color=visual.color.cyan)
        visual.box(frame=self, pos=(length/2, 0, 0), length=length, height=height, width=width , color=visual.color.blue)
        self.rotate(angle=math.radians(180), axis=self._axis)
 def AddToQueue(self, ID, In):
     InOut = 1
     if In == True: InOut = 0
     priorSquare = 0
     if len(self.NodeList[ID][InOut]) > 0:
         priorSquare = self.NodeList[ID][InOut][-1].pos[1]
     newY = priorSquare + 1
     if In==1: box = v.box(pos=(ID*2+InOut, newY, 0), Length=0.25, Width=0.25, Height=0.25, color=v.color.green)
     else: box = v.box(pos=(ID*2+InOut, newY, 0), Length=0.25, Width=0.25, Height=0.25, color=v.color.red)
     self.NodeList[ID][InOut].append(box)
Exemple #18
0
    def __init__(self):
        self._value = random() * 2 * pi
        self._model = v.frame()

        W = 0.1
        v.box(frame=self._model, pos=(+W / 2, 0, 0), size=(W, W, W), color=v.color.red)
        v.box(frame=self._model, pos=(-W / 2, 0, 0), size=(W, W, W),
            color=v.color.white)

        self._model.rotate(angle=self._value, axis=(0, 0, 1))
Exemple #19
0
def visualBrick(brick, opacity = 0.7, offset = (0.0, 0.0, 0.0), material = None, color = visual.color.white):
    center_x = (brick.max_x + brick.min_x) / 2 + offset[0]
    center_y = (brick.max_y + brick.min_y) / 2 + offset[1]
    center_z = (brick.max_z + brick.min_z) / 2 + offset[2]
    size_x = brick.max_x - brick.min_x
    size_y = brick.max_y - brick.min_y
    size_z = brick.max_z - brick.min_z
    visual.box(pos = (center_x, center_y, center_z),
               length = size_x, height = size_y, width = size_z,
               color = color, opacity = opacity,
               material = material
        )
    def hexagonal(self, CAratio=1.6):
        hexagonal = visual.frame()

        base1 = visual.box(frame=hexagonal,
                           pos=(0, -CAratio / 2.0, 0),
                           size=(math.sqrt(3), 0.01, 1),
                           color=(1, 0.7, 0.2))
        base1 = base1.__copy__()
        base1.rotate(angle=math.pi * 60 / 180,
                     axis=(0, 1, 0),
                     origin=(0, 0, 0))
        base1 = base1.__copy__()
        base1.rotate(angle=math.pi * 60 / 180,
                     axis=(0, 1, 0),
                     origin=(0, 0, 0))

        base2 = visual.box(frame=hexagonal,
                           pos=(0, CAratio / 2.0, 0),
                           size=(math.sqrt(3), 0.01, 1),
                           color=(1, 0.7, 0.2))
        base2 = base2.__copy__()
        base2.rotate(angle=math.pi * 60 / 180,
                     axis=(0, 1, 0),
                     origin=(0, 0, 0))
        base2 = base2.__copy__()
        base2.rotate(angle=math.pi * 60 / 180,
                     axis=(0, 1, 0),
                     origin=(0, 0, 0))

        face = visual.box(frame=hexagonal,
                          pos=(math.sqrt(3) / 2.0, 0, 0),
                          size=(0.01, CAratio, 1),
                          color=(1, 0.7, 0.2))
        for _i in range(6):
            face = face.__copy__()
            face.rotate(angle=math.pi * 60 / 180,
                        axis=(0, 1, 0),
                        origin=(0, 0, 0))

        visual.arrow(frame=hexagonal,
                     pos=(0, CAratio / 2, 0),
                     axis=(0, 0.5, 0),
                     shaftwidth=0.1,
                     color=(1, 0, 0))

        visual.arrow(frame=hexagonal,
                     pos=(CAratio / 2, 0, 0),
                     axis=(0.5, 0, 0),
                     shaftwidth=0.1,
                     color=(0, 1, 0))

        return hexagonal
Exemple #21
0
 def addFinitePlane(self, plane, colour=None, opacity=0.):
     if not Visualiser.VISUALISER_ON:
         return
     if isinstance(plane, geo.FinitePlane):
         if colour == None:
             colour = visual.color.blue
         # visual doesn't support planes, so we draw a very thin box
         H = .001
         pos = (plane.length / 2, plane.width / 2, H / 2)
         pos = geo.transform_point(pos, plane.transform)
         size = (plane.length, plane.width, H)
         axis = geo.transform_direction((0, 0, 1), plane.transform)
         visual.box(pos=pos, size=size, color=colour, opacity=0)
Exemple #22
0
 def addFinitePlane(self, plane, colour=None, opacity=0.):
     if not Visualiser.VISUALISER_ON:
         return
     if isinstance(plane, geo.FinitePlane):
         if colour == None:
             colour = visual.color.blue
         # visual doesn't support planes, so we draw a very thin box
         H = .001
         pos = (plane.length/2, plane.width/2, H/2)
         pos = geo.transform_point(pos, plane.transform)
         size = (plane.length, plane.width, H)
         axis = geo.transform_direction((0,0,1), plane.transform)
         visual.box(pos=pos, size=size, color=colour, opacity=0)
Exemple #23
0
 def addFinitePlane(self, plane, colour=None, opacity=1., material=None):
     if not VISUAL_INSTALLED:
         return
     if isinstance(plane, geo.FinitePlane):
         if material is None:
             material = visual.materials.plastic
         if colour == None:
             colour = visual.color.blue
         # visual doesn't support planes, so we draw a very thin box
         H = .001
         pos = (plane.length/2, plane.width/2, H/2)
         pos = geo.transform_point(pos, plane.transform)
         size = (plane.length, plane.width, H)
         axis = geo.transform_direction((0,0,1), plane.transform)
         visual.box(pos=pos, size=size, color=colour, opacity=opacity, material=material)
Exemple #24
0
 def addFinitePlane(self, plane, colour=None, opacity=1., material=None):
     if not VISUAL_INSTALLED:
         return
     if isinstance(plane, geo.FinitePlane):
         if material is None:
             material = visual.materials.plastic
         if colour is None:
             colour = visual.color.blue
         # visual doesn't support planes, so we draw a very thin box
         H = .001
         pos = (plane.length/2, plane.width/2, H/2)
         pos = geo.transform_point(pos, plane.transform)
         size = (plane.length, plane.width, H)
         axis = geo.transform_direction((0,0,1), plane.transform)
         visual.box(pos=pos, size=size, color=colour, opacity=opacity, material=material)
Exemple #25
0
 def sCaidalibre(self):
     self.alturaCL=self.alturaCL.get()
     self.velocidadX=self.velocidadX.get()
     try:
         self.alturaCL=float(self.alturaCL)
         self.velocidadX=float(self.velocidadX)
     except:
         self.alerta()
     gdpos=vgraph.gdisplay(x=600,y=0,xtitle='Tiempo',ytitle='Posicion(y)')
     plotpos=vgraph.gcurve(gdisplay=gdpos,color=vs.color.red)
     gdvel=vgraph.gdisplay(x=600,y=600,xtitle='Velocidad',ytitle='Tiempo')
     plotvel=vgraph.gcurve(gdisplay=gdvel,color=vs.color.blue)
     gdacl=vgraph.gdisplay(x=0,y=900,xtitle='Aceleracion',ytitle='Tiempo')
     plotacl=vgraph.gcurve(gdisplay=gdacl,color=vs.color.blue)
     suelo=vs.box(pos=(0,-5,0),length=30,height=0.1,width=1,color=vs.color.blue)
     esferaC=vs.sphere(pos=(0,self.alturaCL,-2),radius=1,color=vs.color.red)
     T=np.sqrt(2*(self.alturaCL+5)/9.8)
     t=0
     while t<T:
         esferaC.pos=(self.velocidadX*t,self.alturaCL-9.8*t**2/2,-2)
         plotpos.plot(pos=(t,self.alturaCL-9.8*t**2/2))
         plotvel.plot(pos=(t,-9.8*t))
         plotacl.plot(pos=(t,-9.8))
         t+=0.001
         vs.rate(100)
Exemple #26
0
    def addcar(self, pos, color=v.color.green, name="v"):
        # Creating car 
        car = v.frame()
        car.start = pos
        car.pos = car.start
        car.vector = v.vector(0.05, 0, 0) 
        car.color = color
        car.colorori = car.color

        body = v.box(frame = car, pos = (0,0,0), size = (2.4*self.thk, 0.6*self.thk, 1.4*self.thk), color = car.colorori) 
        wheel1 = v.cylinder(frame=car, pos=(0.8*self.thk,-0.2*self.thk,0.8*self.thk), axis=(0,0,-1.6*self.thk), radius=0.25*self.thk, color=(0.6,0.6,0.6)) 
        wheel2 = v.cylinder(frame=car, pos=(-0.8*self.thk,-0.2*self.thk,0.8*self.thk), axis=(0,0,-1.6*self.thk), radius=0.25*self.thk, color=(0.6,0.6,0.6)) 
        head = v.convex(frame=car, color=car.colorori)
        head.append(pos=v.vector(0.6, 0.3, -0.7)*self.thk)
        head.append(pos=v.vector(0.6, 0.3, 0.7)*self.thk)
        head.append(pos=v.vector(-1.2, 0.3, -0.7)*self.thk)
        head.append(pos=v.vector(-1.2, 0.3, 0.7)*self.thk)
        head.append(pos=v.vector(0.4, 0.7, -0.6)*self.thk)
        head.append(pos=v.vector(0.4, 0.7, 0.6)*self.thk)
        head.append(pos=v.vector(-0.8, 0.7, -0.6)*self.thk)
        head.append(pos=v.vector(-0.8, 0.7, 0.6)*self.thk)

        # Creating Label
        car.vlabel = v.label(justify='center', pos=car.pos, xoffset=3*self.thk, yoffset=39*self.thk, space=3*self.thk, text=name,height=15, line=0,border=3)

        self.cars[name] = car
        self.labels[name] = car.vlabel
def draw_world(world_data):
	"""
	Draws a world in 3D
	"""
	for obj in vpy.scene.objects:
		del obj

	box_width = WIDTH // len(world_data[0])
	box_length = LENGTH // len(world_data)

	for row_i, row in enumerate(world_data):
		for col_i, col in enumerate(row):
			color = terrain_key.get(row[col_i], None)
			if color is not None:
				vpy.box(pos=(col_i*box_width, 0, row_i*box_length),
					length=box_length, height=box_width, width=1, color=color)
Exemple #28
0
    def __init__(self, ini=None):
        wx.Frame.__init__(self, None)

        self.Splitter = wx.SplitterWindow(self)
        self.p1 = wx.Panel(self.Splitter)
        self.p2 = wx.Panel(self.Splitter)
        self.Splitter.SplitVertically(self.p1, self.p2)
        self.Splitter.SetMinimumPaneSize(20)
        Sizer = wx.BoxSizer()
        Sizer.Add(self.Splitter, 1, wx.EXPAND)
        self.SetSizer(Sizer)

        # create a VPython application, just an copy of the Ball-demo
        floor = visual.box(pos=(0, 0, 0),
                           length=4,
                           height=0.5,
                           width=4,
                           color=visual.color.blue)
        ball = visual.sphere(pos=(0, 4, 0), radius=1, color=visual.color.red)
        ball.velocity = visual.vector(0, -1, 0)
        dt = 0.01

        # initialize the State_Machine and start the timer
        self.VP_State = 0
        self.Old_Size = (0, 0)
        self.Timer = wx.Timer(self)
        # the third parameter is essential to allow other timers
        self.Bind(wx.EVT_TIMER, self._On_Timer, self.Timer)
        self.Timer.Start(100)
    def init_visual(self, only_wiiobj=False):
        if not only_wiiobj:
            # vpython
            visual.scene.width = self.param["width"]
            visual.scene.height = self.param["height"]
            visual.scene.title = "3D WiiMote Simulation"
            visual.scene.forward = visual.vector(1, 0, 0)  # not to error ?
            visual.scene.up = visual.vector(0, 0, 1)
            visual.scene.forward = visual.vector(-1, 1, -1)
            visual.scene.autoscale = 0
            visual.scene.x = 0
            visual.scene.y = 30

            self.visual["axis"][0] = visual.arrow(
                color=visual.color.red, axis=(3, 0, 0), headwidth=1, shaftwidth=0.5, fixedwidth=1
            )
            self.visual["axis"][1] = visual.arrow(
                color=visual.color.green, axis=(0, 3, 0), headwidth=1, shaftwidth=0.5, fixedwidth=1
            )
            self.visual["axis"][2] = visual.arrow(
                color=visual.color.blue, axis=(0, 0, 3), headwidth=1, shaftwidth=0.5, fixedwidth=1
            )
        self.visual["wiiobj"] = visual.box(
            pos=(0, 0, 0), length=2, height=6, width=1, color=visual.color.white, axis=(2, 0, 0)
        )

        return
Exemple #30
0
 def __init__(self,num_of_disks,num_of_rods):
     self.max_disk_radius = 1.0
     self.disk_thickness = 0.2
     self.rod_height = self.disk_thickness * (num_of_disks + 1)
     self.disks = [visual.cylinder(radius=self.max_disk_radius*(i+2)/(num_of_disks+1),
                                   length=self.disk_thickness,
                                   axis=(0,0,1),
                                   color=(0.0,0.5,1.0),
                                   material=visual.materials.wood) \
                   for i in range(num_of_disks)]
     self.rods  = [visual.cylinder(radius=self.max_disk_radius*1.0/(num_of_disks+1),
                                   material=visual.materials.plastic,
                                   color=(1.0,0.5,0.3),
                                   length=self.rod_height,
                                   axis=(0,0,1)) for i in range(num_of_rods)]
     for i in range(num_of_rods):
         self.rods[i].pos.x = self.max_disk_radius*2*(i-(num_of_rods-1)*0.5)
     for i in range(num_of_disks):
         self.set_disk_pos(disk=i,rod=0,z_order=num_of_disks-i-1)
     self.base = visual.box(
         pos=(0,0,-self.disk_thickness*0.5),
         length=(num_of_rods+0.5)*self.max_disk_radius*2,
         width=self.disk_thickness,
         height=self.max_disk_radius*2.5,
         color=(0.2,1.0,0.2),
         material=visual.materials.wood)
def golf_ball_calc(x,y,z,vx,vy,vz,dt,m,g,B2,S0,w,w_vector):
    t = 0.0
    x_list = [x]
    y_list = [y]
    z_list = [z]
    vx_list = [vx]
    vy_list = [vy]
    vz_list = [vz]
    t_list = [t]
    v_vector = visual.vector(vx,vy,vz)

    tee = visual.box(pos=(0,0,0), length=0.05, width=0.05, height=0.5,color=visual.color.white)
    ball = visual.sphere(pos=(x,y,z), radius = 0.25, color = visual.color.white)
    ball.trail = visual.curve(color = visual.color.red)

    while y > 0.0:
        visual.rate(100)
        t,x,y,z,vx,vy,vz = golfball_step(t,x,y,z,vx,vy,vz,m,g,B2,S0,w,dt,w_vector,v_vector)
        x_list.append(x)
        y_list.append(y)
        z_list.append(z)
        vx_list.append(vx)
        vy_list.append(vy)
        vz_list.append(vz)
        t_list.append(t)
        v_vector = visual.vector(vx,vy,vz)
        ball.pos = (x,y,z)
        ball.trail.append(pos=ball.pos)

    return t_list,x_list,y_list,z_list,vx_list,vy_list,vz_list
Exemple #32
0
def main():
    scene = visual.display(width=settings.SCENE_WIDTH, height=settings.SCENE_HEIGHT)
    ground = visual.box(axis=(0, 1, 0), pos=(0, 0, 0), length=0.1, height=500, width=500, color=visual.color.gray(0.75), opacity=0.5)

    def addGait(gaitClass, gaitName):
        gait = gaitClass(gaitName, settings.GAIT_LEGS_GROUPS[gaitName], settings.GAIT_PARAMS[gaitName])
        GaitManager().add(gait)

    addGait(GaitTripod, "tripod")
    addGait(GaitTetrapod, "tetrapod")
    addGait(GaitRiple, "riple")
    addGait(GaitWave, "metachronal")
    addGait(GaitWave, "wave")
    GaitManager().select("riple")

    robot = Hexapod3D()

    remote = Gamepad(robot)

    GaitSequencer().start()
    remote.start()

    robot.setBodyPosition(z=30)

    robot.mainLoop()

    remote.stop()
    remote.join()
    GaitSequencer().stop()
    GaitSequencer().join()
Exemple #33
0
    def init_visual(self, only_wiiobj=False):
        visual_pos = ((0, 0, 0), (7,7,0), (14,14,0))
        if not only_wiiobj:
            #vpython
            visual.scene.width=self.param["width"] * 3
            visual.scene.height=self.param["height"]
            visual.scene.title = "3D WiiMote Simulation"
            visual.scene.forward = visual.vector(1,0,0) # not to error ?
            visual.scene.up = visual.vector(0,0,1)
            visual.scene.forward = visual.vector(-1,1,-1)
            visual.scene.center = (7,7,0)
            visual.scene.scale = (0.07, 0.07, 0.07)
            visual.scene.autoscale = 0
            visual.scene.x = 0
            visual.scene.y = 30
            
            self.visual["axis"] = [(visual.arrow(pos=visual_pos[i], color=visual.color.red, axis=(3,0,0), headwidth=1, shaftwidth=0.5, fixedwidth=1),
                                    visual.arrow(pos=visual_pos[i], color=visual.color.green, axis=(0,3,0), headwidth=1, shaftwidth=0.5, fixedwidth=1),
                                    visual.arrow(pos=visual_pos[i], color=visual.color.blue, axis=(0,0,3), headwidth=1, shaftwidth=0.5, fixedwidth=1))
                                   for i in xrange(3)]
            self.visual["text"] = [visual.label(text="accel", pos=(1, -1, -4), color=visual.color.white),
                                   visual.label(text="gyro", pos=(8, 6, -4), color=visual.color.white),
                                   visual.label(text="accel + gyro", pos=(15, 13, -4), color=visual.color.white),]
        self.visual["wiiobj"] = [visual.box(pos=visual_pos[i], length=2, height=6, width=1, color=visual.color.white, axis=(1,0,0)) #x=length, y=height, z=width
                                 for i in xrange(3)]

        return
Exemple #34
0
    def DefineBox(self,
                  Density,
                  SizeX,
                  SizeY,
                  SizeZ,
                  colour,
                  position=(0, 0, 0)):
        """Define this element as a ode Box."""
        if self._hasGeom:
            self._geom = ode.GeomBox(
                _bigSpace,
                (SizeX, SizeY,
                 SizeZ))  # BigSpace was None, problem with local body spaces

        DisplayElement.SetDisplayObject(
            self,
            visual.box(length=SizeX,
                       height=SizeY,
                       width=SizeZ,
                       color=colour,
                       pos=position))

        self._mass = ode.Mass()
        self._mass.setBox(Density, SizeX, SizeY, SizeZ)
        return self
Exemple #35
0
    def addCSGvoxel(self, box, colour):
        """
        16/03/10: To visualise CSG objects
        """

        if colour == None:
            colour = visual.color.red

        org = box.origin
        ext = box.extent

        size = np.abs(ext - org)

        pos = org + 0.5 * size

        visual.box(pos=pos, size=size, color=colour, opacity=0.2)
Exemple #36
0
 def addCSGvoxel(self, box, colour):
     """
     16/03/10: To visualise CSG objects
     """
        
     if colour == None:         
         colour = visual.color.red
         
     org = box.origin
     ext = box.extent
         
     size = np.abs(ext - org)
         
     pos = org + 0.5*size                      
         
     visual.box(pos=pos, size=size, color=colour, opacity=0.2)
Exemple #37
0
 def __init__( self, NCellsPerDimension, Length, E0 ):
     self.n   = NCellsPerDimension
     self.L   = Length
     self.V   = self.L**3
     self.N   = 4 * self.n**3
     self.a   = self.L / self.n
     self.E0  = E0
     self.E   = E0
     self.U   = 0
     self.dU  = 0
     self.ddU = 0
     self.particles = []
     self.index = 0
     self.dt    = 1e-2
     self.dt_2  = self.dt * 0.5
     self.dt2_2 = self.dt * self.dt_2
 
     self.scene = visual.display( title = 'System',
                                  x=800, y=0,
                                  width=800, height=800,
                                  center = visual.vector(0.5,0.5,0.5) * self.L,
                                  autoscale = False,
                                  range = 1.5 * self.L)
 
     self.box   = visual.box( pos     = visual.vector(0.5,0.5,0.5) * self.L,
                              length  = self.L,
                              height  = self.L,
                              width   = self.L,
                              color   = visual.color.green,
                              opacity = 0.2 )
Exemple #38
0
 def __init__(self, filepath, pos=(0,0,0), effect=fade_in):
     texture = file_to_texture(filepath) 
     self.card = box(axis = (0,0,1),
                       size = (.01, 25, 50),
                       pos = pos,
                       opacity = 0,
                       material=texture)
     effect(self.card)
Exemple #39
0
 def __init__(self, **kwargs):
     super(Board, self).__init__(**kwargs)
     
     visual.box(pos = (9, 9, -1),
                size = (20, 20, 1),
                color = (1, 0.75, 0),
                material = visual.materials.wood,
                frame = self)
     # lines
     params = dict(color = (.5, .5, .5), frame = self)
     for i in range(19):
         visual.curve(pos = [(0, i, 0), (18, i, 0)], radius = .05, **params)
     for i in range(19):
         visual.curve(pos=[(i, 0, 0), (i, 18, 0)], radius = .05, **params)
     
     self.stones, self.star = [], []
     for x in itertools.product((4, 10, 16), (4, 10, 16)): self.star.append(x[:])
Exemple #40
0
 def addCSGvoxel(self, box, colour, material=None, opacity=1.):
     """
     16/03/10: To visualise CSG objects
     """
     if not VISUAL_INSTALLED:
         return
     if colour == None:         
         colour = visual.color.red
         
     org = box.origin
     ext = box.extent
         
     size = np.abs(ext - org)
         
     pos = org + 0.5*size                      
         
     visual.box(pos=pos, size=size, color=colour, opacity=opacity, material=material)
Exemple #41
0
 def __init__(self, stacks, position):
     """
     Pass a reference to the stacks object that holds all the blocks
     and the index of the initial stack of the block
     """
     Block.__init__(self, stacks, position)
     self.box = box(pos=(position-(stacks.blockCount/2), 0, 0), size=(.9,.9,.9), color=color.blue)
     self.label = label(pos=array(self.box.pos) + array([0,0,1]), text=str(position), opacity=0, box=0, line=0)
Exemple #42
0
 def addCSGvoxel(self, box, colour, material=None, opacity=1.):
     """
     16/03/10: To visualise CSG objects
     """
     if not VISUAL_INSTALLED:
         return
     if colour is None:         
         colour = visual.color.red
         
     org = box.origin
     ext = box.extent
         
     size = np.abs(ext - org)
         
     pos = org + 0.5*size                      
         
     visual.box(pos=pos, size=size, color=colour, opacity=opacity, material=material)
Exemple #43
0
def load_from_file(filepath, pos=(0,0,0), effect=fade_in):
    texture = file_to_texture(filepath) 
    card = box(axis = (0,0,1),
                      size = (.01, 25, 50),
                      pos = pos,
                      opacity = 0,
                      material=texture)
    effect(card)
    return card
Exemple #44
0
    def __init__(self, **kwargs):
        super(Board, self).__init__(**kwargs)

        visual.box(pos=(9, 9, -1),
                   size=(20, 20, 1),
                   color=(1, 0.75, 0),
                   material=visual.materials.wood,
                   frame=self)
        # lines
        params = dict(color=(.5, .5, .5), frame=self)
        for i in range(19):
            visual.curve(pos=[(0, i, 0), (18, i, 0)], radius=.05, **params)
        for i in range(19):
            visual.curve(pos=[(i, 0, 0), (i, 18, 0)], radius=.05, **params)

        self.stones, self.star = [], []
        for x in itertools.product((4, 10, 16), (4, 10, 16)):
            self.star.append(x[:])
Exemple #45
0
def visualBrick(brick,
                opacity=0.7,
                offset=(0.0, 0.0, 0.0),
                material=None,
                color=visual.color.white):
    center_x = (brick.max_x + brick.min_x) / 2 + offset[0]
    center_y = (brick.max_y + brick.min_y) / 2 + offset[1]
    center_z = (brick.max_z + brick.min_z) / 2 + offset[2]
    size_x = brick.max_x - brick.min_x
    size_y = brick.max_y - brick.min_y
    size_z = brick.max_z - brick.min_z
    visual.box(pos=(center_x, center_y, center_z),
               length=size_x,
               height=size_y,
               width=size_z,
               color=color,
               opacity=opacity,
               material=material)
Exemple #46
0
    def InitVisuals():

        from visual import display, points, box
        window = display(title="F16 Simulation",
                         width=Resolution[0],
                         height=Resolution[1])
        window.up = np.identity(3)[2]
        window.forward = -np.ones(3)
        window.center = pos

        if FPV:
            window.range = 15 * 3  #2

        if stereo is not None:
            window.stereo = stereo

        D = 2500  #5000#2500

        #--- CS ---
        for i in range(3):
            arrow(axis=np.identity(3)[i] * 1000,
                  color=np.identity(3)[i],
                  opacity=0.75)

        #--- Point Cloud ---
        if 1:
            Points = []
            d = 500  #100
            n = int(D / d)
            for i in range(-n, n + 1):
                for j in range(-n, n + 1):
                    for k in range(0, n + 1):
                        p = np.array([i, j, k]).astype(float) * d
                        Points.append(tuple(p))  #+=list(p)
            points(pos=Points)

        if 1:
            box(width=D * 2,
                height=D * 2,
                depth=10,
                axis=-np.identity(3)[2],
                color=[0.6, 0.3, 0.15])

        return window
Exemple #47
0
def gettile(cpos=None):
    if cpos is None:
        cpos = visual.vector((0, 0, 0))
    elif type(cpos) == tuple:
        cpos = visual.vector(cpos)

    dip_sep = 1.10  # dipole separations in meters
    xoffsets = [0.0] * 16  # offsets of the dipoles in the W-E 'x' direction
    yoffsets = [0.0] * 16  # offsets of the dipoles in the S-N 'y' direction
    xoffsets[0] = -1.5 * dip_sep
    xoffsets[1] = -0.5 * dip_sep
    xoffsets[2] = 0.5 * dip_sep
    xoffsets[3] = 1.5 * dip_sep
    xoffsets[4] = -1.5 * dip_sep
    xoffsets[5] = -0.5 * dip_sep
    xoffsets[6] = 0.5 * dip_sep
    xoffsets[7] = 1.5 * dip_sep
    xoffsets[8] = -1.5 * dip_sep
    xoffsets[9] = -0.5 * dip_sep
    xoffsets[10] = 0.5 * dip_sep
    xoffsets[11] = 1.5 * dip_sep
    xoffsets[12] = -1.5 * dip_sep
    xoffsets[13] = -0.5 * dip_sep
    xoffsets[14] = 0.5 * dip_sep
    xoffsets[15] = 1.5 * dip_sep

    yoffsets[0] = 1.5 * dip_sep
    yoffsets[1] = 1.5 * dip_sep
    yoffsets[2] = 1.5 * dip_sep
    yoffsets[3] = 1.5 * dip_sep
    yoffsets[4] = 0.5 * dip_sep
    yoffsets[5] = 0.5 * dip_sep
    yoffsets[6] = 0.5 * dip_sep
    yoffsets[7] = 0.5 * dip_sep
    yoffsets[8] = -0.5 * dip_sep
    yoffsets[9] = -0.5 * dip_sep
    yoffsets[10] = -0.5 * dip_sep
    yoffsets[11] = -0.5 * dip_sep
    yoffsets[12] = -1.5 * dip_sep
    yoffsets[13] = -1.5 * dip_sep
    yoffsets[14] = -1.5 * dip_sep
    yoffsets[15] = -1.5 * dip_sep

    gp = visual.box(pos=visual.vector(0, 0, 0) + cpos,
                    axis=(0, 0, 1),
                    height=5.0,
                    width=5.0,
                    length=0.05,
                    color=color.gray(0.5),
                    visible=False)
    olist = [gp]
    for i in range(16):
        dlist = getdipole(cpos=visual.vector(xoffsets[i], yoffsets[i], 0) +
                          cpos)
        olist += dlist
    return olist
def draw_world(world_data):
    """
	Draws a world in 3D
	"""
    for obj in vpy.scene.objects:
        del obj

    box_width = WIDTH // len(world_data[0])
    box_length = LENGTH // len(world_data)

    for row_i, row in enumerate(world_data):
        for col_i, col in enumerate(row):
            color = terrain_key.get(row[col_i], None)
            if color is not None:
                vpy.box(pos=(col_i * box_width, 0, row_i * box_length),
                        length=box_length,
                        height=box_width,
                        width=1,
                        color=color)
Exemple #49
0
    def __init__(self, Stable, wm, quad_pos=(0, 0, 0)):
        self.world = World()
        self.world.setGravity((0, -9.81, 0))
        self.space = Space()
        self.contactgroup = JointGroup()
        self.wm = wm

        # draw floor
        self.floor = GeomPlane(self.space, (0, 1, 0), -1)
        box(pos=(0, -1, 0), width=2, height=0.01, length=2)

        # Draw Quad
        self.quad = Quad(self.world, self.space, pos=quad_pos)

        # Init Algorithm
        self.stable = Stable(self.quad)

        # stop autoscale of the camera
        scene.autoscale = False
Exemple #50
0
def getxmas():
    """Creates a complete Christmas Tree dipole assembly (minus base) at (0,0,0)

     Returned value is a tuple of (xmas, olist), where xmas is the frame containing the
     complete Christmas Tree dipoles, and olist is a list of all of the component objects."""
    xmas = visual.frame()
    olist = []
    for direction in ['E', 'W', 'N', 'S']:  # Create the four dipole arms
        ef, elist = getelement(frame=xmas, which=direction)
        olist.append(ef)
        olist.append(elist)

    # These objects (s1-s3) are the white plastic space assembly
    s1 = visual.curve(pos=[
        V(-0.233, -0.233, 0.59),
        V(0.233, -0.233, 0.59),
        V(0.233, 0.233, 0.59),
        V(-0.233, 0.233, 0.59),
        V(-0.233, -0.233, 0.59)
    ],
                      frame=xmas,
                      radius=0.02,
                      material=SPACERMAT,
                      color=color.white)
    s2 = visual.curve(pos=[V(-0.233, 0, 0.59),
                           V(0.233, 0, 0.59)],
                      frame=xmas,
                      radius=0.02,
                      material=SPACERMAT,
                      color=color.white)
    s3 = visual.curve(pos=[V(0, -0.233, 0.59),
                           V(0, 0.233, 0.59)],
                      frame=xmas,
                      radius=0.02,
                      material=SPACERMAT,
                      color=color.white)

    # This is an approximation to the LNA and feedhorn at the top of the tree
    lna = visual.box(pos=V(0, 0, 1.63),
                     frame=xmas,
                     height=0.03,
                     length=0.03,
                     width=0.08,
                     material=SPACERMAT,
                     color=color.white)

    # This is the cable duct going vertically down the centre of the tree from the LNA
    pole = visual.curve(pos=[V(0, 0, 0.38), V(0, 0, 1.73)],
                        frame=xmas,
                        radius=POLER,
                        material=POLEMAT,
                        color=color.white)

    olist.append([s1, s2, s3, lna, pole])
    return xmas, olist
Exemple #51
0
 def AddToQueue(self, ID, In):
     InOut = 1
     if In == True: InOut = 0
     priorSquare = 0
     if len(self.NodeList[ID][InOut]) > 0:
         priorSquare = self.NodeList[ID][InOut][-1].pos[1]
     newY = priorSquare + 1
     if In == 1:
         box = v.box(pos=(ID * 2 + InOut, newY, 0),
                     Length=0.25,
                     Width=0.25,
                     Height=0.25,
                     color=v.color.green)
     else:
         box = v.box(pos=(ID * 2 + InOut, newY, 0),
                     Length=0.25,
                     Width=0.25,
                     Height=0.25,
                     color=v.color.red)
     self.NodeList[ID][InOut].append(box)
Exemple #52
0
    def init_gui(self):
        # Is the orientation matrix missing here????
        self.length = 100
        wallR = box(pos=vector(self.length / 2., 0, 0),
                    size=(0.2, self.length, self.length),
                    color=color.green)
        wallB = box(pos=vector(0, 0, -self.length / 2.),
                    size=(self.length, self.length, 0.2),
                    color=color.white)
        wallDown = box(pos=vector(0, -self.length / 2., 0),
                       size=(self.length, 0.2, self.length),
                       color=color.red)
        wallUp = box(pos=vector(0, self.length / 2., 0),
                     size=(self.length, 0.2, self.length),
                     color=color.white)
        wallL = box(pos=vector(-self.length / 2., 0, 0),
                    size=(0.2, self.length, self.length),
                    color=color.blue)

        self.unit_target = self.target_vector / np.linalg.norm(
            self.target_vector)
        self.target_position = np.array(
            self.unit_target) * self.max_factor * self.force_scale
        self.ball = sphere(pos=[0, 0, 0],
                           radius=self.ball_rad,
                           color=self.ball_color)
        self.target = sphere(pos=self.target_position,
                             radius=self.target_rad,
                             color=self.target_color)
        self.shadow_cursor = ring(pos=[0, -self.length / 2, 0],
                                  axis=(0, 10, 0),
                                  radius=self.ball_rad,
                                  thickness=1,
                                  color=[0.25, 0.25, 0.25])
        self.shadow_target = ring(pos=[
            self.target_position[0], -self.length / 2, self.target_position[2]
        ],
                                  axis=(0, 10, 0),
                                  radius=self.ball_rad,
                                  thickness=1,
                                  color=[0.25, 0.25, 0.25])
Exemple #53
0
    def DefineBoxTotal(self, TotalMass, SizeX, SizeY, SizeZ):
        """Define this element as an ode BoxTotal."""
        if self._hasGeom:
            self._geom = ode.GeomBox(_bigSpace, (SizeX, SizeY, SizeZ))

        DisplayElement.SetDisplayObject(
            self, visual.box(length=SizeX, height=SizeY, width=SizeZ))

        self._mass = ode.Mass()
        self._mass.setBoxTotal(TotalMass, SizeX, SizeY, SizeZ)
        self._mass.mass = TotalMass  # Bug workaround?
        return self
Exemple #54
0
def draw_camera_frame():
    """Create frame and draw its contents."""
    global  CAM_BOX, CENT_PLANE, CAM_LAB, CAN_TRI, RANGE_LAB, LINELEN, FWD_LINE
    global FWR_ARROW, MOUSE_LINE, MOUSE_ARROW, MOUSE_LAB, FOV, RANGE_X, CAM_DIST, CAM_FRAME
    global RAY
    CAM_FRAME = vs.frame(pos=vs.vector(0, 2, 2, ), axis=(0, 0, 1))
               # NB: contents are rel to this frame.  start with camera looking "forward"
               # origin is at simulated scene.center
    FOV = vs.pi/3.0  # 60 deg
    RANGE_X = 6  # simulates scene.range.x
    CAM_DIST = RANGE_X / vs.tan(FOV/2.0)  # distance between camera and center.
    RAY = vs.vector(-20.0, 2.5, 3.0).norm()  # (unit) direction of ray vector (arbitrary)
                                         #  REL TO CAMERA FRAME
    CAM_BOX = vs.box(frame=CAM_FRAME, length=1.5, height=1, width=1.0,
                     color=CLR.blue, pos=(CAM_DIST, 0, 0)) # camera-box
    CENT_PLANE = vs.box(frame=CAM_FRAME, length=0.01, height=RANGE_X*1.3,
                        width=RANGE_X*2, pos=(0, 0, 0), opacity=0.5)  # central plane
    CAM_LAB = vs.label(frame=CAM_FRAME, text='U', pos=(CAM_DIST, 0, 0),
                       height=9, xoffset=6)
    CAN_TRI = vs.faces(frame=CAM_FRAME, pos=[
        (0, 0, 0), (0, 0, -RANGE_X), (CAM_DIST, 0, 0)])
    CAN_TRI.make_normals()
    CAN_TRI.make_twosided()
    RANGE_LAB = vs.label(frame=CAM_FRAME, text='R', pos=(0, 0, -RANGE_X),
                         height=9, xoffset=6)
    LINELEN = SCENE_SIZE + vs.mag(
        CAM_FRAME.axis.norm()*CAM_DIST + CAM_FRAME.pos)  # len of lines from camera

    FWD_LINE = draw_line(vs.vector(CAM_DIST, 0, 0), LINELEN, vs.vector(-1, 0, 0))
    FWR_ARROW = vs.arrow(frame=CAM_FRAME, axis=(-2, 0, 0), pos=(CAM_DIST, 0, 0),
                         shaftwidth=0.08, color=CLR.yellow)
    vs.label(frame=CAM_FRAME, text='C', pos=(0, 0, 0), height=9, xoffset=6,
             color=CLR.yellow)
    MOUSE_LINE = draw_line(vs.vector(CAM_DIST, 0, 0), LINELEN, RAY)
    MOUSE_ARROW = vs.arrow(frame=CAM_FRAME, axis=RAY*2, pos=(CAM_DIST, 0, 0),
                           shaftwidth=0.08, color=CLR.red)
    MOUSE_LAB = vs.label(
        frame=CAM_FRAME, text='M', height=9, xoffset=10,
        color=CLR.red,
        pos=-RAY*(CAM_DIST/vs.dot(RAY, (1, 0, 0))) + (CAM_DIST, 0, 0))
Exemple #55
0
def setup_base():
    '''
  Creates a visual for the ground, the construction area, and the home area
  '''
    # Setup the ground
    dim = WORLD['properties']['dim_x'], WORLD['properties'][
        'dim_y'], PROGRAM['epsilon'] / 2
    center = tuple([v / 2 for v in dim])
    temp = visual.box(pos=center, length=dim[0], height=dim[1], width=0.05)
    temp.color = (1, 1, 1)

    # Setup the Home Plate
    dim = HOME['size']
    center = HOME['center']
    temp = visual.box(pos=center, length=dim[0], height=dim[1], width=0.1)
    temp.color = (1, 0, 0)

    # Setup the construction plate
    dim = CONSTRUCTION['size']
    center = CONSTRUCTION['center']
    temp = visual.box(pos=center, length=dim[0], height=dim[1], width=0.1)
    temp.color = (0, 1, 0)
Exemple #56
0
 def animate( self, sleeptime=1.0, transparent=True, blur=False ):
     """ display the reaction-diffusion grid using vpytyon
         transparent: use transparent background instead of black
         blur: produce fuzzy borders between cells on the grid
     """
     import visual as vpy
     self.computeTextureMatrix(transparent)
     self.texture = vpy.materials.texture(data=self.texmat, \
                    mapping='sign', interpolate=blur)
     self.plate = vpy.box(axis=(0,0,1), width=2, height=2, \
                  length=0.1, material=self.texture)
     # TODO: how to reuse existing box and texture???
     print "animate t=", self.time
     vpy.sleep(sleeptime)
Exemple #57
0
 def __init__(self, stacks, position):
     """
     Pass a reference to the stacks object that holds all the blocks
     and the index of the initial stack of the block
     """
     Block.__init__(self, stacks, position)
     self.box = box(pos=(position - (stacks.blockCount / 2), 0, 0),
                    size=(.9, .9, .9),
                    color=color.blue)
     self.label = label(pos=array(self.box.pos) + array([0, 0, 1]),
                        text=str(position),
                        opacity=0,
                        box=0,
                        line=0)
 def __init__(self, **kwargs):
     self.container = visual.frame(**kwargs)
     self.box = visual.box(frame=self.container,
                           length=self.size[0],
                           width=self.size[1],
                           height=self.size[2],
                           color=(0, 0, 0.7))
     self.lidarframe = visual.frame(frame=self.container,
                                    pos=(self.size[0] / 2.0,
                                         self.size[1] / 2.0, self.size[2]))
     self.lidarpoints = visual.points(pos=[(0, 0, 0) for i in range(360)],
                                      frame=self.lidarframe,
                                      size=5,
                                      color=(0, 1, 0))
     print(repr(self.lidarpoints))
Exemple #59
0
    def show_ladybug(self, H=None):
        '''Show Ladybug in Visual Python at origin or at the translated position
        if parameter is given.

        TODO: Implement an additional translation H and show at new position.'''
        #        vis.ellipsoid(width=0.12, length=0.08, height=0.08,
        #                      color=vis.color.red, opacity=0.2)
        vis.arrow(axis=(0.04, 0, 0), color=(1, 0, 0))
        vis.arrow(axis=(0, 0.04, 0), color=(0, 1, 0))
        vis.arrow(axis=(0, 0, 0.04), color=(0, 0, 1))
        colors = [
            vis.color.red, vis.color.green, vis.color.blue, vis.color.cyan,
            vis.color.yellow, vis.color.magenta
        ]
        for P in self.LP:
            R = P[:3, :3]
            pos = dot(P[:3], r_[0, 0, 0, 1])
            pos2 = dot(P[:3], r_[0, 0, 0.01, 1])
            vis.sphere(pos=pos, radius=0.002, color=colors.pop(0))
            vis.box(pos=pos2,
                    axis=dot(R, r_[0, 0, 1]).flatten(),
                    size=(0.001, 0.07, 0.09),
                    color=vis.color.red,
                    opacity=0.1)
            vis.arrow(pos=pos,
                      axis=dot(R, r_[0.02, 0, 0]).flatten(),
                      color=(1, 0, 0),
                      opacity=0.5)
            vis.arrow(pos=pos,
                      axis=dot(R, r_[0, 0.02, 0]).flatten(),
                      color=(0, 1, 0),
                      opacity=0.5)
            vis.arrow(pos=pos,
                      axis=dot(R, r_[0, 0, 0.02]).flatten(),
                      color=(0, 0, 1),
                      opacity=0.5)