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
def show_protective(nparticles): # create scene scene = visual.display(title='Protective zones', width=600, height=400, center=(0,0,0)) scene.select() # read in positions, state and protective zones positions = (numpy.genfromtxt('position.dat'))[:nparticles] state = (numpy.genfromtxt('state.dat'))[:nparticles] zones = (numpy.genfromtxt('fpt.dat'))[:nparticles] # go through particles and display them for i in range(nparticles): # color the spheres according to state cball = visual.color.green if (state[i,0]==1): cball = visual.color.red else: cball = visual.color.blue if (state[i,3]==1): cball = visual.color.yellow if (state[i,3]==2): cball = visual.color.orange visual.sphere(pos=(positions[i,0], positions[i,1], positions[i,2]), radius=zones[i], color=cball) visual.label(pos=(positions[i,0], positions[i,1], positions[i,2]), text='{0:d}'.format(i))
def set_label(self): txtlabel = '' if (self.config['display']['extended_label'] != 0): if (self.obj["orig_ip_protocol"] in (6,17)): txtlabel = 'ORIG SRC: %s:%d\n DST: %s:%d\nREPL SRC: %s:%d\n DST: %s:%d\n' % (self.obj["orig_ip_saddr_str"], self.obj["orig_l4_sport"], self.obj["orig_ip_daddr_str"], self.obj["orig_l4_dport"] ,\ self.obj["reply_ip_saddr_str"], self.obj["reply_l4_sport"], self.obj["reply_ip_daddr_str"], self.obj["reply_l4_dport"]) elif (self.obj["orig_ip_protocol"] == 1): txtlabel = 'ORIG SRC: %s\n DST: %s\nREPL SRC: %s\n DST: %s\nCODE: %d TYPE: %d\n' % (self.obj["orig_ip_saddr_str"], \ self.obj["orig_ip_daddr_str"], self.obj["reply_ip_saddr_str"], \ self.obj["reply_ip_daddr_str"], self.obj["icmp_code"], self.obj["icmp_type"]) else: txtlabel = 'ORIG SRC: %s\n DST: %s\nREPL SRC: %s\n DST: %s\n' % (self.obj["orig_ip_saddr_str"],self.obj["reply_ip_saddr_str"], self.obj["orig_ip_daddr_str"], self.obj["reply_ip_daddr_str"]) else: if (self.obj["orig_ip_protocol"] in (6,17)): txtlabel = 'SRC: %s:%d\nDST: %s:%d\n' % (self.obj["orig_ip_saddr_str"], self.obj["orig_l4_sport"], self.obj["orig_ip_daddr_str"], self.obj["orig_l4_dport"]) else: txtlabel = 'SRC: %s\nDST: %s\n' % (self.obj["orig_ip_saddr_str"], self.obj["orig_ip_daddr_str"]) if (self.obj["orig_ip_protocol"] == 6): txtlabel += 'PROTO: TCP' elif (self.obj["orig_ip_protocol"] == 17): txtlabel += 'PROTO: UDP' elif (self.obj["orig_ip_protocol"] == 1): txtlabel += 'PROTO: ICMP' if (self.obj["ct_event"] == 1): self.label = visual.label(pos=self.pos, xoffset = -10, yoffset = 10, text='%s' % (txtlabel)) elif (self.obj["ct_event"] == 4): self.label = visual.label(pos=self.pos, xoffset = -10, yoffset = 10, text='%s\nIN: %d, OUT: %d bits\nDURATION: %f sec' % (txtlabel, self.obj["reply_raw_pktlen"],self.obj["orig_raw_pktlen"] , self.axis.x)) self.label.visible = 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))
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 plot3D(self): axis_length = 10.0 xaxis = vs.arrow(pos = (-5, -5, 0), axis = (axis_length, 0, 0), shaftwidth = 0.01) yaxis = vs.arrow(pos = (-5, -5, 0), axis = (0, axis_length, 0), shaftwidth = 0.01) balls = [] for (i, j) in zip(self.x, self.T): balls.append(vs.sphere(pos = ((j / self.time) * axis_length * 0.9- 4.9, (i / self.v) * axis_length * 0.9 - 4.9, 0), radius = 0.2, color = vs.color.red)) xlabel = vs.label(text = "Time/s", pos = (5, -5, 0)) ylabel = vs.label(text = "Displacement/m", pos = (-5, 5, 0))
def plot3D(): axis_length=10.0 vs.xaxis=vs.arrow(pos=(-5,-5,0),axis=(axis_length,0,0),shaftwidth=0.05) vs.yaxis=vs.arrow(pos=(-5, -5, 0), axis=(0, axis_length, 0), shaftwidth=0.05) balls=[] for (i,j) in zip(N,t): balls.append(vs.sphere(pos=(((j/time)*axis_length*0.9-4.9,(i/N_O)*axis_length*0.9-4.9,0)),radius=0.2,color=vs.color.red)) vs.xlabel = vs.label(text = "time", pos = (5, -5, 0)) vs.ylabel = vs.label(text = "Number of people", pos = (-5,5,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 )
def plot3D(self): axis_length = 10.0 xaxis = vs.arrow(pos = (-5, -5, 0), axis = (axis_length, 0, 0), shaftwidth = 0.01) yaxis = vs.arrow(pos = (-5, -5, 0), axis = (0, axis_length, 0), shaftwidth = 0.01) balls = [] for (i, j) in zip(self.n_uranium, self.T): balls.append(vs.sphere(pos = ((j / self.time) * axis_length * 0.9- 4.9, (i / self.N) * axis_length * 0.9 - 4.9, 0), radius = 0.2, color = vs.color.red)) xlabel = vs.label(text = "time", pos = (5, -5, 0)) ylabel = vs.label(text = "Number of Nuclei", pos = (-5, 5, 0)) while 1: pass
def frame_rel(self,frame_rel,*args): if len(args)==1: scale = args[0] else: if frame_rel == None: scale = 1 else: scale = frame_rel.axis.scale visible = self.visible visible_label = self.visible_label visible_frame = self.axis.visible visible_frame_label = self.axis.visible_label color = self.color self.visible = False del self.__frame_rel del self.__frame_obj if frame_rel == None: self.__frame_rel = None self.__frame_obj = visual.frame(dis=self.__dis,visible=visible) else: self.__frame_rel = frame_rel self.__frame_obj = visual.frame(frame=self.__frame_rel.__frame_obj,pos=self.__dis,visible=visible) self.__frame_obj.axis = self.__rot[:,0] self.__frame_obj.up = self.__rot[:,1] self.__point_obj = visual.points(frame=self.__frame_obj,pos=(0,0,0),color=color,size=4,size_units="pixels",shape="round") self.__label_obj = visual.label(frame=self.__frame_obj,text=self.__label,visible=visible_label, pos=(0,0,0),xoffset=5*scale,yoffset=1*scale,space=5*scale,line=0,height=16*scale,border=0,font='sans',color=color,box=False,opacity=0) self.axis = axes(frame_obj=self.__frame_obj,visible=visible_frame,visible_label=visible_frame_label,scale=scale)
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 __init__(self, zoom=False, center=(0, 0, 0), title="Adolphus Viewer"): """\ Constructor. @param zoom: Toggle user zoom enable. @type zoom: C{bool} @param center: Location of the center point. @type center: C{tuple} of C{float} """ super(Display, self).__init__( title=title, center=center, background=(1, 1, 1), foreground=(0.3, 0.3, 0.3), visible=False ) self.forward = (-1, -1, -1) self.up = (0, 0, 1) self.userzoom = zoom self.range = 1500 self.rmin = 30 self.rmax = 18000 self.message_time = 0 self._stored_view = None # command/message box self._messagebox = visual.label( pos=center, background=(0, 0, 0), height=int(VISUAL_SETTINGS["textsize"] * 1.5), color=(1, 1, 1), visible=False, )
def processClick(event): global seltile, tlabel try: # Key pressed: s = event.key if s == 'c': for ob in simplist: ob.visible = False for ob in complist: ob.visible = True elif s == 's': for ob in complist: ob.visible = False for ob in simplist: ob.visible = True except AttributeError: # Mouse clicked: clickedpos = event.pickpos # The 3D position on the surface of the object clicked on if clickedpos: visual.scene.center = clickedpos # Change the camera centre position ob = event.pick try: name = ob.name if seltile is not None: seltile.color = color.green tlabel.visible = False del tlabel seltile = ob seltile.color = color.red tlabel = visual.label(pos=(seltile.pos.x, seltile.pos.y, seltile.pos.z + 10), text=name, height=10) except AttributeError: pass
def plot3D(self): axis_length = 10.0 xaxis = vs.arrow(pos=(-5, -5, 0), axis=(axis_length, 0, 0), shaftwidth=0.01) yaxis = vs.arrow(pos=(-5, -5, 0), axis=(0, axis_length, 0), shaftwidth=0.01) balls = [] for (i, j) in zip(self.x, self.T): balls.append( vs.sphere(pos=((j / self.time) * axis_length * 0.9 - 4.9, (i / self.v) * axis_length * 0.9 - 4.9, 0), radius=0.2, color=vs.color.red)) xlabel = vs.label(text="Time/s", pos=(5, -5, 0)) ylabel = vs.label(text="Displacement/m", pos=(-5, 5, 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)
def setlabel(self, txt,visible=None): if self.label is not None: if visible is None: visible = self.label.visible self.label.visible = 0 elif visible is None: visible=0 self.label=visual.label(text=txt, pos=self.pos, space=self.radius, xoffset=10, yoffset=20, visible=visible)
def show(self): if self.__repr == 'sphere': self.__reprObj = visual.sphere(pos=self.__pos, \ radius=RADIUS, color=self.__color) elif self.__repr == 'label': self.__reprObj = visual.label(pos=self.__pos, \ text=self.__label, color=self.__color) self.__reprObj.linecolor = self.__color
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 plate(self): if (self.container): for obj in self.container.objects: obj.visible = 0 self.container = visual.frame() field_length = self.length() + 2*self.config['display']['radius'] field_width = 3*self.config['display']['radius']*self.count + 10 if (self.ordered): init = self.conns[0].obj[self.orderby] pborder = 0 t = -1 i = 0 for conn in self.conns: if (init != conn.obj[self.orderby]): if ((i % 2) == 1): bcolor = self.config['colors']['box_light'] else: bcolor = self.config['colors']['box'] if type(init) == (type(1)): labeltext = self.orderby + "\n%d" % (init) elif type(init) == (type('str')): labeltext = self.orderby + "\n'%s'" % (init) visual.box(frame=self.container, pos=(field_length/2 - self.level, -(self.config['display']['radius']+1), 3*self.config['display']['radius']*t/2+self.config['display']['radius'] + pborder/2), \ width = (3*self.config['display']['radius']*t - pborder), length = field_length, height = 1, color = bcolor) visual.label(frame=self.container, pos = (self.config['display']['radius'] -self.level, 0, 3*self.config['display']['radius']*t/2+self.config['display']['radius'] + pborder/2),\ yoffset = 4*self.config['display']['radius'], xoffset = -4* self.config['display']['radius'],text = labeltext) pborder = 3*self.config['display']['radius']*t+self.config['display']['radius'] init = conn.obj[self.orderby] i += 1 t += 1 if type(init) == (type(1)): labeltext = self.orderby + "\n%d" % (init) elif type(init) == (type('str')): labeltext = self.orderby + "\n'%s'" % (init) if ((i % 2) == 1): bcolor = self.config['colors']['box_light'] else: bcolor = self.config['colors']['box'] visual.box(frame=self.container, pos=(field_length/2 - self.level, -(self.config['display']['radius']+1), 3*self.config['display']['radius']*t/2+self.config['display']['radius'] + pborder/2), \ width = (3*self.config['display']['radius']*t - pborder), length = field_length, height = 1, color = bcolor) visual.label(frame=self.container, pos = (self.config['display']['radius'] - self.level, 0, 3*self.config['display']['radius']*t/2+self.config['display']['radius'] + pborder/2),\ yoffset = 4*self.config['display']['radius'], xoffset = -4* self.config['display']['radius'], text = labeltext) else: visual.box(frame=self.container, pos = (field_length/2 - self.level, -(self.config['display']['radius']+1),field_width/2), width = field_width, length = field_length, height = 1, color = self.config['colors']['box']) desctext = 'From %s to %s\n' % (time.strftime("%F %H:%M:%S", time.localtime(self.starttime)), \ time.strftime("%F %H:%M:%S", time.localtime(self.endtime))) desctext += self.build_str_filter(" and ", "Filtering on ") visual.label(frame=self.container, pos = (field_length/2 - self.level, self.config['display']['radius']+0.5,0), yoffset = 4*self.config['display']['radius'], text = desctext) for i in range(self.config['display']['graduation']): visual.curve(frame=self.container, pos=[(field_length/self.config['display']['graduation']*i - self.level, -(self.config['display']['radius']+1)+1,0), (field_length/self.config['display']['graduation']*i - self.level,-(self.config['display']['radius']+1)+1,field_width)]) for i in range(self.config['display']['graduation']/self.config['display']['tick']+1): ctime = time.strftime("%H:%M:%S", time.localtime(self.mintime + field_length/self.config['display']['graduation']*self.config['display']['tick']*i)) visual.label(frame=self.container, pos=(field_length/self.config['display']['graduation']*self.config['display']['tick']*i - self.level, -(self.config['display']['radius']+1)+1,0), text = '%s' % (ctime), border = 5, yoffset = 1.5*self.config['display']['radius'])
def plot3D(): axis_length = 10.0 vs.xaxis = vs.arrow(pos=(-5, -5, 0), axis=(axis_length, 0, 0), shaftwidth=0.05) vs.yaxis = vs.arrow(pos=(-5, -5, 0), axis=(0, axis_length, 0), shaftwidth=0.05) balls = [] for (i, j) in zip(N, t): balls.append( vs.sphere(pos=(((j / time) * axis_length * 0.9 - 4.9, (i / N_O) * axis_length * 0.9 - 4.9, 0)), radius=0.2, color=vs.color.red)) vs.xlabel = vs.label(text="time", pos=(5, -5, 0)) vs.ylabel = vs.label(text="Number of people", pos=(-5, 5, 0))
def f(alfa, v0): vel_fotogramas = 25 g = 9.81 v0x = v0 * np.cos(np.deg2rad(alfa)) v0z = v0 * np.sin(np.deg2rad(alfa)) t_total = 2 * v0z / g x_final = v0x * t_total suelo = vs.box(pos=(x_final / 2., -1, 0), size=(x_final, 1, 10), color=vs.color.green) canyon = vs.cylinder(pos=(0, 0, 0), axis=(2 * np.cos(np.deg2rad(alfa)), 2 * np.sin(np.deg2rad(alfa)), 0)) bola = vs.sphere(pos=(0, 0, 0)) bola.trail = vs.curve(color=bola.color) flecha = vs.arrow(pos=(0, 0, 0), axis=(v0x, v0z, 0), color=vs.color.yellow) labelx = vs.label(pos=bola.pos, text='posicion x = 0 m', xoffset=1, yoffset=80, space=bola.radius, font='sans', box=False, height=10) labely = vs.label(pos=bola.pos, text='posicion y = 0 m', xoffset=1, yoffset=40, space=bola.radius, font='sans', box=False, height=10) t = 0 while t <= t_total: bola.pos = (v0x * t, v0z * t - 0.5 * g * t**2, 0) flecha.pos = (v0x * t, v0z * t - 0.5 * g * t**2, 0) flecha.axis = (v0x, v0z - g * t, 0) bola.trail.append(pos=bola.pos) labelx.pos = bola.pos labelx.text = 'posicion x = %s m' % str(v0x * t) labely.pos = bola.pos labely.text = 'posicion y = %s m' % str(v0z * t - 0.5 * g * t**2) t = t + t_total / 100. vs.rate(vel_fotogramas) return x_final
def set_label(self): txtlabel = '' if (self.config['display']['extended_label'] != 0): if (self.obj["orig_ip_protocol"] in (6, 17)): txtlabel = 'ORIG SRC: %s:%d\n DST: %s:%d\nREPL SRC: %s:%d\n DST: %s:%d\n' % (self.obj["orig_ip_saddr_str"], self.obj["orig_l4_sport"], self.obj["orig_ip_daddr_str"], self.obj["orig_l4_dport"] ,\ self.obj["reply_ip_saddr_str"], self.obj["reply_l4_sport"], self.obj["reply_ip_daddr_str"], self.obj["reply_l4_dport"]) elif (self.obj["orig_ip_protocol"] == 1): txtlabel = 'ORIG SRC: %s\n DST: %s\nREPL SRC: %s\n DST: %s\nCODE: %d TYPE: %d\n' % (self.obj["orig_ip_saddr_str"], \ self.obj["orig_ip_daddr_str"], self.obj["reply_ip_saddr_str"], \ self.obj["reply_ip_daddr_str"], self.obj["icmp_code"], self.obj["icmp_type"]) else: txtlabel = 'ORIG SRC: %s\n DST: %s\nREPL SRC: %s\n DST: %s\n' % ( self.obj["orig_ip_saddr_str"], self.obj["reply_ip_saddr_str"], self.obj["orig_ip_daddr_str"], self.obj["reply_ip_daddr_str"]) else: if (self.obj["orig_ip_protocol"] in (6, 17)): txtlabel = 'SRC: %s:%d\nDST: %s:%d\n' % ( self.obj["orig_ip_saddr_str"], self.obj["orig_l4_sport"], self.obj["orig_ip_daddr_str"], self.obj["orig_l4_dport"]) else: txtlabel = 'SRC: %s\nDST: %s\n' % ( self.obj["orig_ip_saddr_str"], self.obj["orig_ip_daddr_str"]) if (self.obj["orig_ip_protocol"] == 6): txtlabel += 'PROTO: TCP' elif (self.obj["orig_ip_protocol"] == 17): txtlabel += 'PROTO: UDP' elif (self.obj["orig_ip_protocol"] == 1): txtlabel += 'PROTO: ICMP' if (self.obj["ct_event"] == 1): self.label = visual.label(pos=self.pos, xoffset=-10, yoffset=10, text='%s' % (txtlabel)) elif (self.obj["ct_event"] == 4): self.label = visual.label( pos=self.pos, xoffset=-10, yoffset=10, text='%s\nIN: %d, OUT: %d bits\nDURATION: %f sec' % (txtlabel, self.obj["reply_raw_pktlen"], self.obj["orig_raw_pktlen"], self.axis.x)) self.label.visible = 0
def draw_axes(self): # scene.forward = (0, 0, -1) # Default view direction zero = (0, 0, 0) x_direction = (5, 0, 0) y_direction = (0, 5, 0) z_direction = (0, 0, 5) # Axis X pointerX = arrow(pos=zero, axis=x_direction, shaftwidth=0.5, color=color.red) labelX = label(pos=x_direction, text='X') # Axis Y pointerY = arrow(pos=zero, axis=y_direction, shaftwidth=0.5, color=color.blue) labelY = label(pos=y_direction, text='Y') # Axis Z pointerZ = arrow(pos=zero, axis=z_direction, shaftwidth=0.5, color=color.yellow) labelZ = label(pos=z_direction, text='Z')
def phase_3(self): while time.time() - self.start_time <= self.time: self.falling.pos = (0, -self.time * 1.1, 0) self.falling.axis = (0, 1, 0) self.falling.length = (self.time - time.time() + self.start_time) * 12.5 self.countdown.label = str(self.start_time + self.time - time.time()) + " seconds left" self.falling.visible = 0 self.countdown.visible = 0 end = label(pos=(0, self.time * 1.5, 0), text="End")
def __init__(self, index, name, colors, mRNA, protein, P0, P1, P2): self.index = index self.name = name self.pos = (index, 0, 0) self.color = colors[index] self.mRNA_amt = mRNA self.protein_amt = protein self.P0_amt = P0 self.P1_amt = P1 self.P2_amt = P2 self.f = v.frame() j = (index + 1) % 3 self.P0 = v.cylinder(display=v.scene, frame=self.f, pos=(-0.1, -1, 0), axis=(0, 0, 1), radius=SCALE * math.sqrt(PROMOTER_FACTOR), length=self.P0_amt * math.sqrt(PROMOTER_FACTOR), color=colors[j]) self.P1 = v.cylinder(display=v.scene, frame=self.f, pos=(0.0, -1, 0), axis=(0, 0, 1), radius=SCALE * math.sqrt(PROMOTER_FACTOR), length=self.P1_amt * math.sqrt(PROMOTER_FACTOR), color=colors[j]) self.P2 = v.cylinder(display=v.scene, frame=self.f, pos=(0.1, -1, 0), axis=(0, 0, 1), radius=SCALE * math.sqrt(PROMOTER_FACTOR), length=self.P2_amt * math.sqrt(PROMOTER_FACTOR), color=colors[j]) self.m = v.cylinder(display=v.scene, frame=self.f, pos=(0, 0, 0), axis=(0, 0, 1), radius=SCALE * math.sqrt(RNA_FACTOR), length=self.mRNA_amt / RNA_FACTOR, color=self.color) self.p = v.cylinder(display=v.scene, frame=self.f, pos=(0, 1, 0), axis=(0, 0, 1), radius=SCALE * math.sqrt(PROTEIN_FACTOR), length=self.protein_amt / PROTEIN_FACTOR, color=self.color) self.lab = v.label(frame=self.f, text=self.name, pos=(0, -1.5, 0), height=100, color=self.color, box=0, font='helvetica') self.f.pos = self.pos self.f.axis = (1, 0, 0)
def main2(): thickness = 0.001 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=thickness, height=thickness, color=visual.color.red, opacity=0.5) axisy = visual.box(pos=(0,0,0), axis=(0,10.0,0), width=thickness, height=thickness, color=visual.color.blue, opacity=0.5) axisz = visual.box(pos=(0,0,0), axis=(0,0,10.0), width=thickness, height=thickness, color=visual.color.green, opacity=0.5) 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") #histogram = Hist3D("/home/cory/Research/vikar311/detectors/7BeExp.det","/home/cory/Research/vikar311/source/rewrite/VIKARoutput.dat") #RawRead("/home/cory/Research/VANDLE/Vikar/test.out", 2) #VBars = DetRead("/home/cory/Research/Vikar/detectors/default.det") while True: visual.rate(60) if labScene.kb.keys: s_ = labScene.kb.getkey() if(s_ == "esc"): wx.Exit()
def plot3D(self): axis_length = 10.0 xaxis = vs.arrow(pos=(-5, -5, 0), axis=(axis_length, 0, 0), shaftwidth=0.01) yaxis = vs.arrow(pos=(-5, -5, 0), axis=(0, axis_length, 0), shaftwidth=0.01) balls = [] for (i, j) in zip(self.N, self.t): balls.append( vs.sphere(pos=((j / self.time) * axis_length * 0.9 - 4.9, (i / self.N) * axis_length * 0.9 - 4.9, 0), radius=0.2, color=vs.color.red)) xlabel = vs.label(text="time[s]", pos=(5, -5, 0)) ylabel = vs.label(text="Population", pos=(-5, 5, 0)) while 1: pass
def __init__(self): self.ChannelList = [] self.NodeList = [] print 'Start visualising' self.ChnLabel = v.label(pos=(0, 0, 0), color=v.color.green) for i in range(len(Network.Nodes)): MacInQueue = [] MacOutQueue = [] self.NodeList.append([MacInQueue, MacOutQueue])
def AddToQueue(self, ID, In): InOut = 1 if In == True: InOut = 0 priorSquare = 0 if len(self.NodeList[ID][InOut]) > 0: print 'here' priorSquare = self.NodeList[ID][InOut][-1].pos[1] newY = priorSquare + 5 label = v.label(pos=(ID*2+InOut, newY, 0), text=str(ID), color=v.color.green) self.NodeList[ID][InOut].append(label)
def __init__(self): self.ChannelList = [] self.NodeList = [] print 'Start visualising' self.ChnLabel = v.label(pos=(0,0,0), color=v.color.green) for i in range(len(Network.Nodes)): MacInQueue = [] MacOutQueue = [] self.NodeList.append([MacInQueue, MacOutQueue])
def __init__(self, v_auf, v_orient, txt, p, *args, **kwargs): super(Vector_stat, self).__init__(*args, **kwargs) self.p = p if not v_auf == 0: x1 = get_v_arg(v_auf,0)*self.p y1 = get_v_arg(v_auf,1)*self.p z1 = get_v_arg(v_auf,2)*self.p else: x1 = 0. y1 = 0. z1 = 0. x2 = get_v_arg(v_orient,0)*self.p y2 = get_v_arg(v_orient,1)*self.p z2 = get_v_arg(v_orient,2)*self.p self.x = x1 self.y = y1 self.z = z1 self.axis = (x2,y2,z2) vis.label(pos=(x1+x2-0.75, y1+y2-0.75,z1+z2-0.75), text=txt)
def __init__(self): self.sphereList = [] #sphere for each node self.rodList = [] #unused self.manageRodList = [] #rods connecting nodes to centre management node r = 1.0 #radius of circle that nodes are in delta_theta = (2.0*math.pi) / G.NUMNODES #angle between nodes theta = 0 self.management = v.sphere(pos=v.vector(0,0,0), radius=0.1, colour=v.color.blue) #management node in centre self.label = v.label(pos=(1,1,0), text= '0') #label for amount of disparities at that point in time self.label_cum = v.label(pos=(-1,1,0), text= '0') #cumulative total number of above for i in range(0,G.NUMNODES): circ = v.sphere(pos=v.vector(r*math.cos(theta),r*math.sin(theta),0), radius=0.1, color=v.color.green) self.sphereList.append(circ) print 'circle no. ', i, ' coords ', r*math.cos(theta), ' ', r*math.sin(theta) theta += delta_theta rod = v.cylinder(pos=(0,0,0),axis=(self.sphereList[i].pos), radius=0.005, color=v.color.white) self.manageRodList.append(rod)
def set_scene(R): # draw scene, ball, trails, spin, info box scene = vp.display(background=(.2,.5,1), forward=(-1,-.1,-.1), center=(.5*R,1,0), ambient=.4, fullscreen=1) floor = vp.box(pos=(R/2,0,0), length=1.1*R, height=.1, width=8, color=vp.color.orange, opacity=0.7) # transparent zone = vp.curve(pos=[(R,0,1),(R,1,1),(R,1,-1),(R,0,-1)], radius=.02) ball = vp.sphere(pos=(0,0,0), radius=.2, material=vp.materials.rough) trail = vp.curve(pos=(0,0,0), radius=0.04) ideal = vp.curve(pos=(0,0,0), radius=0.04, color=vp.color.green) spin = vp.arrow(axis=omega,pos=(0,0,0),length=1) # omega dir info = vp.label(pos=(1.1*R,2,-2),text='Any key=repeat') return scene, ball, trail, ideal, spin
def phase_3(self): while (time.time() - self.start_time <= self.time): self.falling.pos = (0, -self.time * 1.1, 0) self.falling.axis = (0, 1, 0) self.falling.length = ( (self.time - time.time() + self.start_time) * 12.5) self.countdown.label = ( str(self.start_time + self.time - time.time()) + ' seconds left') self.falling.visible = 0 self.countdown.visible = 0 end = label(pos=(0, self.time * 1.5, 0), text='End')
def __init__(self, v_auf, v_orient, txt, p, *args, **kwargs): super(Vector_stat, self).__init__(*args, **kwargs) self.p = p if not v_auf == 0: x1 = get_v_arg(v_auf, 0) * self.p y1 = get_v_arg(v_auf, 1) * self.p z1 = get_v_arg(v_auf, 2) * self.p else: x1 = 0. y1 = 0. z1 = 0. x2 = get_v_arg(v_orient, 0) * self.p y2 = get_v_arg(v_orient, 1) * self.p z2 = get_v_arg(v_orient, 2) * self.p self.x = x1 self.y = y1 self.z = z1 self.axis = (x2, y2, z2) vis.label(pos=(x1 + x2 - 0.75, y1 + y2 - 0.75, z1 + z2 - 0.75), text=txt)
def AddToQueue(self, ID, In): InOut = 1 if In == True: InOut = 0 priorSquare = 0 if len(self.NodeList[ID][InOut]) > 0: print 'here' priorSquare = self.NodeList[ID][InOut][-1].pos[1] newY = priorSquare + 5 label = v.label(pos=(ID * 2 + InOut, newY, 0), text=str(ID), color=v.color.green) self.NodeList[ID][InOut].append(label)
def set_scene(r): # r = init position of planet # draw scene, mercury, sun, info box, Runge-Lenz vector scene = vp.display(title='Precession of Mercury', center=(.1*0,0), background=(.2,.5,1)) planet= vp.sphere(pos=r, color=(.9,.6,.4), make_trail=True, radius=0.05, material=vp.materials.diffuse) sun = vp.sphere(pos=(0,0), color=vp.color.yellow, radius=0.02, material=vp.materials.emissive) sunlight = vp.local_light(pos=(0,0), color=vp.color.yellow) info = vp.label(pos=(.3,-.4), text='Angle') # angle info RLvec = vp.arrow(pos=(0,0), axis=(-1,0,0), length = 0.25) return planet, info, RLvec
def PlotElevator(filename): try: f = open(filename,'r') data = json.loads(f.read()) f.close() except Exception as e: return str(e) print(data["L0"]) pos = [] for i in range(data["SavedSteps"]): if not None in [elem for s1 in data["Position"][i] for elem in s1]: pos.append(data["Position"][i]) else: break pos = array(pos) vel = array(data["Velocity"]) scene = vs.display(title='3D representation', x=500, y=0, width=1920, height=1080, background=(0,0,0), center=pos[0][-1]) string = vs.curve(pos=pos[0], radius=50) earth = vs.sphere(radius=R_earth_equator) asteroid = vs.sphere(pos=pos[0][-1],radius=1e3, color=vs.color.red) anchor = vs.sphere(pos=pos[0][0],radius=1e2, color=vs.color.green) label_avg_l0 = vs.label(pos=pos[0][-1], text="t: %3.1f" % (data["Time"][0],)) body = 1 nt = 0 while True: vs.rate(60) if scene.kb.keys: # event waiting to be processed? s = scene.kb.getkey() # get keyboard info if s == "d": if body == -1: body = 0 elif body == 0: body = 1 else: body = -1 if body == 1: scene.center = (0,0,0) else: scene.center = pos[nt][body] string.pos=pos[nt] asteroid.pos=pos[nt][-1] anchor.pos=pos[nt][0] label_avg_l0.pos = asteroid.pos label_avg_l0.text = "t: %3.1f" % (data["Time"][nt],) if nt + 1 >= pos.shape[0]: nt = 0 else: nt += 1
def input(self, data): fft = data['fft'] if (len(self.curves) > self.maxlen): todel = self.curves.pop() todel.visible = False del todel for oldcurve in self.curves: for point in range(len(oldcurve.pos)): oldcurve.pos[point][2] -= self.step y = [] for point in fft: y.append(point) y.append(point) curve = visual.curve(color=visual.color.white, display=self.g, radius=0) if data.has_key('dominantbucket'): dominant = data['dominantbucket'] else: dominant = False if (self.lastdominant != dominant and self.label): self.label.visible = False del self.label self.label = False for point in zip(range(len(fft)), fft): if dominant and (point[0] + 2) > dominant and (point[0] - 2) < dominant: r = 1 g = 0 b = 0 if (self.lastdominant != dominant and dominant == point[0]): self.label = visual.label(pos=(point[0], 10, 0), text=str(data['note']), xoffset=20, yoffset=12, height=10, border=6, font='sans') else: r = g = b = point[1] / 3 curve.append(pos=(point[0], point[1], 0), color=(r, g, b)) self.lastdominant = dominant self.curves.insert(0, curve)
def __init__(self, background=None, ambient=None, show_axis=True): super(Visualiser, self).__init__() if not VISUAL_INSTALLED: return if background is None: background = (0.957, 0.957, 1) if ambient is None: ambient = 0.5 self.display = visual.display(title='PVTrace', x=0, y=0, width=800, height=600, background=background, ambient=ambient) self.display.bind('keydown', self.keyInput) self.display.exit = False self.display.center = (0.025, 0.015, 0) self.display.forward = (0, 0.83205, -0.5547) show_axis = False if show_axis: visual.curve(pos=[(0, 0, 0), (.08, 0, 0)], radius=0.0005, color=visual.color.red) visual.curve(pos=[(0, 0, 0), (0, .07, 0)], radius=0.0005, color=visual.color.green) visual.curve(pos=[(0, 0, 0), (0, 0, .08)], radius=0.0005, color=visual.color.blue) visual.label(pos=(.09, 0, 0), text='X', background=visual.color.red, linecolor=visual.color.red) visual.label(pos=(0, .08, 0), text='Y', background=visual.color.green, linecolor=visual.color.green) visual.label(pos=(0, 0, .07), text='Z', background=visual.color.blue, linecolor=visual.color.blue)
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))
def __init__(self,frame_obj,visible=True,visible_label=True,scale=1.0): x_red = visual.color.darkerred #(1,0.2,0.2) y_green = visual.color.darkergreen #(0.2,1,0.2) z_blue = visual.color.darkerblue #(0.2,0.2,1) label_color = visual.color.fainttext #(0.7,0.7,0.7) self.__scale = scale al = self.__scale # arrow length sw = self.__scale*0.01 # shaftwidth hw = self.__scale*0.03 # headwidth hl = self.__scale*0.05 # headlength self.__frame_obj = frame_obj self.__frame_axis_obj = visual.frame(frame=self.__frame_obj,pos=(0,0,0),visible=visible) self.__frame_axis_label_obj = visual.frame(frame=self.__frame_axis_obj,pos=(0,0,0),visible=visible_label) self.__x_axis_obj = visual.arrow(frame=self.__frame_axis_obj,pos=(0,0,0),axis=(al,0,0),shaftwidth=sw,headwidth=hw,headlength=hl,color=x_red) self.__x_axis_label_obj = visual.label(frame=self.__frame_axis_label_obj,pos=(al,0,0),xoffset=1,font='sans',text="x",box=False,opacity=0,border=0,line=0,height=10*scale,color=label_color) self.__y_axis_obj = visual.arrow(frame=self.__frame_axis_obj,pos=(0,0,0), axis=(0,al,0),shaftwidth=sw,headwidth=hw,headlength=hl,color=y_green) self.__y_axis_label_obj = visual.label(frame=self.__frame_axis_label_obj,pos=(0,al,0),xoffset=1,font='sans',text="y",box=False,opacity=0,border=0,line=0,height=10*scale,color=label_color) self.__z_axis_obj = visual.arrow(frame=self.__frame_axis_obj,pos=(0,0,0), axis=(0,0,al), shaftwidth=sw,headwidth=hw,headlength=hl,color=z_blue) self.__z_axis_label_obj = visual.label(frame=self.__frame_axis_label_obj,pos=(0,0,al),xoffset=1,font='sans',text="z",box=False,opacity=0,border=0,line=0,height=10*scale,color=label_color)
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 setRepr(self, repr): self.display.select() self.__reprstr = repr if self.__repr is not None: self.__repr.visible = False if repr == 'sphere': if self.display.range.x/self.display.w < 1: RADIUS = 1 else: RADIUS = self.display.range.x/self.display.w self.__repr = visual.sphere(pos=self.__vpos, radius=RADIUS, color=self.__color) else: self.__repr = visual.label(pos=self.__vpos, text=self.__label, color=self.__color) self.__repr.linecolor = self.__color
def __init__(self, background=(0,0,0), ambient=1.): super(Visualiser, self).__init__() if not VISUAL_INSTALLED: return self.display = visual.display(title='PVTrace', x=0, y=0, width=800, height=600, background=(0.957, 0.957, 1), ambient=0.5) self.display.exit = False visual.curve(pos=[(0,0,0), (.2,0,0)], radius=0.001, color=visual.color.red) visual.curve(pos=[(0,0,0), (0,.2,0)], radius=0.001, color=visual.color.green) visual.curve(pos=[(0,0,0), (0,0,.2)], radius=0.001, color=visual.color.blue) visual.label(pos=(.22, 0, 0), text='X', linecolor=visual.color.red) visual.label(pos=(0, .22, 0), text='Y', linecolor=visual.color.green) visual.label(pos=(0, 0, .22), text='Z', linecolor=visual.color.blue)
def set_scene(r): # r = init position of planet # draw scene, mercury, sun, info box, Runge-Lenz vector scene = vp.display(title='Precession of Mercury', center=(.1 * 0, 0), background=(.2, .5, 1)) planet = vp.sphere(pos=r, color=(.9, .6, .4), make_trail=True, radius=0.05, material=vp.materials.diffuse) sun = vp.sphere(pos=(0, 0), color=vp.color.yellow, radius=0.02, material=vp.materials.emissive) sunlight = vp.local_light(pos=(0, 0), color=vp.color.yellow) info = vp.label(pos=(.3, -.4), text='Angle') # angle info RLvec = vp.arrow(pos=(0, 0), axis=(-1, 0, 0), length=0.25) return planet, info, RLvec
def __init__(self, pos=vp.vector(0, 0, 0), axis=vp.vector(0, 1.0, 0), value=None, width=0.15, min_val=0, max_val=100., color=(1, 0, 0)): pos = vp.vector(pos) # axis = vector(axis) if value == None: value = min_val self.min = min_val self.max = max_val self.value = value self.shaft = vp.cylinder(pos=pos, axis=axis, radius=width/4.0, color=GREY) self.start = pos self.axis = axis self.control = vp.sphere( pos=self.start+(self.min+value)/(self.max-self.min)*self.axis, radius=width/2., color=color) self.label = vp.label(pos=self.control.pos, text="%0.2f" % value, opacity=0, box=0, line=0)
def set_scene(R): # draw scene, ball, trails, spin, info box scene = vp.display(background=(.2, .5, 1), forward=(-1, -.1, -.1), center=(.5 * R, 1, 0), ambient=.4, fullscreen=1) floor = vp.box(pos=(R / 2, 0, 0), length=1.1 * R, height=.1, width=8, color=vp.color.orange, opacity=0.7) # transparent zone = vp.curve(pos=[(R, 0, 1), (R, 1, 1), (R, 1, -1), (R, 0, -1)], radius=.02) ball = vp.sphere(pos=(0, 0, 0), radius=.2, material=vp.materials.rough) trail = vp.curve(pos=(0, 0, 0), radius=0.04) ideal = vp.curve(pos=(0, 0, 0), radius=0.04, color=vp.color.green) spin = vp.arrow(axis=omega, pos=(0, 0, 0), length=1) # omega dir info = vp.label(pos=(1.1 * R, 2, -2), text='Any key=repeat') return scene, ball, trail, ideal, spin
def __init__(self, skeleton, motion, scene=None): self.skeleton = skeleton self.motion = motion self.bone_data = dict() self.framerate = None self.title = 'amcparser %s' % (self.motion.filename) if not scene: self.scene = visual_common.create_display.display(title=self.title, width=640, height=480, center=(0, 0, 0), forward=(-2, -2, -1)) else: self.scene = scene self.window_id = None self.gif_frames = list() self._frameno = visual.label(pos=(-6, -0, 0), text='0') self._create_floor() self._axes = Axes([1.0, 0, 0], [0, 1, 0], [0, 0, 1], 0.5)
def __init__(self,dis=np.zeros((3,1)),rot=np.eye(3),label="",frame_rel=None,color=visual.color.text, visible=True,visible_frame=True,visible_label=True,visible_frame_label=True,scale=1.0): self.__dis = np.array(dis).reshape(3,1) self.__rot = np.array(rot).reshape(3,3) self.__hom = np.vstack((np.hstack((self.__rot,self.__dis)),np.array([0,0,0,1]))) self.__hom_inv = np.vstack((np.hstack((self.__rot.T,-np.dot(self.__rot.T,self.__dis))),np.array([0,0,0,1]))) self.__label = label self.__color = color if frame_rel == None: self.__frame_rel = None self.__frame_obj = visual.frame(pos=self.__dis,visible=visible) else: self.__frame_rel = frame_rel self.__frame_obj = visual.frame(frame=self.__frame_rel.__frame_obj,pos=self.__dis,visible=visible) self.__frame_obj.axis = self.__rot[:,0] self.__frame_obj.up = self.__rot[:,1] self.__point_obj = visual.points(frame=self.__frame_obj,pos=(0,0,0),color=color,size=4,size_units="pixels",shape="round") self.__label_obj = visual.label(frame=self.__frame_obj,text=self.__label,visible=visible_label, pos=(0,0,0),xoffset=5*scale,yoffset=1*scale,space=5*scale,line=0,height=16*scale,border=0,font='sans',color=color,box=False,opacity=0) self.axis = axes(frame_obj=self.__frame_obj,visible=visible_frame,visible_label=visible_frame_label,scale=scale)
accel += Q[i] * (Y[0] - loc[i]) / (vp.mag(Y[0] - loc[i]))**3 return [Y[1], q * accel] # list for non-vectorized solver a, b, w = 1., 0.5, 0.125 # rink size, goal width q, qcor, qmid, qcen = -1.0, 1.0, -2., 2. # Qs: puck, cor., mid, cen. Q = [qcor, qmid, qcor, qcor, qmid, qcor, qcen] # charges, locations loc = [[-a, b], [0, b], [a, b], [a, -b], [0, -b], [-a, -b], [0, 0]] scene = vp.display(title='Electric hockey', background=(.2, .5, 1)) puck = vp.sphere(pos=(-a, 0, 0), radius=0.05, make_trail=True) # trail rink = vp.curve(pos=loc[:-1] + [loc[0]], radius=0.01) # closed curve goalL = vp.curve(pos=[(-a, w, 0), (-a, -w, 0)], color=(0, 1, 0), radius=.02) goalR = vp.curve(pos=[(a, w, 0), (a, -w, 0)], color=(0, 1, 0), radius=.02) for i in range(len(loc)): # charges, red if Q>0, blue if Q<0 color = (1, 0, 0) if Q[i] > 0 else (0, 0, 1) vp.sphere(pos=loc[i], radius=0.05, color=color) v, theta = input('enter speed, theta; eg, 2.2, 19:') # try 2.2, 18.5 v, theta = min(4, v), max(1, theta) * np.pi / 180. # check valid input Y = np.array([[-a, 0], [v * np.cos(theta), v * np.sin(theta)]]) while True: vp.rate(200) Y = ode.RK45n(hockey, Y, t=0., h=0.002) x, y = Y[0][0], Y[0][1] if (abs(x) > a or abs(y) > b): txt = 'Goal!' if (x > 0 and abs(y) < w) else 'Miss!' vp.label(pos=(x, y + .2), text=txt, box=False) break puck.pos = Y[0]
canyon = vs.cylinder(pos=(0, 0, 0), axis=(2 * np.cos(alfa), 2 * np.sin(alfa), 0), size=(0, 0, 0, 0)) ## Creamos el proyectil y una linea que dejara la estela del proyectil bola = vs.sphere(pos=(0, 0, 0), radius=0.5, color=vs.color.magenta) bola.trail = vs.curve(color=vs.color.cyan) ## Creamos el vector que indica la direccion del movimiento (vector velocidad) flecha = vs.arrow(pos=(0, 0, 0), axis=(v0x, v0z, 0), color=vs.color.yellow, size=(0)) ## texto (ponemos etiquetas para informar de la posicion del proyectil) labelx = vs.label(pos=bola.pos, text='posicion x = 0 m', xoffset=1, yoffset=80, space=bola.radius, font='sans', box=False, height=10) labely = vs.label(pos=bola.pos, text='posicion y = 0 m', xoffset=1, yoffset=40, space=bola.radius, font='sans', box=False, height=10) ## Animamos todo el cotarro!!! t = 0 while t <= t_total: bola.pos = (v0x * t, v0z * t - 0.5 * g * t**2, 0)
def __init__(self, windowTitle): # Main scene self.scene = visual.display(title=windowTitle) self.scene.range = (1.2, 1.2, 1.2) #self.scene.forward = (0,-1,-0.25) self.scene.forward = (1, 0, -0.25) self.scene.up = (0, 0, 1) # Second scene (Roll, Pitch, Yaw) self.scene2 = visual.display(title=windowTitle, x=0, y=0, width=500, height=200, center=(0, 0, 0), background=(0, 0, 0)) self.scene2.range = (1, 1, 1) self.scene.width = 500 self.scene.y = 200 self.scene2.select() #Roll, Pitch, Yaw self.cil_roll = visual.cylinder(pos=(-0.4, 0, 0), axis=(0.2, 0, 0), radius=0.01, color=visual.color.red) self.cil_roll2 = visual.cylinder(pos=(-0.4, 0, 0), axis=(-0.2, 0, 0), radius=0.01, color=visual.color.red) self.cil_pitch = visual.cylinder(pos=(0.1, 0, 0), axis=(0.2, 0, 0), radius=0.01, color=visual.color.green) self.cil_pitch2 = visual.cylinder(pos=(0.1, 0, 0), axis=(-0.2, 0, 0), radius=0.01, color=visual.color.green) #cil_course = visual.cylinder(pos=(0.6,0,0),axis=(0.2,0,0),radius=0.01,color=visual.color.blue) #cil_course2 = visual.cylinder(pos=(0.6,0,0),axis=(-0.2,0,0),radius=0.01,color=visual.color.blue) self.arrow_course = visual.arrow(pos=(0.6, 0, 0), color=visual.color.cyan, axis=(-0.2, 0, 0), shaftwidth=0.02, fixedwidth=1) #Roll,Pitch,Yaw visual.labels visual.label(pos=(-0.4, 0.3, 0), text="Roll", box=0, opacity=0) visual.label(pos=(0.1, 0.3, 0), text="Pitch", box=0, opacity=0) visual.label(pos=(0.55, 0.3, 0), text="Yaw", box=0, opacity=0) visual.label(pos=(0.6, 0.22, 0), text="N", box=0, opacity=0, color=visual.color.yellow) visual.label(pos=(0.6, -0.22, 0), text="S", box=0, opacity=0, color=visual.color.yellow) visual.label(pos=(0.38, 0, 0), text="W", box=0, opacity=0, color=visual.color.yellow) visual.label(pos=(0.82, 0, 0), text="E", box=0, opacity=0, color=visual.color.yellow) visual.label(pos=(0.75, 0.15, 0), height=7, text="NE", box=0, color=visual.color.yellow) visual.label(pos=(0.45, 0.15, 0), height=7, text="NW", box=0, color=visual.color.yellow) visual.label(pos=(0.75, -0.15, 0), height=7, text="SE", box=0, color=visual.color.yellow) visual.label(pos=(0.45, -0.15, 0), height=7, text="SW", box=0, color=visual.color.yellow) self.L1 = visual.label(pos=(-0.4, 0.22, 0), text="-", box=0, opacity=0) self.L2 = visual.label(pos=(0.1, 0.22, 0), text="-", box=0, opacity=0) self.L3 = visual.label(pos=(0.7, 0.3, 0), text="-", box=0, opacity=0) # Main scene objects self.scene.select() # Reference axis (x,y,z) visual.arrow(color=visual.color.green, axis=(1, 0, 0), shaftwidth=0.02, fixedwidth=1) visual.arrow(color=visual.color.green, axis=(0, -1, 0), shaftwidth=0.02, fixedwidth=1) visual.arrow(color=visual.color.green, axis=(0, 0, -1), shaftwidth=0.02, fixedwidth=1) # visual.labels visual.label(pos=(0, 0, 0.8), text=windowTitle, box=0, opacity=0) visual.label(pos=(1, 0, 0), text="X", box=0, opacity=0) visual.label(pos=(0, -1, 0), text="Y", box=0, opacity=0) visual.label(pos=(0, 0, -1), text="Z", box=0, opacity=0) # IMU object self.platform = visual.box(length=1, height=0.05, width=1, color=visual.color.red) self.p_line = visual.box(length=1, height=0.08, width=0.1, color=visual.color.yellow) self.plat_arrow = visual.arrow(color=visual.color.green, axis=(1, 0, 0), shaftwidth=0.06, fixedwidth=1) self.roll = 0 self.pitch = 0 self.yaw = 0
def draw(self): self.f = visual.frame() self.vis = visual.label(frame=self.f, box=False) Primitive.draw(self)
axis=vector(a / 2, 0, 0), shaftwidth=0.01, color=color.white) arrow(pos=vector(0.6, -0.6, 1.2), axis=vector(0, a / 2, 0), shaftwidth=0.01, color=color.white) arrow(pos=vector(0.6, -0.6, 1.2), axis=vector(0, 0, a / 2), shaftwidth=0.01, color=color.white) label(pos=vector(0.5, -0.6, 1.), xoffset=-.5, yoffset=-0.5, zoffset=-.5, text='O', box=False, background=color.white, opacity=0.06, line=False) label(pos=vector(0.6 + a / 2, -0.6, 1.2), xoffset=-a / 6, yoffset=+a / 6, text='x', box=False, background=color.white, opacity=0.06, line=False) label(pos=vector(0.6, a / 2 - 0.6, 1.2), xoffset=a / 6, yoffset=a / 10,