# Solar system animation issue

**URL:** <https://discourse.processing.org/t/solar-system-animation-issue/44308>\
**Category:** Processing.py\
**Created:** [April 18, 2024, 12:58am UTC](https://discourse.processing.org/t/solar-system-animation-issue/44308 "2024-04-18T00:58:38Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ray0204](https://avatars.discourse-cdn.com/v4/letter/r/848f3c/32.png) [@Ray0204](https://discourse.processing.org/u/Ray0204)\
**Post date:** [April 18, 2024, 12:58am UTC](https://discourse.processing.org/t/solar-system-animation-issue/44308/1 "2024-04-18T00:58:38Z")

</div>

Hi, everyone, I encountered an issue while creating a solar system animation in Python mode. When running the program, instead of the new planets orbiting the sun, they rapidly flicker and then disappear. Upon single-frame observation, I noticed that the positions of the planets keep changing in all four directions around the sun, and the distances increase rapidly over time. However, I couldn’t identify the problem in my code. I hope someone can help me. Thank you very much!

Below is the code:

```auto

from Planet import planet
add_library('peasycam')

def setup():
    size(800,600,P3D)
    global sun
    cam = PeasyCam(this, 400)
    sun = planet(50,0,0)
    sun.spawnMoons(3,1)
    # frameRate(1)
    
def draw():
    background(0)
    lights()
    sun.show()
    sun.orbit()
    # push()
    # fill(255)
    # text (len(sun.planets), 10, 10)
    # text (sun.planets[0].v.x, 20, 20)
    # text (sun.planets[0].v.x,20, 40)
    # text (sun.planets[0].v.x, 30, 60)
    # pop()

class planet:
    
    def __init__ (self, r, d, o):
        self.v = PVector.random3D()
        self.radius = r
        self.distance = d
        self.v.mult(self.distance)
        self.angle = random(TWO_PI)
        self.orbitspeed = o
        self.planets = []
        
    def orbit(self):
        self.angle = self.angle + self.orbitspeed
        if len(self.planets) > 0:
            for i in self.planets:
                i.orbit()
                
    def spawnMoons(self, total, level):

        for i in range(total):
            r = self.radius / (level * 2)
            # d = random(self.radius + r, (self.radius + r) * 2)
            d = random(self.radius + r, self.radius + r * 3)
            o= random(-0.01, 0.01)
            self.planets.append(planet(r, d, o))
            if level <2 :
                num = int(random(0,3))
                self.planets[i].spawnMoons(num, level + 1)
                
    def show(self):
        pushMatrix()
        noStroke()
        v2 = PVector(1, 0, 1)
        p = self.v.cross(v2)
        rotate(self.angle, p.x, p.y, p.z)
        stroke(255)
        line(0,0,0, self.v.x, self.v.y, self.v.z)
        line(0,0,0, p.x, p.y, p.z)
        translate(self.v.x, self.v.y, self.v.z)
        noStroke()
        fill(255)
        sphere(self.radius)
        if len(self.planets) > 0:
            for i in range(len(self.planets)):
                self.planets[i].show()
        popMatrix()

```

---

<div class="post-metadata">

**Author:** ![Ray0204](https://avatars.discourse-cdn.com/v4/letter/r/848f3c/32.png) [@Ray0204](https://discourse.processing.org/u/Ray0204)\
**Post date:** [April 18, 2024, 1:41am UTC](https://discourse.processing.org/t/solar-system-animation-issue/44308/2 "2024-04-18T01:41:47Z")

</div>

And this is the my reference code in p5.js . when I convert it to Python code it does not work: [p5.js Web Editor](https://editor.p5js.org/codingtrain/sketches/QIB-sT10)

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [April 18, 2024, 9:15am UTC](https://discourse.processing.org/t/solar-system-animation-issue/44308/3 "2024-04-18T09:15:48Z")

</div>

it looks pretty good in p5.js and is working?

maybe give the sun, the planets and the moons different color? Or even use texture.

 ![mars](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/7/a/7aa0d8b93c8cf6e24ce8afabd3840dd24045b249.jpeg)  
 ![saturn](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/2/5/2569d76e09f354df993b5eb7d88d15d615ae853f.jpeg)  
 ![sun](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/a/c/ac5d5d9704ec5cdc0ccf194a496f74f642de488b.jpeg)  
 ![earth](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/1/0/105a10ffb729b3035c57e234152d017d8cee160a.jpeg)

---

<div class="post-metadata">

**Author:** ![Ray0204](https://avatars.discourse-cdn.com/v4/letter/r/848f3c/32.png) [@Ray0204](https://discourse.processing.org/u/Ray0204)\
**Post date:** [April 19, 2024, 5:20am UTC](https://discourse.processing.org/t/solar-system-animation-issue/44308/4 "2024-04-19T05:20:25Z")

</div>

Thank you for your reply. I apologize for not clarifying the issue I encountered: the P5.js code is my reference code, and for some reason, it does not work when I convert it to Python code. Thank you very much for the screenshots you provided.

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [April 19, 2024, 6:22am UTC](https://discourse.processing.org/t/solar-system-animation-issue/44308/5 "2024-04-19T06:22:22Z")

</div>

Not really screenshots

Those are textures you can use

---

<div class="post-metadata">

**Author:** ![Ray0204](https://avatars.discourse-cdn.com/v4/letter/r/848f3c/32.png) [@Ray0204](https://discourse.processing.org/u/Ray0204)\
**Post date:** [April 19, 2024, 6:39am UTC](https://discourse.processing.org/t/solar-system-animation-issue/44308/6 "2024-04-19T06:39:34Z")

</div>

The problem has been solved.
