KingOfWesteros

MoniqueUFRJ

Apr 23rd, 2021
509
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import turtle
  2. import Math
  3.  
  4. class SolarSystem
  5.  
  6.     def _init_(self, width, height)
  7.         self.thesun = None
  8.         self.planets = []
  9.         self.ssturtle = turtle.Turtle()
  10.         self.ssturtle.hideturtle()
  11.         self.ssscreen = turtle.Screen()
  12.         self.ssscreen.setworldcoordinates(-width/2.0,-height/2.0,width/2.0,height/2.0)
  13.          self.ssscreen.tracer(50)
  14.  
  15.     def addPlanet(self, aplanet)
  16.         self.planets.append(aplanet)
  17.  
  18.     def addSun(self, asun)
  19.         self.thesun = asun
  20.  
  21.     def showPlanetas(self)
  22.         for aplanet in self.planets
  23.             print(aplanet)
  24.  
  25.     def freeze(self)
  26.         self.ssscreen.exitonclick()
  27.  
  28.     def movePlanets(self)
  29.         G = 0.1
  30.         dt = 0,001
  31.  
  32.         for p in self.planets
  33.            p.moveTo(p.getXPos() + dt * p.getXVel(), p.getYPos() + dt * p.getYVel())
  34.  
  35.            rx = self.thesun.getXPos() - p.getXPos()
  36.            ry = self.thesun.getYPos() - p.getYPos()
  37.            r = math.sqrt(rx*2 + ry*2)
  38.  
  39.            accx = G * self.thesun.getMass()rx/r*3
  40.            accy = G * self.thesun.getMass()ry/r*3
  41.  
  42.            p.setXVel(p.getXVel() + dt * accx)
  43.  
  44.            p.setYVel(p.getYVel() + dt * accy)
  45.  
  46. class Sun
  47.    def _init_(iname, irad, im, itemp)
  48.        self.name = iname
  49.        self.radius = irad
  50.        self.mass = im
  51.        self.temp = itemp
  52.        self.x = 0
  53.        self.y = 0
  54.  
  55.        self.sturtle = turtle.Turtle()
  56.        self.sturtle.shape("circle")
  57.        self.sturtle.color("yellow")
  58.  
  59.    def getName(self)
  60.        return self.name
  61.  
  62.    def getRadius(self)
  63.        return self.radius
  64.  
  65.    def getMass(self)
  66.        return self.mass
  67.  
  68.    def getTemperature(self)
  69.        return self.temp
  70.  
  71.    def getVolume(self)
  72.        v = 4.0/3 * math.pi * self.radius**3
  73.        return v
  74.  
  75.    def getSurfaceArea(self)
  76.        sa = 4.0 * math.pi * self.radius**2
  77.        return sa
  78.  
  79.    def getDensity(self)
  80.        d = self.mass / self.getVolume()
  81.        return d
  82.  
  83.    def setName(self, newname)
  84.        self.name = newname
  85.  
  86.    def _str_(self)
  87.        return self.name
  88.  
  89.    def getXPos(self)
  90.        return self.x
  91.  
  92.    def getYPos(self)
  93.        return self.y
  94.  
  95. class Planet
  96.  
  97.    def _init_(self, iname, irad, im, idist, ivx, ivy, ic):
  98.        self.name = iname
  99.        self.radius = irad
  100.        self.mass = im
  101.        self.distance = idist
  102.        self.x = idist
  103.        self.y = 0
  104.        self.velx = ivx
  105.        self.vely = ivy
  106.        self.color = ic
  107.  
  108.        self.pturtle = turtle.Turtle()
  109.        #self.pturtle.speed('fast')
  110.        self.pturtle.up()
  111.        self.pturtle.color(self.color)
  112.        self.pturtle.shape("circle")
  113.        self.pturtle.goto(self.x,self.y)
  114.        self.pturtle.down()
  115.  
  116.    def getName(self)
  117.        return self.name
  118.  
  119.    def getRadius(self)
  120.        return self.radius
  121.  
  122.    def getMass(self)
  123.        return self.mass
  124.  
  125.    def getDistance(self)
  126.        return self.distance
  127.  
  128.    def getVolume(self)
  129.        v = 4.0/3 * math.pi * self.radius**3
  130.        return v
  131.  
  132.    def getSurfaceArea(self)
  133.        sa = 4.0 * math.pi * self.radius**2
  134.        return sa
  135.  
  136.    def getDensity(self)
  137.        d = self.mass / self.getVolume()
  138.        return d
  139.  
  140.    def setName(self, newname)
  141.        self.name = newname
  142.  
  143.    def show(self)
  144.         print(self.name)
  145.  
  146.    def _str_(self)
  147.        return self.name
  148.  
  149.    def moveTo(self, newx, newy)
  150.        self.x = newx
  151.        self.y = newy
  152.        self.pturtle.goto(newx, newy)
  153.  
  154.    def getXPos(self)
  155.        return self.x
  156.  
  157.    def getYPos(self)
  158.        return self.y
  159.  
  160.    def getXVel(self)
  161.        return self.velx
  162.  
  163.    def getYVel(self)
  164.        return self.vely
  165.  
  166.    def setXVel(self, newvx)
  167.        self.velx = newvx
  168.  
  169.    def setYVel(self, newvy)
  170.        self.vely = newvy
  171.  
  172.  
  173. def createSSandAnimate()
  174.    ss = SolarSystem(2,2)
  175.  
  176.    sun = Sun("SUN", 5000, 10, 5800)
  177.    ss.addSun(sun)
  178.  
  179.  
  180.    m = Planet("MERCURY", 19.5, 1000, .25, 0, 2, "blue")
  181.    ss.addPlanet(m)
  182.  
  183.    m = Planet("EARTH", 47.5, 5000, 0.3, 0, 2.0, "green")
  184.    ss.addPlanet(m)
  185.  
  186.    m = Planet("MARS", 50, 9000, 0.5, 0, 1.63, "red")
  187.    ss.addPlanet(m)
  188.  
  189.    m = planet("JUPITER", 100, 49000, 0.7, 0, 1, "black")
  190.    ss.addPlanet(m)
  191.  
  192.    m = Planet(Pluto, 1, 500, 0.9, 0, .5, "orange")
  193.    ss.addPlanet(m)
  194.  
  195.    m = Planeta("Asteroid", 1, 500, 1.0, 0, .75, "cyan")
  196.    ss.addPlanet(m)
  197.  
  198.    numTimePeriods = 10000
  199.    for amove in range(numtimePeriods)
  200.         ss.movePlanets()
  201.  
  202.    ss.freeze()
  203.  
  204. createSSAndAnimate()
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×