def game_over(board, players): display_game_over(board, True) # Turn GAME OVER message on while True: received_inputs = Key_Event for event in received_inputs: if received_inputs: display_game_over(board, False) if event == 'e': # Tidy up and exits game turn_board_off(board) for player in players: for item in (player.tetromino, player.next_tetromino, player.shadow): item.updater(visible=False) text(pos=vector( int(board['width'] / 2) - 8, int(board['height'] / 2) - 3, 1), text=' Goodbye! ', height=2.5, color=color.green) exit_status = True return exit_status else: # display_game_over(board, False) # Tidy up and restart game for _ in range(board['height']): clear_line(board, 0) board['level'], board['points'] = 1, 0 show_points(board) for player in players: player.reset_game(board) player.update_shadow(board) return
def __init__(self, state,\ center=vp.vector(0,0,0),\ radius=1,\ tag=None,\ sphere_color=vp.color.blue,\ star_color=vp.color.white,\ arrow_color=None,\ show_sphere=True,\ show_stars=True,\ show_arrow=True,\ show_tag=True,\ show_tag_on_stars=False): self.n = state.shape[0] self.state = state self.center = center self.radius = radius self.tag = tag self.sphere_color = sphere_color self.star_color = star_color self.arrow_color = self.sphere_color if arrow_color == None else arrow_color self.show_sphere = show_sphere self.show_stars = show_stars self.show_arrow = show_arrow self.show_tag = show_tag self.show_tag_on_stars = show_tag_on_stars self.vsphere = vp.sphere(visible=False) self.varrow = vp.arrow(visible=False) self.vstars = [vp.sphere(visible=False) for i in range(self.n - 1)] self.vtag = vp.text(text="e", visible=False) self.vtags = [ vp.text(text="e", visible=False) for i in range(self.n - 1) ]
def __init__(self, state,\ center=None,\ radius=1,\ sphere_color=None,\ star_color=None,\ arrow_color=None,\ show_sphere=True,\ show_stars=True,\ show_arrow=True,\ show_tag=False,\ show_tag_on_stars=False,\ star_radius=0.1,\ tag="e"): self.star_radius = star_radius self.n = state.shape[0] self.state = state self.energy = None self.evolving = False self.center = center if center else vp.vector(0, 0, 0) self.radius = radius self.sphere_color = sphere_color if sphere_color != None else vp.color.blue self.star_color = star_color if star_color != None else vp.color.white self.arrow_color = self.sphere_color if arrow_color == None else arrow_color self.show_sphere = show_sphere self.show_stars = show_stars self.show_arrow = show_arrow self.show_tag = show_tag self.show_tag_on_stars = show_tag_on_stars self.tag = tag self.dt = 0.0001 self.vsphere = vp.sphere(radius=self.radius,\ color=self.sphere_color,\ opacity=0.3,\ visible=self.show_sphere) self.varrow = vp.arrow(color=self.arrow_color,\ shaftwidth=0.05,\ emissive=True,\ visible=self.show_arrow) self.vstars = [vp.sphere(radius=self.star_radius,\ color=self.star_color,\ opacity=0.7,\ emissive=True,\ visible=self.show_stars) for i in range(self.n-1)] self.vtag = vp.text(text=self.tag,\ color=self.arrow_color,\ align="center",\ height=0.2*self.radius,\ emissive=True,\ visible=self.show_tag) self.vtags = [vp.text(text=self.tag,\ color=self.arrow_color,\ align="center",\ height=0.125*self.radius,\ visible=self.show_tag_on_stars) for i in range(self.n-1)] self.active = 0
def main(grid, init, goal, steering_noise, distance_noise, measurement_noise,weight_data, weight_smooth, p_gain, d_gain): landmarkss = [] for i in range(len(grid)): for j in range(len(grid[0])): if grid[i][j]==1: landmarkss.append((i,j)) z = (len(grid)*10)+5 x = (len(grid[0])*10)+5 escena = vpython.canvas(width=1200,height=1000) escena.title = "Simulador de Autonomía Vehicular" escena.background = vpython.color.cyan escena.center = vpython.vector(x/2,-1,z/2) escena.forward= vpython.vector(0,-2,-1) #escena.range= 80 #ejex= vpython.curve(color=vpython.color.blue) #ejey=vpython.curve(color=vpython.color.red) #ejez=vpython.curve(color=vpython.color.green) #vpython.userzoom = True #for i in range(x): # pos_x = vpython.vector(i,0,0) # ejex.append(pos_x) # pos_y = vpython.vector(0,i,0) # ejey.append(pos_y) # pos_z=vpython.vector(0,0,i) # ejez.append(pos_z) suelo = vpython.box(pos=vpython.vector(x/2,-0.5,z/2),color=vpython.color.white,size=vpython.vector(x,1.0,z),texture={'file':vpython.textures.metal, 'place':'all'}) high_wall = 30 for i in range(len(landmarkss)): x_wall = (landmarkss[i][1]*10)+5 z_wall = (landmarkss[i][0]*10)+5 if i%2==0: wall = vpython.box(pos=vpython.vector(x_wall,15,z_wall),color=vpython.vector(1,0.7,0.2),size=vpython.vector(10,high_wall,10),texture={'file':vpython.textures.metal, 'place':'all'}) else: wall = vpython.box(pos=vpython.vector(x_wall,25,z_wall),color=vpython.vector(1,0.7,0.2),size=vpython.vector(10,high_wall+20,10),texture={'file':vpython.textures.metal, 'place':'all'}) #IMPLEMENTING PLANING: A* ALGORITHM path = plan(grid, init, goal) path.astar() path_way = path.path #IMPLEMENTING SMOOTHNESS PATH path.smooth(weight_data, weight_smooth) path_smoothed = path.spath inicio =vpython.text(text="Inicio",align='center',color=vpython.color.green,pos=vpython.vector((path_smoothed[0][1]*10)+5,22,(path_smoothed[0][0]*10)+5),height=5,width=12) meta = vpython.text(text="Meta",align='center',color=vpython.color.green,pos=vpython.vector((path_smoothed[-1][1]*10)+5,22,(path_smoothed[-1][0]*10)+5),height=5,width=12) #IMPLEMENTING PARTICLE FILTERS AND PID return run(grid, goal, path.spath, [p_gain, d_gain],escena)
def gettile(offsets=None, cpos=None): """Create and return a list of 3D objects making up a single MWA tile. If cpos is given, it's used as the center position for the whole tile (if you want to show multiple tiles). """ if offsets is None: offsets = TILEOFFSETS if cpos is None: cpos = v(0, 0, 0) elif type(cpos) == tuple: cpos = v(cpos) eaxis = vpython.arrow(pos=v(0, 0, 0), axis=v(3, 0, 0), color=color.blue, shaftwidth=0.1, fixedwidth=True, opacity=0.2) naxis = vpython.arrow(pos=v(0, 0, 0), axis=v(0, 3, 0), color=color.blue, shaftwidth=0.1, fixedwidth=True, opacity=0.2) eaxislabel = vpython.text(text='E', pos=v(3, 0, 0.2), height=0.5, depth=0.1, color=color.blue, opacity=0.2) naxislabel = vpython.text(text='N', pos=v(0, 3, 0.2), height=0.5, depth=0.1, color=color.blue, opacity=0.2) gp = vpython.box(pos=v(0, 0, 0) + cpos, axis=v(0, 0, 1), height=5.0, width=5.0, length=0.05, color=color.gray(0.5)) olist = [eaxis, naxis, eaxislabel, naxislabel, gp] letters = 'ABCDEFGHIJKLMNOP' for i in range(16): xy = offsets[i] p = v(xy[0], xy[1], 0) + cpos dlist = getdipole(cpos=p, dlabel=letters[i]) olist += dlist return olist
def show_instruction(): """ show the instruction massage to user: which shape's type and color to pick :return: None """ vpython.text(text=lang.INSTRUCTION_MESSAGE, color=vpython.color.red, pos=vpython.vector(-25, 25, 0), height=3) vpython.text(text=chosen_shape + lang.INSTRUCTION_MESSAGE2 + str(shape_color), color=vpython.color.red, pos=vpython.vector(-25, 20, 0), height=3)
def __init__(self, v, arrow_label, arrow_color, arrow_pos): if arrow_label == 'x': vec_u = Arrow.vec_i elif arrow_label == 'y': vec_u = Arrow.vec_j elif arrow_label == 'z': vec_u = Arrow.vec_k else: vec_u = vp.vector(v.x * Arrow.vec_i.x, v.y * Arrow.vec_j.y, v.z * Arrow.vec_k.z) self.rod_radius = vp.mag(vec_u) * 0.01 scaled_arrow_pos = vp.vector(arrow_pos.x * Arrow.vec_i.x, arrow_pos.y * Arrow.vec_i.y, arrow_pos.z * Arrow.vec_i.z) self.rod = vp.cylinder(pos=scaled_arrow_pos, axis=vec_u, radius=self.rod_radius, color=arrow_color) self.cone = vp.cone(pos=vec_u, axis=0.1 * vec_u, radius=vp.mag(vec_u) * 0.03, color=arrow_color) if arrow_label in 'xyz': self.axis_text = vp.text(text=arrow_label, pos=self.cone.pos + 0.1 * vec_u, color=arrow_color)
def display_current_rewards_returns(self): # self.GI.V_of_s[loc] # self.grid_dict['returns'][loc] = \ # self.grid_dict['rewards'][loc] text_ht_1 = self.grid_height * 0.1 text_ht_2 = self.grid_height * 0.1 for col in range(self.cols): for row in range(self.rows): loc = (row, col) x1 = col * self.grid_width - self.ctr_x - \ self.grid_width / 4.0 y1 = -row * self.grid_height + self.ctr_y - \ self.grid_width / 4.0 the_text_1 = self.grid_dict['rewards'][loc] if str(the_text_1) in ('10', '-10'): the_text_1 = None if the_text_1 is not None: self.rewards[col][row] = vp.text( text=str(the_text_1), height=text_ht_1, align='center', color=vp.color.black, pos=vp.vector(x1, y1 - text_ht_1 / 2, self.grid_thick * 2))
def representer(grid,path_way,clock,landmarks): z =len(grid)*10 x=len(grid[0])*10 escena = vpython.canvas(width=1200,height=600) escena.title = "Path Finder usando el algoritmo A*" escena.background = vpython.color.cyan escena.center = vpython.vector(x/2,-1,z/2) #escena.forward= vpython.vector(1,-1,0.2) escena.forward= vpython.vector(0,-2,-1) #ejex= vpython.curve(color=vpython.color.blue) #ejey=vpython.curve(color=vpython.color.red) #ejez=vpython.curve(color=vpython.color.green) #vpython.userzoom = True #for i in range(x): # pos_x = vpython.vector(i,0,0) # ejex.append(pos_x) # pos_y = vpython.vector(0,i,0) # ejey.append(pos_y) # pos_z=vpython.vector(0,0,i) # ejez.append(pos_z) suelo = vpython.box(pos=vpython.vector(x/2,-1,z/2),color=vpython.color.yellow,size=vpython.vector(x,0.1,z),texture=vpython.textures.rough) high_wall = 20 for i in range(len(landmarks)): z_wall=(landmarks[i][0]*10)+5 x_wall=(landmarks[i][1]*10)+5 muro = vpython.box(pos=vpython.vector(x_wall,10,z_wall),color=vpython.color.white,size=vpython.vector(10,high_wall,10),texture=vpython.textures.wood) robot = vpython.sphere(pos=vpython.vector(path_way[0][1]+5,3,path_way[0][0]+5),color=vpython.color.black,radius=3) trayectoria = vpython.curve(color=vpython.color.white) inicio =vpython.text(text="Inicio",align='center',color=vpython.color.green,pos=vpython.vector(5,22,5),height=5,width=12) meta = vpython.text(text="Meta",align='center',color=vpython.color.green,pos=vpython.vector((path_way[-1][1]*10)+5,22,(path_way[-1][0]*10)+5),height=5,width=12) time.sleep(clock) escena.range=150 for i in range(len(path_way)): #escena.center = vpython.vector((path_way[i][1]*10)+5,-100,(path_way[i][0]*10)+5-20) escena.center = vpython.vector((path_way[i][1]*10)+5,4,(path_way[i][0]*10)+5) #time.sleep(0.3) time.sleep(0.1) pos = vpython.vector((path_way[i][1]*10)+5,3,(path_way[i][0]*10)+5) robot.pos = pos trayectoria.append(pos) #vpython.rate(100) vpython.rate(300)
def __init__(self, centr_body, **kwargs): self.name = kwargs.pop('name') self.radius = kwargs.pop('radius')*1e3 # km to m self.mass = kwargs.pop('mass')*1e24 # kg self.color = getattr(vp.color,kwargs.pop('color')) self.centr_body = centr_body # passed in as an object self.is_moon = False # marks whether this is a planet/sun or a moon # If this is a planet or a sun if 'perih_distance' in kwargs: perih_distance = kwargs.pop('perih_distance')*1e9 # Perihelion distance; 10^6km to m long_perih = kwargs.pop('long_perih')*np.pi/180. # Longitude of perihelion; deg to rad long_asc_node = kwargs.pop('long_asc_node')*np.pi/180. # Longitude of ascending node inclination = kwargs.pop('inclination')*np.pi/180. # Orbital inclination # Initialize planet/sun position self.position = init_pos(self.centr_body, perih_distance, long_perih, long_asc_node, inclination) print('Generating',self.name,'at perihelion distance of',perih_distance/1e9,'e+6 km.') # If this is a moon if 'm_distance' in kwargs: self.is_moon = True distance = kwargs.pop('m_distance')*1e3 # Initialize moon position self.position = init_moon_pos(self.centr_body, distance) print('Generating',self.name,'at',distance/1e3,'km from',self.centr_body.name) # Initialize body velocity self.velocity = init_vel(self.centr_body, self.position) # Initialize body acceleration self.acceleration = init_acc(self.centr_body, self.position) # Draw vpython representation trail = True if self.is_moon == False else False self.sphere = vp.sphere(pos=self.position*model_scale,radius=self.radius*model_scale,color=self.color, make_trail=trail,trail_radius=trail_size*model_scale) # Draw name label above sphere if this is a planet or sun if self.is_moon == False: self.label = vp.text(pos=model_scale*vp.vector(self.position.x,self.position.y+1e10*model_scale,self.position.z), align='center',text=self.name,height=5e10*model_scale,color=vp.color.green) # Initialize the trojan belt for jupiter if self.name == 'Jupiter' and show_trojan_belt == True: print('Generating Trojan belts') # Use position (in cartesian coord) to find theta on xz-plane self.init_j_theta = np.arctan(self.position.x/self.position.z) if self.position.z < 0: # if denominator is negative (in Quadrant2/3), add 180deg self.init_j_theta += np.pi self.tro_rock_list, self.tro_theta0_list, self.tro_radius_list = init_trojan_belt(self.init_j_theta) if show_arrows == True: self.arrow = vp.arrow(pos=model_scale*self.position,axis=self.velocity,length=1e11*model_scale,color=vp.color.red)
def credits(): t0 = vp.text(text='Jacob Jones', pos=vp.vec(5,5,0),color=vp.color.cyan, billboard=True, emissive=True) t1 = vp.text(text='Ralph Ghannam', pos=vp.vec(3,3,0),color=vp.color.cyan, billboard=True, emissive=True) t2 = vp.text(text='Matthew Cosman', pos=vp.vec(1,1,0),color=vp.color.cyan, billboard=True, emissive=True) t3 = vp.text(text='Ameer Noufal', pos=vp.vec(-1,-1,0),color=vp.color.cyan, billboard=True, emissive=True) t4 = vp.text(text='Akshar Patel', pos=vp.vec(-3,-3,0),color=vp.color.cyan, billboard=True, emissive=True) t5 = vp.text(text='Daniel Smith De-Paz', pos=vp.vec(-5,-5,0),color=vp.color.cyan, billboard=True, emissive=True) t6 = vp.text(text='Shail Patel ', pos=vp.vec(-7,-7,0),color=vp.color.cyan, billboard=True, emissive=True)
def geteda(offsets=EDAOFFSETS): """Create and return a list of 3D objects making up the entire 256 element Engineering Development Array, using the dipole locations in locations.txt """ gp = vpython.box(pos=v(0, 0, 0), axis=v(0, 0, 1), height=40.0, width=40.0, length=0.05, color=color.gray(0.5)) olist = [gp] for bfid in pointing.HEXD: for dipid in pointing.HEXD: dlist = getdipole(cpos=v(*offsets[bfid][dipid]), dlabel=bfid + dipid) olist += dlist eaxis = vpython.arrow(pos=v(0, 0, 0), axis=v(20, 0, 0), color=color.blue, shaftwidth=0.1, fixedwidth=True, opacity=0.2) naxis = vpython.arrow(pos=v(0, 0, 0), axis=v(0, 20, 0), color=color.blue, shaftwidth=0.1, fixedwidth=True, opacity=0.2) eaxislabel = vpython.text(text='E', pos=v(20, 0, 0.2), height=0.5, depth=0.1, color=color.blue, opacity=0.2) naxislabel = vpython.text(text='N', pos=v(0, 20, 0.2), height=0.5, depth=0.1, color=color.blue, opacity=0.2) olist += [eaxis, naxis, eaxislabel, naxislabel] return olist
def create_world(): """create ground and an axis cross at 0,0,0 """ mybox = v.box(pos=v.vector(0, 0, 0), size=v.vector(0.5, 0.5, 0.5), color=v.vector(0.2, 0.2, 0.2), opacity=0.25) xarrow = v.arrow(pos=v.vector(0, 0, 0), axis=v.vector(1, 0, 0), color=v.vector(1, 0, 0)) xletter = v.text(pos=xarrow.axis, text="x", color=xarrow.color, height=0.5, lenght=0.5, depth=0.1, billboard=False, axis=xarrow.axis, up=v.vector(0, 1, 0)) yarrow = v.arrow(pos=v.vector(0, 0, 0), axis=v.vector(0, 1, 0), color=v.vector(0, 1, 0)) yletter = v.text(pos=yarrow.axis, text="y", color=yarrow.color, height=0.5, lenght=0.5, depth=0.1, billboard=False, axis=yarrow.axis, up=v.vector(0, 1, 0)) zarrow = v.arrow(pos=v.vector(0, 0, 0), axis=v.vector(0, 0, 2), color=v.vector(0, 0, 1)) zletter = v.text(pos=zarrow.axis, text="z", color=zarrow.color, height=0.5, lenght=0.5, depth=0.1, billboard=False, axis=zarrow.axis, up=v.vector(0, 1, 0))
def build_text(shape_number): """ creating a text's shape :param shape_number: the index number of the shape that the text will be inside it :return: a text's shape object """ text = vpython.text(text=get_random_word(), color=get_random_color(), pos=vpython.vector( -config.DISTANCE_BETWEEN_SHAPE + shape_number * config.DISTANCE_BETWEEN_SHAPE, 0, 0), billboard=True, align=ALIGN) return text
def draw_board(columns, rows): """ The board is a dictionary of cubes with coordinates as keys. Other information and graphics is stored too, with descriptive names as keys """ scene.center = vector(int((columns - 1) / 2), int(rows / 2), 0) x_coordinates, y_coordinates = list(range(columns)), list(range(rows)) board = {(x, y): box(pos=vector(x, y, 0), height=.8, width=.8, length=.8, opacity=0.2) for x in x_coordinates for y in y_coordinates} for item in board: board[item].status = False board['width'] = columns board['height'] = rows board['level'] = 1 board['points'] = 0 board['point_display'] = text(pos=vector(-4, 18, 0), text='0', color=vector(0.6, 0.4, 0.8)) board['GO_message1'] = text(pos=vector( int(columns / 2) - 4, int(rows / 2) - 3, 1), text=' GAME OVER! ', color=color.green, visible=False) board['GO_message2'] = text( pos=vector(int(columns / 2) - 12, int(rows / 2) - 6, 1), text=" Press any key to try again or 'e' to Exit ", color=color.green, visible=False) return board
def __init__(self, f, xmin, xmax, ymin, ymax, zmin, zmax): # The x axis is labeled y, the z axis is labeled x, and the y axis is labeled z. # This is done to mimic fairly standard practive for plotting # the z value of a function of x and y. self.f = f if not xmin: self.xmin = 0 else: self.xmin = xmin if not xmax: self.xmax = 1 else: self.xmax = xmax if not ymin: self.ymin = 0 else: self.ymin = ymin if not ymax: self.ymax = 1 else: self.ymax = ymax if not zmin: self.zmin = 0 else: self.zmin = zmin if not zmax: self.zmax = 1 else: self.zmax = zmax R = L/100 d = L-2 xaxis = vp.cylinder(pos=vp.vector(0, 0, 0), axis=vp.vector( 0, 0, d), radius=R, color=vp.color.yellow) yaxis = vp.cylinder(pos=vp.vector(0, 0, 0), axis=vp.vector( d, 0, 0), radius=R, color=vp.color.yellow) zaxis = vp.cylinder(pos=vp.vector(0, 0, 0), axis=vp.vector( 0, d, 0), radius=R, color=vp.color.yellow) k = 1.02 h = 0.05*L vp.text(pos=xaxis.pos+k*xaxis.axis, text='x', height=h, align='center', billboard=True, emissive=True) vp.text(pos=yaxis.pos+k*yaxis.axis, text='y', height=h, align='center', billboard=True, emissive=True) vp.text(pos=zaxis.pos+k*zaxis.axis, text='z', height=h, align='center', billboard=True, emissive=True) self.vertices = [] for x in range(L): for y in range(L): val = self.evaluate(x, y) self.vertices.append(self.make_vertex(x, y, val)) self.make_quads() self.make_normals()
def __init__(self, n, state=None,\ center=vp.vector(0,0,0),\ radius=1,\ color=vp.color.blue,\ star_color=vp.color.white, tag=None,\ show_stars=True): self.n = n if state == None: self.state = qutip.rand_ket(n) else: self.state = state self.center = center self.radius = radius if color == None: self.color = vp.vector(random.random(),\ random.random(),\ random.random()) else: self.color = color self.star_color = star_color self.tag = tag self.show_stars = show_stars self.vsphere = vp.sphere(pos=self.center,\ radius=self.radius,\ color=self.color,\ opacity=0.3) self.varrow = vp.arrow(pos=self.center,\ color=self.color,\ shaftwidth=0.05,\ emissive=True) if self.tag: self.text = vp.text(text=self.tag,\ align='center',\ color=self.color,\ height=0.2) if self.show_stars: self.vstars = [vp.sphere(radius=0.1*self.radius,\ opacity=0.5,\ emissive=True) for i in range(self.n-1)]
def __init__(self, axis_label, axis_color, arrow_pos): if axis_label == 'x': vec_u = Arrow.vec_i elif axis_label == 'y': vec_u = Arrow.vec_j elif axis_label == 'z': vec_u = Arrow.vec_k self.rod_radius = vp.mag(vec_u) * 0.01 self.rod = vp.cylinder(pos=arrow_pos, axis=vec_u, radius=self.rod_radius, color=axis_color) self.cone = vp.cone(pos=vec_u, axis=0.1 * vec_u, radius=vp.mag(vec_u) * 0.03, color=axis_color) if axis_label in 'xyz': self.axis_text = vp.text(text=axis_label, pos=self.cone.pos + 0.1 * vec_u, color=axis_color)
def credits(): t0 = vp.text(text='Jacob Jones', pos=vp.vec(5, 5, 0), color=vp.color.cyan, billboard=True, emissive=True) t1 = vp.text(text='Ralph Ghannam', pos=vp.vec(3, 3, 0), color=vp.color.cyan, billboard=True, emissive=True) t2 = vp.text(text='Matthew Cosman', pos=vp.vec(1, 1, 0), color=vp.color.cyan, billboard=True, emissive=True) t3 = vp.text(text='Ameer Noufal', pos=vp.vec(-1, -1, 0), color=vp.color.cyan, billboard=True, emissive=True) t4 = vp.text(text='Akshar Patel', pos=vp.vec(-3, -3, 0), color=vp.color.cyan, billboard=True, emissive=True) t5 = vp.text(text='Daniel Smith De-Paz', pos=vp.vec(-5, -5, 0), color=vp.color.cyan, billboard=True, emissive=True) t6 = vp.text(text='Shail Patel ', pos=vp.vec(-7, -7, 0), color=vp.color.cyan, billboard=True, emissive=True) time.sleep(2) webbrowser.open_new("https://www.youtube.com/watch?v=dQw4w9WgXcQ")
def __init__(self, grid_instance, grid_dict, grid_width=1.0, grid_height=1.0, grid_thick=0.05, arrow_base_width=0.05, show_ctr=False): self.GI = grid_instance self.grid_dict = grid_dict self.cols = grid_dict['cols'] self.rows = grid_dict['rows'] self.grid_width = grid_width self.grid_height = grid_height self.grid_thick = grid_thick scale = 2.0 self.agent_radius = grid_width / (5.0 / scale) self.bounce_scale = 1.0 / (self.agent_radius - grid_width / 2.0) # 4.0 / scale self.arrow_length = grid_width / 3.0 - 2.0 * grid_thick self.arrow_base_width = arrow_base_width self.ctr_x = float(self.cols * grid_width) / 2.0 - grid_width / 2.0 self.ctr_y = float(self.rows * grid_height) / 2.0 - grid_height / 2.0 if show_ctr: vp.sphere(pos=vp.vector(0, 0, 0), radius=0.1, color=vp.color.red) self.axis_list = [ vp.vector(-1, 0, 0), vp.vector(1, 0, 0), vp.vector(0, -1, 0), vp.vector(0, 1, 0) ] agent_x = +self.grid_dict['start'][1] * self.grid_width - self.ctr_x agent_y = -self.grid_dict['start'][0] * self.grid_height + self.ctr_y self.agent = vp.cylinder(pos=vp.vector(agent_x, agent_y, grid_thick / 2.0), radius=self.agent_radius, axis=vp.vector(0, 0, grid_thick), color=vp.color.white, texture='Andrew.jpg') self.squares = [] self.arrows = [] self.rewards = [] self.returns = [] self.grid_dict['returns'] = {} for col in range(self.cols): self.squares.append([]) self.arrows.append([]) self.rewards.append([]) self.returns.append([]) for row in range(self.rows): loc = (row, col) self.squares[col].append('') self.arrows[col].append([]) self.rewards[col].append('') self.returns[col].append('') for i in range(4): self.arrows[col][row].append('') T = vp.text(text="Grid World", align='center', color=vp.color.white, height=self.grid_height * 0.5, pos=vp.vector(0, self.ctr_y + self.grid_height / 1.5, 0)) self.__draw_grid__() self.draw_weighted_arrows() self.display_current_rewards_returns() self.__step_button__() self.__start_over_button__() self.__auto_stepping_button__() vp.scene.append_to_caption(" Set Pause Time: ") self.__pause_time_input__() self.__clear_records_button__()
import vpython as vp earth_center = vp.vector(50., 50., 0.) earth_dimensions = vp.vector(50., 50., 0.) earth = vp.box(pos=earth_center, size=earth_dimensions, color=vp.color.green) Earth = vp.text(text="EARTH", pos=vp.vector(50, 50, -20), align='center', height=15, color=vp.color.green, axis=vp.vector(1, 1, 0), up=vp.vector(0, 0, 1)) mars_center = vp.vector(0., 0., 0.) mars_dimensions = vp.vector(50., 50., 0.) mars = vp.box(pos=mars_center, size=mars_dimensions, color=vp.color.red) Mars = vp.text(text="MARS", pos=vp.vector(-0, -0, -20), align='center', height=15, color=vp.color.red, axis=vp.vector(1, 1, 0), up=vp.vector(0, 0, 1)) moon_center = vp.vector(-50., -50., 0.) moon_dimensions = vp.vector(50., 50., 0.) moon = vp.box(pos=moon_center, size=moon_dimensions, color=vp.color.gray(.8)) Moon = vp.text(text="MOON",
y_axis = vp.cylinder(pos=origin, axis=vp.vector(0, 1, 0), radius=.01, color=vp.color.gray(.1), opacity=.75) z_axis = vp.cylinder(pos=origin, axis=vp.vector(0, 0, 1), radius=.01, color=vp.color.gray(.1), opacity=.75) # Labels for each Axes x_text = vp.text(text='X', pos=vp.vector(1.1, 0, 0), align='center', height=0.05, color=vp.color.gray(.1), billboard=True, emissive=True) y_text = vp.text(text='Y', pos=vp.vector(0, 1.1, 0), align='center', height=0.05, color=vp.color.gray(.1), billboard=True, emissive=True) z_text = vp.text(text='Z', pos=vp.vector(0, 0, 1.1), align='center', height=0.05, color=vp.color.gray(.1),
def show_points(board): board['point_display'].visible = False del (board['point_display']) board['point_display'] = text(pos=vector(-6, 18, 0), text=str(board['points']), color=vector(0.6, 0.4, 0.8))
b40=0 b41=0 b42=0 b43=0 b44=0 #View Setup vs.scene.range=25 vs.scene.center=vs.vector(0,0,0) vs.scene.userzoom=False vs.scene.userspin=False #Objects paddle=vs.box(pos=vs.vector(0,-20,0), length=7, height=1, width=0.1, texture=vs.textures.wood) ball=vs.sphere(pos=vs.vector(0,-19.4,0),radius=0.5, color=vs.color.yellow) vs.text(text=('Ultimate Brick Breaker'), color=vs.vector(0.7,0.1,0.1), pos=vs.vector(-11.8,22.8,0),height=2) vs.text(text=('Controls - Left and Right Arrow Keys'), color=vs.vector(0.7,0.1,0.1), pos=vs.vector(-18.5,-24.2,0),height=2) #border=extrusion(pos=vector(0,0,0), shape=shapes.rectangle(width=50, height=50,thickness=0.05),color=vector(0.1,0.1,0.2)) #Bricks box = {} for x in chain(range(-20,-19), range(-16,-15), range(-12, -11), range(-8,-7), range(-4, -3), range(0,1), range(4,5), range(8,9), range(12,13), range(16,17), range(20, 21)): for y in chain(range(8,9), range(12,13), range(16,17), range(20,21)): z = 0 box[(x, y)]= vs.box(pos=vs.vector(x, y, z), length=4, height=4, width=0.1, color=vs.color.blue, texture=vs.textures.rock) #Initial Velocities paddle.v=vs.vector(3,0,0) ball.v=vs.vector(0.7,5,0) #Game
# Plot 2: Ellipsoids origin = vp.vector(0, 0, 0) scene1 = vp.canvas(title='Ellipsoids', width=800, height=800, center=origin) # Create a set of Axis & Label each Axis x_axis = vp.cylinder(pos=origin, axis=vp.vector(1.2, 0, 0), radius=.02, color=vp.color.yellow, opacity=.5) y_axis = vp.cylinder(pos=origin, axis=vp.vector(0, 1.2, 0), radius=.02, color=vp.color.yellow, opacity=.5) z_axis = vp.cylinder(pos=origin, axis=vp.vector(0, 0, 1.2), radius=.02, color=vp.color.yellow, opacity=.5) lx_text = vp.text(text='lx', pos=vp.vector(1.1, .1, 0), align='center', height=0.05, color=vp.color.white, billboard=True, emissive=True) ly_text = vp.text(text='ly', pos=vp.vector(.1, 1.1, 0), align='center', height=0.05, color=vp.color.white, billboard=True, emissive=True) lz_text = vp.text(text='lz', pos=vp.vector(-.1, 0, 1.1), align='center', height=0.05, color=vp.color.white, billboard=True, emissive=True) # Legend for the Ellipsoids visualization KE_text = vp.text(text='KE', pos=vp.vector(1.3, .5, 0), align='center', height=.05, color=vp.color.orange, billboard=True, emissive=True) L_text = vp.text(text='ω', pos=vp.vector(1.3, 0, 0), align='center', height=.05, color=vp.color.blue,
canvas=window, make_trail=True) Xaxis = arrow(pos=vector(0, 0, 0), axis=vector(100, 0, 0), shaftwidth=1, color=vector(1, 0, 0)) Yaxis = arrow(pos=vector(0, 0, 0), axis=vector(0, 100, 0), shaftwidth=1, color=vector(0, 1, 0)) Zaxis = arrow(pos=vector(0, 0, 0), axis=vector(0, 0, 100), shaftwidth=1, color=vector(0, 0, 1)) onX50 = text(text="50cm", align='center', color=vector(1, 0, 0), pos=vector(50, 2, 0)) onY50 = text(text="50cm", align='center', color=vector(0, 1, 0), pos=vector(4, 50, 0)) onZ50 = text(text="50cm", align='center', color=vector(0, 0, 1), pos=vector(0, 2, 50)) onX100 = text(text="100cm", align='center', color=vector(1, 0, 0), pos=vector(100, 2, 0)) onY100 = text(text="100cm", align='center',
listBase = [target, mBoxMain ] aclength=0.01 lenArrowOrigin = 1.00 lenArrowTarget = 0.75*lenArrowOrigin mArrowOriginX=arrow(pos=mPosOrigin, axis=vector(-lenArrowOrigin, 0, 0)*0.6, shaftwidth=aclength, color=color.black) mArrowOriginY=arrow(pos=mPosOrigin, axis=vector(0, lenArrowOrigin, 0), shaftwidth=aclength, color=color.black) mArrowOriginZ=arrow(pos=mPosOrigin, axis=vector(0, 0, lenArrowOrigin), shaftwidth=aclength, color=color.black) mArrowTargetX=arrow(pos=mPosTarget, axis=vector(-lenArrowTarget, 0, 0), shaftwidth=aclength, color=color.black) mArrowTargetY=arrow(pos=mPosTarget, axis=vector(0, lenArrowTarget, 0), shaftwidth=aclength, color=color.black) mArrowTargetZ=arrow(pos=mPosTarget, axis=vector(0, 0, lenArrowTarget), shaftwidth=aclength, color=color.black) listArrows = [mArrowTargetX, mArrowTargetY, mArrowTargetZ, mArrowOriginX, mArrowOriginY, mArrowOriginZ] lenArrowOrigin*=1.05 lenArrowTarget*=1.05 mTextOriginX = text(text='z', pos=mPosOrigin + vector(-lenArrowOrigin, 0, 0)*0.6, color=color.black, depth=0.05) mTextOriginY = text(text='y', pos=mPosOrigin + vector(0, lenArrowOrigin, 0), color=color.black, depth=0.05) mTextOriginZ = text(text='x', pos=mPosOrigin + vector(0, 0, lenArrowOrigin), color=color.black, depth=0.05) mTextTargetX = text(text="z'", pos=mPosTarget + vector(-lenArrowTarget, 0, 0), color=color.black, depth=0.05) mTextTargetY = text(text="y'", pos=mPosTarget + vector(0, lenArrowTarget, 0), color=color.black, depth=0.05) mTextTargetZ = text(text="x'", pos=mPosTarget + vector(0, 0, lenArrowTarget), color=color.black, depth=0.05) listArrowsText=[mTextOriginX, mTextOriginY, mTextOriginZ, mTextTargetX, mTextTargetY, mTextTargetZ] for item in listArrowsText: item.length = 0.1*item.length item.height = 0.1 * item.height item.rotate( angle=1.5 ) mTextTitle = text(text=LabelShow, pos=vector(-1,-0.6,-0.2), align='center', color=color.black,depth=0.01) mTextTitle.length = 0.15*mTextTitle.length mTextTitle.height = 0.15 * mTextTitle.height mTextTitle.rotate( angle=1.0 )
def escenario1_creacion(): global particulas particulas.clear() # creacion de objetos y añadir objetos: vp.text(text='Modelo Estandar', pos=vp.vector(40, 29, 0), align='center', color=vp.color.green, height=5) vp.text(text='Leptones', pos=vp.vector(5, 25, 0), align='center', color=vp.color.green, height=3) vp.text(text='Quarks', pos=vp.vector(25, 25, 0), align='center', color=vp.color.purple, height=3) vp.text(text='Bosones', pos=vp.vector(65, 25, 0), align='center', color=vp.color.red, height=3) particulas_fermionicas = [[], [], []] for i in range(len(particulas_fermionicas)): for k in range(4): particulas_fermionicas[i].append( vp.sphere(pos=vp.vector(k * 10, 20 - (i * 10), 0), radius=4 - i, iden="fermiones:" + str(i) + "," + str(k))) particulas_bosonicas = [[], [], []] for i in range(len(particulas_bosonicas)): for k in range(2): if i == 2 and k == 1: break else: particulas_bosonicas[i].append( vp.sphere(pos=vp.vector(60 + k * 10, 20 - (i * 10), 0), radius=2, color=vp.color.red, iden="bosones:" + str(i) + "," + str(k))) zoom_label = vp.vector(0, 0, 0) vp.label(pos=particulas_bosonicas[0][0].pos - zoom_label, text='Z', color=vp.vector(0.1, 1, 0.7), opacity=0.7, height=15, box=0) vp.label(pos=particulas_bosonicas[0][1].pos - zoom_label, text='Bosones W', color=vp.vector(0.1, 1, 0.7), opacity=0.7, height=15, box=0) vp.label(pos=particulas_bosonicas[1][0].pos - zoom_label, text='Fotón', color=vp.vector(0.1, 1, 0.7), opacity=0.7, height=15, box=0) particulas_bosonicas[1][0].color = vp.vector(255 / 273, 242 / 273, 0) particulas_bosonicas[1][0].emissive = True vp.label(pos=particulas_bosonicas[1][1].pos - zoom_label, text='Gluón', color=vp.vector(0.1, 1, 0.7), opacity=0.7, height=15, box=0) vp.label(pos=particulas_bosonicas[2][0].pos - zoom_label, text='Higgs', color=vp.vector(0.1, 1, 0.7), opacity=0.7, height=15, box=0) vp.label(pos=particulas_fermionicas[0][0].pos - zoom_label, text='Electrón', color=vp.vector(0.1, 1, 0.7), opacity=0.7, height=15, box=0) particulas_fermionicas[0][0].color = vp.vector(0, 74, 2) / 273 vp.label(pos=particulas_fermionicas[1][0].pos - zoom_label, text='Muón', color=vp.vector(0.1, 1, 0.7), opacity=0.7, height=15, box=0) particulas_fermionicas[1][0].color = vp.vector(0, 189, 9) / 273 vp.label(pos=particulas_fermionicas[2][0].pos - zoom_label, text='Tau', color=vp.vector(0.1, 1, 0.7), opacity=0.7, height=15, box=0) particulas_fermionicas[2][0].color = vp.vector(0, 255, 12) / 273 vp.label(pos=particulas_fermionicas[0][1].pos - zoom_label, text='Neutrino \nElectrónico', color=vp.vector(0.1, 1, 0.7), opacity=0.7, height=15, box=0) particulas_fermionicas[0][1].color = vp.vector(0, 74, 2) / 273 vp.label(pos=particulas_fermionicas[1][1].pos - zoom_label, text='Neutrino \nMuónico', color=vp.vector(0.1, 1, 0.7), opacity=0.7, height=15, box=0) particulas_fermionicas[1][1].color = vp.vector(0, 189, 9) / 273 vp.label(pos=particulas_fermionicas[2][1].pos - zoom_label, text='Neutrino \nTauónico', color=vp.vector(0.1, 1, 0.7), opacity=0.7, height=15, box=0) particulas_fermionicas[2][1].color = vp.vector(0, 255, 12) / 273 vp.label(pos=particulas_fermionicas[0][2].pos - zoom_label, text='Down', color=vp.vector(0.1, 1, 0.7), opacity=0.7, height=15, box=0) particulas_fermionicas[0][2].color = vp.vector(52, 0, 92) / 273 vp.label(pos=particulas_fermionicas[1][2].pos - zoom_label, text='Strange', color=vp.vector(0.1, 1, 0.7), opacity=0.7, height=15, box=0) particulas_fermionicas[1][2].color = vp.vector(88, 0, 156) / 273 vp.label(pos=particulas_fermionicas[2][2].pos - zoom_label, text='Bottom', color=vp.vector(0.1, 1, 0.7), opacity=0.7, height=15, box=0) particulas_fermionicas[2][2].color = vp.vector(144, 0, 255) / 273 vp.label(pos=particulas_fermionicas[0][3].pos - zoom_label, text='Up', color=vp.vector(0.1, 1, 0.7), opacity=0.7, height=15, box=0) particulas_fermionicas[0][3].color = vp.vector(52, 0, 92) / 273 vp.label(pos=particulas_fermionicas[1][3].pos - zoom_label, text='Charm', color=vp.vector(0.1, 1, 0.7), opacity=0.7, height=15, box=0) particulas_fermionicas[1][3].color = vp.vector(88, 0, 156) / 273 vp.label(pos=particulas_fermionicas[2][3].pos - zoom_label, text='Top', color=vp.vector(0.1, 1, 0.7), opacity=0.7, height=15, box=0) particulas_fermionicas[2][3].color = vp.vector(144, 0, 255) / 273
def init_visuals(self): if self.parent != None: self.center = self.parent.get_center(self) self.radius = self.parent.get_radius(self) else: if self.center == None: self.center = vp.vector(0,0,0) if self.radius == None: self.radius = 1 if self.children != None: for child in self.children: child.init_visuals() self.answer_colors = [] for child_a in self.children: for child_b in self.children: self.answer_colors.append(child_a.color+child_b.color) summ = self.answer_colors[0] for answer_color in self.answer_colors[1:]: summ = summ + answer_color summ = summ/len(self.answer_colors) self.color = summ #self.color = sum(self.answer_colors)/len(self.answer_colors) else: self.answer_colors = [np.random.randn(3) for i in range(self.dim)] summ = self.answer_colors[0] for answer_color in self.answer_colors[1:]: summ = summ + answer_color summ = summ/len(self.answer_colors) self.color = summ #self.color = sum(self.answer_colors)/len(self.answer_colors) i = 0 col = vp.vector(*np.absolute(self.color)) self.reference_sphere = vp.sphere(pos=self.center,\ radius=self.radius,\ color=col,\ opacity=0.2) self.answer_spheres = [] for answer_space in self.question_space: xyzs = v_SurfaceXYZ(answer_space) col = vp.vector(*np.absolute(self.answer_colors[i])) ax = vp.vector(*self.answer_colors[i]) answer_stars = vp.points(pos=[self.center+self.radius*vp.vector(*xyz) for xyz in xyzs],\ color=col,\ radius=10*self.radius, opacity=0.4, emissive=True) answer_tags = [vp.text(text=self.answers[i],\ align="center",\ pos=self.center+self.radius*vp.vector(*xyz),\ color=col,\ height=0.125*self.radius,\ opacity=0.4, axis=ax) for xyz in xyzs] answer_spin_axis = spin_axis(len(xyzs)+1, qt.Qobj(answer_space)) answer_arrow = vp.arrow(pos=self.center,\ axis=self.radius*vp.vector(*answer_spin_axis),\ color=col,\ shaftwidth=0.007, opacity=0.7) answer_tag = vp.text(text=self.answers[i], align="center",\ pos=self.radius*vp.vector(*answer_spin_axis) + self.center,\ color=col,\ height=0.16*self.radius,\ opacity=0.5,\ axis=ax) self.answer_spheres.append([answer_stars, answer_tags, answer_arrow, answer_tag]) i += 1 pure_xyzs = v_SurfaceXYZ(self.pure_answer.full().T[0]) pure_answer_stars = vp.points(pos=[self.center+self.radius*vp.vector(*pure_xyz) for pure_xyz in pure_xyzs],\ color=vp.color.white,\ radius=10*self.radius, emissive=True) pure_spin_axis = spin_axis(len(pure_xyzs)+1, self.pure_answer) pure_answer_arrow = vp.arrow(pos=self.center,\ axis=self.radius*vp.vector(*pure_spin_axis),\ color=vp.color.white,\ shaftwidth=0.01) self.pure_answer_sphere = [pure_answer_stars, pure_answer_arrow] if self.parent != None: state_xyzs = v_SurfaceXYZ(self.state.full().T[0]) state_stars = vp.points(pos=[self.center+self.radius*vp.vector(*state_xyz) for state_xyz in state_xyzs],\ color=col,\ radius=10*self.radius, opacity=0.8) state_spin_axis = spin_axis(len(state_xyzs)+1, self.state) state_arrow = vp.arrow(pos=self.center,\ axis=self.radius*vp.vector(*state_spin_axis),\ color=col,\ shaftwidth=0.03, opacity=0.8) self.state_sphere = [state_stars, state_arrow]
vec_i = vp.vector(10, 0, 0) vec_j = vp.vector(0, 10, 0) vec_k = vp.vector(0, 0, 10) rod_radius = vp.mag(vec_i) * 0.01 # 0.01 x_rod = vp.cylinder(pos=vec_o, axis=vec_i, radius=rod_radius, color=vp.color.red) x_cone = vp.cone(pos=vec_i, axis=0.1 * vec_i, radius=vp.mag(vec_i) * 0.03, color=vp.color.red) x_axis_text = vp.text(text='x', pos=x_cone.pos + 0.1 * vec_i, color=vp.color.red) y_rod = vp.cylinder(pos=vec_o, axis=vec_j, radius=rod_radius, color=vp.color.cyan) y_cone = vp.cone(pos=vec_j, axis=vp.vector(0, vp.mag(vec_i) * 0.1, 0), radius=vp.mag(vec_j) * 0.03, color=vp.color.cyan) y_axis_text = vp.text(text='y', pos=y_cone.pos + 0.1 * vec_j, color=vp.color.cyan)