def calculateTotalEnergy(self): """ this method calculates the total energy of the system by adding the kinetic and potential energies together. """ self.potEnergy = Planet.calculatePotentialEnergy(self.listPlanets) self.sumKineticEnergy = Planet.calculateTotalKineticEnergy( self.listPlanets) self.totalEnergy = self.sumKineticEnergy + self.potEnergy
def setup(): global LeftPlanet,RightPlanet p5.scale(1,-1) p5.size(1500,700) p5.translate(0,-height) LeftPlanet=Planet(0,height/2,1,[10,0],25,trail=1) LeftPlanet.pos.x+=LeftPlanet.r RightPlanet=Planet(width,height/2,1,[-10,0],25,trail=1) RightPlanet.pos.x-=RightPlanet.r
def definePlanets(): global Sun Sun = Planet(modes[scale.val]['sizes'][0], Vector(modes[scale.val]['AUs'][0], 0), modes[scale.val]['momentum'][0], (255, 255, 0, 255), 'Sun', modes[scale.val]['AUs'][0], modes[scale.val]['mass'][0], velocities[0], 0) Mercury = Planet(modes[scale.val]['sizes'][1], Vector(modes[scale.val]['AUs'][1], 0), modes[scale.val]['momentum'][1], (200, 200, 200, 255), 'Mercury', modes[scale.val]['AUs'][1], modes[scale.val]['mass'][1], velocities[1], 0) Venus = Planet(modes[scale.val]['sizes'][2], Vector(modes[scale.val]['AUs'][2], 0), modes[scale.val]['momentum'][2], (255, 200, 0, 255), 'Venus', modes[scale.val]['AUs'][2], modes[scale.val]['mass'][2], velocities[2], 0) Earth = Planet(modes[scale.val]['sizes'][3], Vector(modes[scale.val]['AUs'][3], 0), modes[scale.val]['momentum'][3], (0, 0, 255, 255), 'Earth', modes[scale.val]['AUs'][3], modes[scale.val]['mass'][3], velocities[3], 0) Mars = Planet(modes[scale.val]['sizes'][4], Vector(modes[scale.val]['AUs'][4], 0), modes[scale.val]['momentum'][4], (255, 0, 0, 255), 'Mars', modes[scale.val]['AUs'][4], modes[scale.val]['mass'][4], velocities[4], 0) Jupiter = Planet(modes[scale.val]['sizes'][5], Vector(modes[scale.val]['AUs'][5], 0), modes[scale.val]['momentum'][5], (255, 87, 51, 255), 'Jupiter', modes[scale.val]['AUs'][5], modes[scale.val]['mass'][5], velocities[5], 0) Saturn = Planet(modes[scale.val]['sizes'][6], Vector(modes[scale.val]['AUs'][6], 0), modes[scale.val]['momentum'][6], (255, 195, 0, 255), 'Saturn', modes[scale.val]['AUs'][6], modes[scale.val]['mass'][6], velocities[6], 0) Uranus = Planet(modes[scale.val]['sizes'][7], Vector(modes[scale.val]['AUs'][7], 0), modes[scale.val]['momentum'][7], (0, 100, 255, 255), 'Uranus', modes[scale.val]['AUs'][7], modes[scale.val]['mass'][7], velocities[7], 0) Neptune = Planet(modes[scale.val]['sizes'][8], Vector(modes[scale.val]['AUs'][8], 0), modes[scale.val]['momentum'][8], (0, 255, 255, 255), 'Neptune', modes[scale.val]['AUs'][8], modes[scale.val]['mass'][8], velocities[8], 0) Pluto = Planet(modes[scale.val]['sizes'][9], Vector(modes[scale.val]['AUs'][9], 0), modes[scale.val]['momentum'][9], (255, 255, 255, 255), 'Pluto', modes[scale.val]['AUs'][9], modes[scale.val]['mass'][9], velocities[9], 0)
def getInformationPlanets(self): """ This method gets all the information about the planets from the file. It also adds a satellite with custrom parameters (but not from the file). """ line = self.f.readline() while line is not "\n": try: planetName = line[:line.index("\n")] planetMass = self.getNumber() planetInitPosx = self.getNumber() planetInitPosy = self.getNumber() planetInitPos = np.array([planetInitPosx, planetInitPosy]) planetInitVelx = self.getNumber() planetInitVely = self.getNumber() planetInitVel = np.array([planetInitVelx, planetInitVely]) planetRadius = self.getNumber() planetColour = self.getString() except: print( "There was a problem while getting information from the file." ) quit() planet = Planet(planetName, planetMass, planetInitPos, planetInitVel, planetRadius, planetColour) self.listPlanets.append(planet) self.listPatches.append(planet.patch) line = self.f.readline() # we also include a satellite that we implement here satName = "Satellite" satMass = 500000 satInitPos = np.array([1.5e+11 + 100, 0]) satInitVelx = 11500 satInitVely = -800 satInitVel = np.array([satInitVelx, satInitVely + 29748.485675745]) satRadius = 928e+6 satColour = "#000000" Satellite = Planet(satName, satMass, satInitPos, satInitVel, satRadius, satColour) self.listPlanets.append(Satellite) self.listPatches.append(Satellite.patch)
def setup(): global planet, moon p5.scale(1, -1) p5.size(1500, 700) p5.translate(0, -height) planet = Planet(width / 2, height / 2, 20, [0, 0], 500, trail=0) moon = Planet(width / 2, planet.pos.y + planet.r + 50, 1, [0, 0], 10, trail=1) #0,1,2,5,7,7.5,7.7,7.8,7.82 min_orbit_vx = np.sqrt( ((G * planet.m) / (abs(moon.initpos.y - planet.initpos.y)))) #moon.vel.x=min_orbit_vx print(min_orbit_vx)
def setup(): global PlanetLeft, PlanetRight p5.size(500, 500) PlanetLeft = Planet(width / 2 - 100, height / 2, 1, [1, 1], 10, trail=1) PlanetRight = Planet(width / 2 + 100, height / 2, 1, [-1, 1], 10, trail=1)
sf += modes[scale.val]['dzoom'][0] pathLayer.fill((0, 0, 0)) if event.type == pg.MOUSEBUTTONUP: if event.button == 1: if growtime > 0.8: coord = Vector(sf * (mouse[0] - 400), sf * (mouse[1] - 400)) vi = modes[scale.val]['AUs'].index( min(modes[scale.val]['AUs'], key=lambda x: abs(x - coord.mag))) v = velocities[vi] off = (atan2(planets[vi].vector.y, planets[vi].vector.x) % (2 * pi)) - atan2(coord.y, coord.x) new = Planet(int(growtime / 2), coord, Vector(0, 0.02 * growtime), (randint(0, 255), randint( 0, 255), randint(0, 255), 255), f'new{len(planets)-9}', coord.mag, growtime * 0.01, v, off) growing = False growtime = 0 else: growtime = 0 growing = False curDt = modes[scale.val]['dt'][gravity.val] * vMul pg.draw.rect(display, (255, 255, 0), (800, -1, controlWidth + 1, 802), 1) pg.draw.rect(display, (255, 255, 0), (800, 460, controlWidth + 1, 340), 1) display.blit(mode_message, (820, 20)) display.blit(grav_message, (820, 80)) display.blit(linZoom_message, (820, 140))