def create_viz(): global state, G scene = vp.canvas(background=vp.color.white) n = len(state.dims[0]) d = state.dims[0][0] coords = [ vp.vector(root.real, root.imag, 0) for root in [np.exp(1j * 2 * np.pi * i / d) for i in range(d)] ] colors = [vp.color.red, vp.color.green, vp.color.blue] if n == 3 else\ [vp.vector(*np.random.random(3)) for i in range(n)] vpts = {} for i in range(n): pov_state = take_pov(state, 0, i, G) vp.label(text="pov: %d" % i,\ pos=vp.vector(3*i-n,-1.5,0),\ color=colors[i]) vp.ring(color=colors[i],\ radius=1,\ axis=vp.vector(0,0,1),\ thickness=0.01,\ pos=vp.vector(3*i-n, 0, 0)) for k in range(n): partial = pov_state.ptrace(k).full() for j in range(d): vpts[(i, k, j)] = vp.sphere(opacity=0.5,\ pos=vp.vector(3*i-n,np.random.randn()/25,0)+coords[j],\ color=colors[k],\ radius=partial[j,j].real/4) return vpts
def plot_scene(self, FitnessColumn): cyls = [] for index, variant in self.data.iterrows(): self.num_cylinder_in_orbital = len([ i for i in self.data['Orbital_Number'] if variant['Orbital_Number'] == i ]) poss = self.position_cylinder(self.num_cylinder_in_orbital, variant['Order_in_Orbital'], variant['Orbital_Number']) if 'Mutant_Middle' in variant: prom = variant['Mutant_Middle'] else: prom = 0 cyls_now = self.create_cylinder( poss.x, poss.y, variant[FitnessColumn] * self.disk_height, variant[self.MutantColumns].values, prom) cyls.append(cyls_now) for i in range(1, self.data['Orbital_Number'].max() + 1): ring(pos=vector(0, 0, .1), axis=vector(0, 0, 0.1), radius=self.orbital_diameter * i, thickness=.2, color=vector(0, 0, 0)) return cyls
def __init__(self): self.updated = None self.size = _size self.cgpos = -0.25 * _size self.energy = 0.0 self.body = _vp.sphere(radius=1.0*_size, color=_vp.color.red) self.top = _vp.sphere(radius=0.2*_size, color=_vp.color.blue) self.prop1 = _vp.ring(radius=0.3*_size, thickness=0.05*_size, color=_vp.color.orange) self.prop2 = _vp.ring(radius=0.3*_size, thickness=0.05*_size, color=_vp.color.blue) self.prop3 = _vp.ring(radius=0.3*_size, thickness=0.05*_size, color=_vp.color.blue) self.prop4 = _vp.ring(radius=0.3*_size, thickness=0.05*_size, color=_vp.color.blue) self.set_mass(_mass) self.set_wind(0.0) self.set_thrust(0.0, 0.0, 0.0, 0.0) self.reset()
def __init__(self, dm, LV, pos): self.dm = dm self.n = dm.shape[0] self.L, self.V = LV self.projectors = [v * v.dag() for v in self.V] self.pos = pos self.vring = vp.ring(pos=pos,\ axis=vp.vector(0,0,1),\ color=vp.color.red,\ radius=1, thickness=0.1, opacity=0.5) roots_of_unity = [ np.exp(2 * np.pi * 1j * i / self.n) for i in range(self.n) ] directions = [vp.vector(roots_of_unity[i].real,\ roots_of_unity[i].imag,\ 0) for i in range(self.n)] clock_probs = np.array([(self.dm * self.projectors[i]).tr().real for i in range(self.n)]) self.vclock_arrows = [vp.arrow(pos=self.vring.pos,\ axis=directions[i],\ opacity=clock_probs[i],\ color=vp.color.red) for i in range(self.n)] npdirections = [np.array([roots_of_unity[i].real,\ roots_of_unity[i].imag,\ 0]) for i in range(self.n)] expected_time = sum( [npdirections[i] * clock_probs[i] for i in range(self.n)]) self.vexpected_time = vp.sphere(color=vp.color.red, radius=0.1,\ pos=self.pos+vp.vector(*expected_time), opacity=0.5)
def __init__(self, pos, ori, rad, thi, I, no_of_seg, turns=1): self.pos = pos self.ori = ori self.rad = rad self.thi = thi self.I = I self.no_of_seg = no_of_seg self.turns = turns self.ring = vp.ring(pos=self.pos, axis=self.ori, radius=self.rad, thickness=self.thi) element_length = (2 * np.pi * self.rad) / self.no_of_seg segments = [0] * (self.no_of_seg) for i in range(self.no_of_seg): theta = i * (2 * np.pi / self.no_of_seg) y = self.rad * np.cos(theta) z = self.rad * np.sin(theta) segments[i] = vp.cylinder( pos=vp.vec(self.pos.x, self.pos.y + y, self.pos.z + z), axis=element_length * vp.vec(0, -vp.sin(theta), vp.cos(theta)), radius=self.thi) segments[i].visible = False self.segments = segments print('done')
def __init__(self): self._visible = False # There are two cases that we care about for a 2-body orbit, elliptical # or hyperbolic. Make a graphic for either case. self._ring = vpython.ring(axis=vpython.vector(0, 0, 1), visible=False) # Since vpython doesn't have a hyperbola primitive, we make one ourself # by generating a bunch of points along a hyperbola. Look at this graph # https://www.desmos.com/calculator/dbhsftzyjc # or put the following into wolframalpha.com # parametric graph sinh(t), cosh(t) from t = -asinh(1e2) to asinh(1e2) hyperbola_points: List[vpython.vector] = [] start_t = -math.asinh(self.POINTS_IN_HYPERBOLA) for i in range(0, self.POINTS_IN_HYPERBOLA + 1): t = start_t + abs(start_t) * 2 * i / self.POINTS_IN_HYPERBOLA hyperbola_points.append( vpython.vector(math.sinh(t), math.cosh(t), 0)) self._hyperbola = vpython.curve(hyperbola_points, axis=vpython.vector(1, 1, 0), up=vpython.vec(-1, 0, 0)) self._hyperbola.visible = False
def throw_animation(radius_ring, omega_ring, added_v_throw, angle_throw, spinward): #creates the projectile motion animation c = vp.canvas() period = (2 * mp.pi) / omega_ring height = radius_ring * (3 / 5) ball_length = 0 v_x = omega_ring * (height) time = 0 ring_ani = vp.ring(pos=vp.vector(0, 0, 0), axis=vp.vector(0, 0, 1), radius=radius_ring, canvas=c, thickness=radius_ring * 0.01, color=color.white) zero_ani = vp.sphere(pos=vp.vector(0, -height, 0), radius=radius_ring * 0.05, canvas=c, color=color.yellow, make_trail=True) added_v_x = added_v_throw * np.cos(mp.radians(angle_throw)) added_v_y = added_v_throw * np.sin(mp.radians(angle_throw)) while ball_length < 1.50 * radius_ring: #animates the ball until the distance between ball and center is equal to radius, as lines 129-131 reset the animation. # ball_x = v_x * time + (spinward) * (added_v_x * time ) # "+" spinward, "-" anti ball_y = added_v_y * time - height rate(20) zero_ani_x = ball_x * mp.cos(omega_ring * time) + ball_y * mp.sin( omega_ring * time) zero_ani_y = -ball_x * mp.sin(omega_ring * time) + ball_y * mp.cos( omega_ring * time) zero_ani.pos = vp.vector(zero_ani_x, zero_ani_y, 0) ball_length = mp.sqrt(ball_x**2 + ball_y**2) time += 0.1 if ball_length > radius_ring: zero_ani.make_trail = False time = 0
def ring_animation(radius_z, omega_z): c = vp.canvas() #defines canvas earth_radius = 6.371e6 #defines radius of earth angles = [ ] #stores angles so the rotating spheres on the ring can update their positions. for rads in np.linspace(0, 2 * mp.pi, 11): #appends angles into the angles list. angles.append(rads) period = (2 * mp.pi) / omega_z #defines the period #creates the earth sphere earth = vp.sphere(pos=vp.vector(0, 0, -1.01 * earth_radius), radius=earth_radius, canvas=c, color=vp.color.blue) #creates the ring ring_ani = vp.ring(pos=vp.vector(0, 0, 0), axis=vp.vector(0, 0, 1), radius=radius_z, canvas=c, thickness=radius_z * 0.01, color=color.white) #The following variables create the 10 spheres that rotate with the ring to represent rotation. zero_ani = vp.sphere(pos=vp.vector(radius_z * mp.cos(angles[0]), radius_z * mp.sin(angles[0]), 0), radius=radius_z * 0.05, canvas=c, color=color.yellow) one_ani = vp.sphere(pos=vp.vector(radius_z * mp.cos(angles[1]), radius_z * mp.sin(angles[1]), 0), radius=radius_z * 0.05, canvas=c, color=color.blue) two_ani = vp.sphere(pos=vp.vector(radius_z * mp.cos(angles[2]), radius_z * mp.sin(angles[2]), 0), radius=radius_z * 0.05, canvas=c, color=color.yellow) three_ani = vp.sphere(pos=vp.vector(radius_z * mp.cos(angles[3]), radius_z * mp.sin(angles[3]), 0), radius=radius_z * 0.05, canvas=c, color=color.blue) four_ani = vp.sphere(pos=vp.vector(radius_z * mp.cos(angles[4]), radius_z * mp.sin(angles[4]), 0), radius=radius_z * 0.05, canvas=c, color=color.yellow) five_ani = vp.sphere(pos=vp.vector(radius_z * mp.cos(angles[5]), radius_z * mp.sin(angles[5]), 0), radius=radius_z * 0.05, canvas=c, color=color.blue) six_ani = vp.sphere(pos=vp.vector(radius_z * mp.cos(angles[6]), radius_z * mp.sin(angles[6]), 0), radius=radius_z * 0.05, canvas=c, color=color.yellow) seven_ani = vp.sphere(pos=vp.vector(radius_z * mp.cos(angles[7]), radius_z * mp.sin(angles[7]), 0), radius=radius_z * 0.05, canvas=c, color=color.blue) eight_ani = vp.sphere(pos=vp.vector(radius_z * mp.cos(angles[8]), radius_z * mp.sin(angles[8]), 0), radius=radius_z * 0.05, canvas=c, color=color.yellow) nine_ani = vp.sphere(pos=vp.vector(radius_z * mp.cos(angles[9]), radius_z * mp.sin(angles[9]), 0), radius=radius_z * 0.05, canvas=c, color=color.blue) #Sets a pointer pointer = arrow(pos=vp.vector(0, 0, 0), axis=vp.vector(radius_z, 0, 0), shaftwidth=1) #Labels Distance distance = label(pos=vp.vector( float(radius_z) / 2, float(radius_z) * 0.2, 0), text='Radius = ' + str(radius_z) + "m") #Labels angular velocity ang_vel = label(pos=vp.vector(0, -float(radius_z) * 0.5, 0), text='Omega = ' + str(omega_z) + "rad/s") for time in np.arange( 0, 100000, 1 ): #This for loop updates the positions of the spheres to create "rotation". rate(5) zero_ani_x = (radius_z) * mp.cos( ((2 * mp.pi * time) / period) + angles[0]) #updates x position zero_ani_y = (radius_z) * mp.sin( ((2 * mp.pi * time) / period) + angles[0]) #updates y position zero_ani.pos = vp.vector(zero_ani_x, zero_ani_y, 0) one_ani_x = (radius_z) * mp.cos(( (2 * mp.pi * time) / period) + angles[1]) one_ani_y = (radius_z) * mp.sin(( (2 * mp.pi * time) / period) + angles[1]) one_ani.pos = vp.vector(one_ani_x, one_ani_y, 0) two_ani_x = (radius_z) * mp.cos(( (2 * mp.pi * time) / period) + angles[2]) two_ani_y = (radius_z) * mp.sin(( (2 * mp.pi * time) / period) + angles[2]) two_ani.pos = vp.vector(two_ani_x, two_ani_y, 0) three_ani_x = (radius_z) * mp.cos(( (2 * mp.pi * time) / period) + angles[3]) three_ani_y = (radius_z) * mp.sin(( (2 * mp.pi * time) / period) + angles[3]) three_ani.pos = vp.vector(three_ani_x, three_ani_y, 0) four_ani_x = (radius_z) * mp.cos(( (2 * mp.pi * time) / period) + angles[4]) four_ani_y = (radius_z) * mp.sin(( (2 * mp.pi * time) / period) + angles[4]) four_ani.pos = vp.vector(four_ani_x, four_ani_y, 0) five_ani_x = (radius_z) * mp.cos(( (2 * mp.pi * time) / period) + angles[5]) five_ani_y = (radius_z) * mp.sin(( (2 * mp.pi * time) / period) + angles[5]) five_ani.pos = vp.vector(five_ani_x, five_ani_y, 0) six_ani_x = (radius_z) * mp.cos(( (2 * mp.pi * time) / period) + angles[6]) six_ani_y = (radius_z) * mp.sin(( (2 * mp.pi * time) / period) + angles[6]) six_ani.pos = vp.vector(six_ani_x, six_ani_y, 0) seven_ani_x = (radius_z) * mp.cos(( (2 * mp.pi * time) / period) + angles[7]) seven_ani_y = (radius_z) * mp.sin(( (2 * mp.pi * time) / period) + angles[7]) seven_ani.pos = vp.vector(seven_ani_x, seven_ani_y, 0) eight_ani_x = (radius_z) * mp.cos(( (2 * mp.pi * time) / period) + angles[8]) eight_ani_y = (radius_z) * mp.sin(( (2 * mp.pi * time) / period) + angles[8]) eight_ani.pos = vp.vector(eight_ani_x, eight_ani_y, 0) nine_ani_x = (radius_z) * mp.cos(( (2 * mp.pi * time) / period) + angles[9]) nine_ani_y = (radius_z) * mp.sin(( (2 * mp.pi * time) / period) + angles[9]) nine_ani.pos = vp.vector(nine_ani_x, nine_ani_y, 0)
d.autoscale = False vp.rate(1000) # Create an array of 1000 spheres # Create another array of the same length to mark the maximums s_array = np.empty(n, vp.sphere) m_array = np.empty(n, vp.sphere) for i in range(n): s_array[i] = vp.sphere(radius=r, color=vp.color.red) m_array[i] = vp.sphere(radius=r, color=vp.color.green) # Create a black sphere to mark the origin origin = vp.sphere(radius=0.15, color=vp.color.black) # Create rings to represent the RMS of spheres and maxes sph_rin = vp.ring(axis=vp.vector(0, 0, 1), thickness=0.1, color=vp.color.red) max_rin = vp.ring(axis=vp.vector(0, 0, 1), thickness=0.1, color=vp.color.green) start = t.time() # Move the n spheres randomly for j in range(iterations): r_sum = 0 m_sum = 0 for i in range(n): dx = (2 * ran.random() - 1) * s dy = (2 * ran.random() - 1) * s s_array[i].pos += vp.vector(dx, dy, 0) # Calculate distances and sums from origin
################################################################################ colors = [vp.color.red, vp.color.orange, vp.color.yellow,\ vp.color.green, vp.color.white, vp.color.magenta] vspin_sphere = vp.sphere(pos=vp.vector(-3,0,0),radius=2,\ color=vp.color.blue, opacity=0.4) vspin_layers = [vp.sphere(pos=vspin_sphere.pos+vspin_sphere.radius*vp.vector(*qubit_xyz(SV[i])),\ color=colors[i], radius=0.5, opacity=SL[i]) for i in range(spin_n)] vspin_arrow = vp.arrow(pos=vspin_sphere.pos, axis=vspin_sphere.radius*vp.vector(*qubit_xyz(spin_part))) ################################################################################ vclock_ring = vp.ring(pos=vp.vector(2,0,0), axis=vp.vector(0,0,1),\ color=vp.color.red,\ radius=1, thickness=0.1, opacity=0.5) roots_of_unity = [np.exp(2*np.pi*1j*i/clock_n) for i in range(clock_n)] directions = [vp.vector(roots_of_unity[i].real,\ roots_of_unity[i].imag,\ 0) for i in range(clock_n)] vclock_arrows = [vp.arrow(pos=vclock_ring.pos,\ axis=directions[i],\ opacity=clock_probs[i]) for i in range(clock_n)] vprojarrow = vp.arrow(pos=vclock_ring.pos, color=vp.color.white, opacity=0.7,\ visible=False) ################################################################################
##calculo del vector normal: normal = vp.hat(vect_inter) ##calculo el nuevo vector velocidad dado el choque: v_f = redireccion(obj.vel, normal) ##calculo nuevo vector posición: obj.pos = vect_inter + dt * v_f ##actualizo el vector posicion inicial y vector velocidad: obj.vel = v_f obj.pos_0 = vect_inter p_0 = vp.vector(-1, 0, 0) #<- se puede cambiar posicion inicial v = vp.vector(1, 1, 0) #<- se puede cambiar velocidad inicial particula = vp.sphere(pos=p_0, radius=0.25) #<- se puede cambiar el radio vp.ring( pos=vp.vector(0, 0, 0), axis=vp.vector(0, 0, 1), radius=25, thickness=0.1 ) #<- debe cambiar el radio si cambia el radio arriba este es el exterior vp.ring( pos=vp.vector(0, 0, 0), axis=vp.vector(0, 0, 1), radius=10, thickness=0.1 ) #<- debe cambiar el radio si cambia el radio arriba este es el interior particula.vel = v #particula.pos_0 = p_0 <- checar notas de pelota_caja_circular camino = vp.curve(color=vp.vector(1, 0, 0)) t = 0 dt = 0.01 #<- se puede cambiar el paso temporal radio_ext = 25 #<- se puede cambiar condicion exterior de la caja radio_int = 10 #<- se puede cambiar condicion interior de la caja while t < 1:
vp.cylinder(pos=vp.vector(-2, 2, 1.25), radius=0.7, axis=vp.vector(0, 0, -2.5), color=vp.color.blue) ball = vp.sphere(pos=vp.vector(2, 1, 0), radius=0.5, color=vp.color.cyan) ptr = vp.arrow(pos=vp.vector(0, 0, 2), axis=vp.vector(2, 0, 0), color=vp.color.yellow) vp.cone(pos=vp.vector(-2, 0, 0), radius=1, length=3, color=vp.color.green, opacity=0.3) vp.ring(pos=vp.vector(.2, 0, 0), radius=.6, axis=vp.vector(1, 0, 0), thickness=0.12, color=vp.color.gray(0.4)) vp.ellipsoid(pos=vp.vector(-.3, 2, 0), color=vp.color.orange, size=vp.vector(.3, 1.5, 1.5)) vp.pyramid(pos=vp.vector(.3, 2, 0), color=vp.vector(0, 0.5, .25), size=vp.vector(0.8, 1.2, 1.2)) spring = vp.helix(pos=vp.vector(2, -1.25, 0), radius=0.3, axis=vp.vector(0, 1.8, 0), color=vp.color.orange, thickness=.1) angle = 0 da = .01
stator_number = 8 stator_r = 0.1 # 1 = 10 nm stator_thickness = 0.03 # 1er biais : Mauvaise valeur de D possible # turn_per_nanosec = 1/dt dt = 1/30 # correspond au petit tho step_size = 0.02 # rad angle = 0 sphere_state = [] time_list = [] max_stator = 8 tot_sphere = 1 list_stator_pos = [ v.ring(pos=v.vector(0.8*m.cos(2 * np.pi * x / max_stator), 0.8*m.sin(2 * np.pi * x / max_stator), 0), axis=v.vector(0, 0, 1), radius=stator_r, thickness=stator_thickness, color=v.color.green) for x in range(max_stator)] coef_red_vol = 1 height = 9 # 1 = 10 nm width = 9 length = 9 tot_time = 0 a = 0.0475 turn = 0.0 D_th = a**2/dt # = 1.13*10^-2 (10nm)²/ns tour_de_boucle = 0 nb_step = 0 # h_cube = (height/a)