r/Python • • Oct 10 '19

Just trying to create a orbit system in python and this happened...

5.2k Upvotes

357 comments sorted by

711

u/Grow-away123 Oct 10 '19

When my code messes up I get error messages meanwhile you’re over here making art

283

u/LAMagicx Oct 10 '19

I went through plenty of errors to get to that stage. But the best bit is that it was a complete accident that this happened.

89

u/Terence_McKenna Oct 10 '19

Some of the greatest discoveries have been completely accidental/unintentional.

Thanks for sharing! :)

39

u/planx_constant Oct 11 '19

One of the things that sparked modern chaos theory was when Lorenz discovered by accident that tiny variations in the input to a computer weather model could result in profoundly different evolutions.

13

u/strangemagic365 Oct 11 '19

Like chocolate chip cookies!

→ More replies (3)

35

u/muntoo R_{μν} - 1/2 R g_{μν} + Λ g_{μν} = 8π T_{μν} Oct 11 '19

I liked the part where it aliased and looked like it suddenly switched directions.

But if you hate art, you might want to try symplectic methods and ensure conservation of energy. That's the easiest way to stop those damn pesky artists from taking our coding jobs. Build a wall of conserved energy, I say.

7

u/lolfunctionspace Oct 11 '19

Yep, the Semi-implicit Euler method is the easiest way to conserve energy for n body gravity sims.

For each particle, at each time step, first calculate the force (acceleration) for it at timestep n, then use that to calculate the velocity of the particle at timestep n+1, then use the n+1 velocity to calculate the position at timestep n+1.

When what the velocity of the particle would be at the n+1 timestep is used to calculate the position at the n+1 timestep, all of your error perturbations go away and you stop getting runaway increases or decreases in system energy.

→ More replies (1)

20

u/[deleted] Oct 10 '19

That wasn't an accident. That was a happy mistake

10

u/shiroshiro14 Oct 11 '19

We don't make mistake, just happy accident.

→ More replies (1)
→ More replies (4)

23

u/[deleted] Oct 11 '19

“Help my program is broken!” .... “ok what was the return code lets start from there” ... “a spirograph” ... “oooook”

→ More replies (1)

5

u/Python_Automation_ Oct 10 '19

This made me laugh 😆

3

u/ColdPorridge Oct 11 '19

I don’t even get errors, I just notice that all the numbers I’ve been reporting for months are off by an order of magnitude.

2

u/tmdag Oct 11 '19

Have you ever heard about screen capture programs ? ;)

449

u/lilgreenwein Oct 10 '19

did you just solve the 3 body problem?

58

u/LAMagicx Oct 10 '19

I highly doubt it. It's more like a simulation of the 3 body problem.

→ More replies (5)

152

u/a22e Oct 10 '19

The Trisolarans will be ecstatic!

59

u/[deleted] Oct 10 '19

Just don't send the location!

34

u/a22e Oct 10 '19

Fuck.

Oh well, what's the worst that could happen?

→ More replies (11)

21

u/Huntred Oct 10 '19

REHYDRATE!!!

11

u/captain_wiggles_ Oct 10 '19

The 3 body problem has several known solutions for initial start states. The problem is that there's no know way to calculate ALL future states for ALL initial start states. Simulating a particular case is easy enough, but that's not the same as solving the problem.

In the book, they use the human computer thing as a simulation to find what happens next, over the next X years or whatever. Obviously they get it wrong, but that's not the point here. The point is if they had computers then they'd easily be able to calculate future states for their system, since the start state is known. Finally that simulation would grow more and more inaccurate as time progresses, due to the fact that even a 3 body simulation is a prediction (it doesn't take into account other masses, such as asteroids / moons / other planets / etc...), and it's based on a measured start state, and that measurement will have an error.

2

u/[deleted] Oct 11 '19

this is a similar website. solarsim.net generation algorithms being ran in the background

→ More replies (2)

185

u/the_dancing_squirel Oct 10 '19

You should definitely save this as a full on programm/script

90

u/LAMagicx Oct 10 '19

Oh yeah! I've just made a new file and copied it over. Now just messing with more variables.

73

u/the_dancing_squirel Oct 10 '19

Do you mind sharing it? Like on GitHub or somewhere else? Just out if curiosity

20

u/LAMagicx Oct 11 '19

You can now find the source code at https://github.com/LAMagicx/OrbitalArt , I would love to see what you can come up with.

17

u/Borahulo100 Oct 10 '19

Agree, please share on Github!

7

u/Charlesssssss7 Oct 10 '19

Please share the codeeee

→ More replies (2)
→ More replies (1)

6

u/paintthedaytimeblack Oct 10 '19

Yeah agreed I need Hyperspace Turtle

1

u/LAMagicx Oct 11 '19

You can now find the source code at https://github.com/LAMagicx/OrbitalArt , I would love to see what you can come up with.

→ More replies (3)

8

u/Who_The_Fook Oct 10 '19 edited Oct 11 '19

Bruh please share the code, I'd love to see how this works. Even if it's for something close to but not the same as this. I'm out here still learning Java rn but this shit is so cool looking.

2

u/LAMagicx Oct 11 '19

You can now find the source code at https://github.com/LAMagicx/OrbitalArt , I would love to see what you can come up with.

→ More replies (1)
→ More replies (1)

9

u/YellowOnion Oct 11 '19

made a new file and copied it over.

Learn git, it's a lot easier to track your changes, plus you can revert if you decide later you changes were a mistake.

1

u/sebaseek Oct 11 '19

Share it on github! I will fork it

1

u/LAMagicx Oct 11 '19

You can now find the source code at https://github.com/LAMagicx/OrbitalArt , I would love to see what you can come up with.

→ More replies (1)

46

u/[deleted] Oct 10 '19

You've created life, my friend

27

u/LAMagicx Oct 10 '19

Funnily enough I'm studying emergence for a school project. And this is just the start

21

u/Lard_of_Dorkness Oct 10 '19

this is just the start

That's how emergence works, right?

14

u/LAMagicx Oct 10 '19

Hopefully yeah..

6

u/BadPercussionist Oct 11 '19

Wait, you can study 177013?

→ More replies (1)

4

u/BlitzFuer Oct 11 '19

Futuristic beings materialize in your office “TimeLord you must come with us, we will explain everything, but your life, and our existence is in danger.”

→ More replies (1)

37

u/psharpep Oct 10 '19 edited Oct 10 '19

Cool work!

A word of advice: assuming you're modeling gravity with a 1/r2 kernel function, it looks like you've got a lot of error due to your time integration scheme here! (The most immediately apparent indication: the orbital decay shows that the total energy of your system is changing with respect to time, when it should be fixed.)

What integration scheme did you implement here? Maybe you could try a higher-order method like RK4?

An alternative would be to use kinetic energy, location (potential energy), and direction of motion as your state variables, or to do a total-energy compensation step at each timestep!

15

u/LAMagicx Oct 10 '19

Thanks! The kinetic and potential energy sounds great I will try to implement that for the actual system. This is more of a sandbox type simulation because I'm changing the force of gravity to become more and more powerful, hence why the orbital decay. In this I'm not trying to model an orbit however the base of it is an orbital model.

btw I have no idea if its a kernal function or what a integration scheme is and the RK4 method is beyond me (for now).

7

u/namesnonames Oct 10 '19

I'd have to guess you are doing Euler integration then. Could you share the source?

1

u/LAMagicx Oct 11 '19

You can now find the source code at https://github.com/LAMagicx/OrbitalArt , I would love to see what you can come up with.

→ More replies (1)

5

u/masasin Expert. 3.9. Robotics. Oct 10 '19

You're probably using Euler. Try leapfrogging? And RK4 has complicated symbols, but it's easy when you translate it to code. (See if you can find a code example.)

5

u/billsil Oct 11 '19

RK4 is notoriously inaccurate for orbits. A single orbital period can have large truncation error, let alone 10000. It’s better than Euler though. It’s not energy preserving though and there are methods that are similar to RK4 in complexity that are.

→ More replies (4)
→ More replies (1)

7

u/AnomalousLurker Oct 10 '19

Would a symplectic integration scheme not work better here?

3

u/psharpep Oct 11 '19

Yes, it would - that'd be better than either Euler or RK4 for this kind of problem since it's inherently conservative!

You'd have to reformulate the physics of the problem with some sort of conservation law (i.e. move towards Hamiltonian mechanics), which is kind of what I was trying to hint at with my last idea there.

→ More replies (1)

3

u/[deleted] Oct 11 '19

you need a symplectic integration scheme for this to work. energy is not properly conserved in RK4. the easiest one is probably velocity verlet which is second order but symplectic.

2

u/novel_eye Oct 10 '19

Mind sharing some links? I’m doing an orbit simulation for the solar system and I’ve been using Verlet integration but would like to do some more classical mechanics based integration. Having trouble finding a link with enough rigor for good implementation without bogging me down with physics I’m unfamiliar with.

→ More replies (1)

11

u/squidly-diddly97 Oct 10 '19

sauce ?

[source code(if you don't mind, please) ?]

EDIT: politeness

1

u/LAMagicx Oct 11 '19

Of course my dear kind polite friend, you can now find the source code at https://github.com/LAMagicx/OrbitalArt , I would love to see what you can come up with.

→ More replies (1)

19

u/nandrajrathod Oct 10 '19

It's Awesome. Can you please pass the code?

1

u/LAMagicx Oct 11 '19

You can now find the source code at https://github.com/LAMagicx/OrbitalArt , I would love to see what you can come up with.

→ More replies (1)

6

u/Pissed_Off_Penguin Oct 10 '19

Noob here! Is pygame a good way to plot data quickly? I'm working on a Lidar thing and I would like to find a way to plot the scans a little faster than matplotlib scatter.

3

u/LAMagicx Oct 10 '19

I was going to suggest matplotlib but seeing as you've already done that then pygame is the next step. Just have to add a bit more code to make it possible.

3

u/[deleted] Oct 10 '19

Dude, that is awesome! Like everyone else is saying: would you mind sharing the sourcecode?

8

u/LAMagicx Oct 10 '19

Yeah I know but if I do that I'm going to spruce it up and make sure it's understandable.

3

u/[deleted] Oct 10 '19

Totally ok with me!

1

u/LAMagicx Oct 11 '19

You can now find the source code at https://github.com/LAMagicx/OrbitalArt , I would love to see what you can come up with.

113

u/el_matt [for i in lst comprehend(i)] Oct 10 '19

r/dark

Sic mundus creatus est.

27

u/pdiego96 Oct 10 '19

Der Anfang is das Ende. Und das Ende ist der Anfang.

7

u/anselminie Oct 10 '19

Exactly my thoughts on this

→ More replies (1)

38

u/plontx Oct 10 '19

Did you stop recording bc it stabilizes at that point? I feel like it ended too soon, I'd love to watch this for hours!

26

u/djm2491 Oct 10 '19

Dude send this to one of the famous DJs and have them throw it on screen at a rave. People would lose their minds

19

u/reinaldo866 Oct 10 '19

"Finally, I've mastered mathemathics and applied programming science, I've built the best galaxy simulation piece of software ever created, I'll give it to this DJ to play it on a Dubstep concert"

5

u/djm2491 Oct 10 '19

feed the wooks dark beats and dope visuals!

→ More replies (2)

2

u/GenericHumanNo7 Oct 10 '19

Google "Algorave"

→ More replies (1)

15

u/[deleted] Oct 10 '19

I love how your rosette explodes into the Eye of Sauron after it destabilizes. You've doomed us all.

2

u/frany_RL Oct 10 '19

Hey!! Thats really nice, can you pass the code?

2

u/LAMagicx Oct 11 '19

You can now find the source code at https://github.com/LAMagicx/OrbitalArt , I would love to see what you can come up with.

1

u/LAMagicx Oct 10 '19

I understand that many of you are asking for the source code which I plan to release to github however it would be my first public code post and I'm wondering if you have any tips for the commenting or 'tidying' up that I should do? (or do I just post it as it is and see what happens?) Could really use some guidelines for this sort of thing.

3

u/mriswithe Oct 10 '19

Honestly for this just putting it in a git repo with whatever you have is fine. We aren't after a perfectly documented production dependency. If you want to improve it from there you can make commits along the way and can always fall back to what you had

3

u/LAMagicx Oct 10 '19

Thanks I like the idea of making commits with changes

→ More replies (2)

1

u/LAMagicx Oct 11 '19

You can now find the source code at https://github.com/LAMagicx/OrbitalArt , I would love to see what you can come up with.

1

u/chinpokomon Oct 12 '19

Any tips for running it?

The source has Unicode, which Python 2 didn't like. I tried Python 3, but PyGame didn't like that. So I went back to Python 2 and renamed the Unicode symbols. Then it failed because it looks like it uses some other Python 3 version of PyGame.

Might as well just ask at this point.

1

u/LAMagicx Oct 12 '19

I running python 3.6 with pygame so can't tell you what you're doing wrong really.

→ More replies (1)

1

u/LAMagicx Oct 11 '19

Originally just a simple orbital system but here gravity becomes more powerful hence the decay.

1

u/LAMagicx Oct 11 '19

You can now find the source code at https://github.com/LAMagicx/OrbitalArt , I would love to see what you can come up with.

4

u/Subject_1889974 Oct 10 '19

You created a black hole

1

u/GlazCoin Oct 10 '19

Nice Could you share the code and how you made it, please.

2

u/LAMagicx Oct 11 '19

You can now find the source code at https://github.com/LAMagicx/OrbitalArt , I would love to see what you can come up with.

1

u/[deleted] Oct 10 '19

Can I get the source code?

1

u/LAMagicx Oct 11 '19

You can now find the source code at https://github.com/LAMagicx/OrbitalArt , I would love to see what you can come up with.

→ More replies (1)

1

u/Vegerot Oct 10 '19

Wanna post the source code?

1

u/LAMagicx Oct 11 '19

You can now find the source code at https://github.com/LAMagicx/OrbitalArt , I would love to see what you can come up with.

1

u/ishman123 Oct 10 '19

are you able to share code?

1

u/LAMagicx Oct 11 '19

You can now find the source code at https://github.com/LAMagicx/OrbitalArt , I would love to see what you can come up with.

1

u/meshikhah Oct 10 '19

source code pls

1

u/LAMagicx Oct 11 '19

You can now find the source code at https://github.com/LAMagicx/OrbitalArt , I would love to see what you can come up with.

1

u/kielerrr Oct 10 '19

Can you link the code? Would love to try running it!

1

u/LAMagicx Oct 11 '19

You can now find the source code at https://github.com/LAMagicx/OrbitalArt , I would love to see what you can come up with.

1

u/Acid_Monster Oct 10 '19

Can you share the code for this?

1

u/LAMagicx Oct 11 '19

You can now find the source code at https://github.com/LAMagicx/OrbitalArt , I would love to see what you can come up with.

1

u/vEnoM_420 Oct 10 '19

I'm new to python. Can you tell me what did you to produce this pattern? Not asking for the code but how did you manage to get those different colors? Just curious.

2

u/LAMagicx Oct 10 '19

the funny thing is, on my computer screen there is only 3 colours, red, green and blue. In the video it seems like they blend together to form a multicoloured pattern.

1

u/jamee42 Oct 10 '19

Would love to see the longer version.. assume it just goes on and on and .....

1

u/LAMagicx Oct 10 '19

Yeah but there is a variable that I can change and different patterns emerge.

1

u/martinLBarranco Oct 10 '19

Can you let us please see the code, that's quite beautiful and I'd like to see what I can do to expand and improve this.

2

u/LAMagicx Oct 11 '19

You can now find the source code at https://github.com/LAMagicx/OrbitalArt , I would love to see what you can come up with.

1

u/LAMagicx Oct 10 '19

I posted a comment about this somewhere on here

1

u/Gingevere Oct 10 '19

Why do the orbits decay? Are you simulating tidal friction?

1

u/LAMagicx Oct 11 '19

They are now decaying its just that gravity is becoming stronger and stronger so thier orbits are being pulled closer together

1

u/0xD3adB33f_ Oct 10 '19

Whoa that's super awesome! What libraries are working with on this project? I'm assuming perhaps matplotlib at the very least?

1

u/LAMagicx Oct 11 '19

Nope just good ol' pygame

1

u/TIBTHINK Oct 11 '19

Code?

It looks really cool

1

u/LAMagicx Oct 11 '19

You can now find the source code at https://github.com/LAMagicx/OrbitalArt , I would love to see what you can come up with.

1

u/bastawhiz Oct 11 '19

Are the sudden changes in velocities/directions of the particles due to the algorithm or does it happen because of the way floating point numbers work?

1

u/LAMagicx Oct 11 '19

More of how the algorithm works. Gravity becomes more and more powerful and when the particles touch they then explode outward.

1

u/[deleted] Oct 11 '19

Code pls which made this

1

u/LAMagicx Oct 11 '19

You can now find the source code at https://github.com/LAMagicx/OrbitalArt , I would love to see what you can come up with.

1

u/[deleted] Oct 11 '19

Amazing... How did begin to code this, could be a great learning opportunity for others if your willing to share.. My self I'm super interested.

2

u/LAMagicx Oct 11 '19

You can now find the source code at https://github.com/LAMagicx/OrbitalArt , I would love to see what you can come up with.

→ More replies (1)

1

u/LAMagicx Oct 11 '19

I am intending to just got to make it readable.

1

u/[deleted] Oct 11 '19

What did you use? Is it possible to simulate a solar system somehow?

1

u/LAMagicx Oct 11 '19

That was my initial intention but this turned out to be much better

→ More replies (2)

1

u/LopSidedm Oct 11 '19

What IDE are you using?

1

u/LAMagicx Oct 11 '19

I use sublime text 3.

1

u/magespawn Oct 11 '19

Share the code, if you please.

2

u/LAMagicx Oct 11 '19

I have now done so.

1

u/LAMagicx Oct 11 '19

You can now find the source code at https://github.com/LAMagicx/OrbitalArt , I would love to see what you can come up with.

1

u/hello-i-am-turtle Oct 16 '19

Beginner here would this be a good project to test how much you know?

2

u/LAMagicx Oct 16 '19

Yeah of course, a simple orbital system is a great challenge. For testing how much you know it is also pretty good because there are many different levels of "difficulty" you can have a single body with one or more satellites orbiting it and then add the attractions between the satellites and so on.. Any challenging project is good for a beginner.

1

u/[deleted] Oct 29 '19

Which libraries did you use?

1

u/LAMagicx Oct 29 '19

Just pygame.

→ More replies (1)

3

u/Madcat789 Oct 10 '19

That's one fancy art program.

3

u/VeganOrange Oct 10 '19

That’s fucking legit!! Chaos theory FTW

3

u/548benatti Oct 10 '19

I have seen God

3

u/14446368 Oct 10 '19

No idea why, but this reminded me of the whirring machinery of Atlantis, and the Nur-ab-Sal pendant/god from Indiana Jones and the Fate of Atlantis.

1

u/[deleted] Oct 10 '19 edited Oct 10 '19

Is it possible to solve schrodinger's equation with these?

2

u/LAMagicx Oct 10 '19

I don't know what Schroedinger equations are so I doubt it.

1

u/[deleted] Oct 10 '19

Wich library are you using ?

3

u/LAMagicx Oct 10 '19

Just pygame

2

u/[deleted] Oct 10 '19

That's awesome

2

u/TurboCancer4202 Oct 10 '19

People at r/sacredgeometry will dig this.

2

u/0da4dnc0nfu53d Oct 10 '19

This is so cool

2

u/jppianoguy Oct 10 '19

Congrats, you just made a Windows 3.1 screensaver

2

u/[deleted] Oct 10 '19

Did you just solve how the universe was created

2

u/Jonklopez Oct 10 '19

And this my friend is how you create new elements

2

u/Limp_Distribution Oct 10 '19

I keep thinking about electrons watching this clip.

2

u/the_dinks Oct 10 '19

Anyone reminded of fucking around with Snap! in middle school?

2

u/Guinness Oct 10 '19

The center is a black hole where you divided by zero.

This has summoned the great byte monster.

The great byte monster will eat all data in the universe.

Good job.

2

u/foresttrader Oct 10 '19

It went viral.

2

u/JohnClark13 Oct 10 '19

Brings back memories of turtle graphics on the c64

2

u/Gogani Oct 10 '19

Its not a bug, its a feature

2

u/dillmon Oct 10 '19

This is like the accidental discovery of penicillin!

2

u/paspro Oct 10 '19

Why is the simulation so slow? Oh, I see now. It's written in Python.

2

u/jkovach89 Oct 11 '19

Oh hey it's worki-- Oh no, oh God, oh fuck fuck fuck fuck...

2

u/[deleted] Oct 11 '19

Task failed sucessfuly.

2

u/Keanar Oct 11 '19

Scott Derrickson called, he wants to buy your code for the portal of the next Doctor Strange

2

u/[deleted] Oct 11 '19

Upload the python code, bro.

2

u/CapitanNexus Oct 22 '19

I dont know where you from or how they grade in america if u are from america but in uk you would get A** even tho there is no ** in grades

3

u/Im_oRAnGE Oct 10 '19

Please don't use v.redd.it. I can't watch this in anything other than 144p, even if I change the setting to 1080p it doesn't load in higher quality. And it still takes ages to load even in low quality.

1

u/oneanders Oct 10 '19

Love it!

1

u/[deleted] Oct 10 '19

Wow these shrooms are great

1

u/[deleted] Oct 10 '19

Mmm.. orbital donut. /homer

1

u/[deleted] Oct 10 '19

The summary of the Design Process for the Tray Arch Icon

1

u/thekalmanfilter Oct 10 '19

Juts make them go in circles.

1

u/YeastBeast33 Oct 10 '19

Can u share the code

1

u/[deleted] Oct 10 '19

damn thats trippy as hell!

1

u/Disposable_disaster Oct 10 '19

Python is a helluva drug

1

u/[deleted] Oct 10 '19

I mean I like it

1

u/Teslanaut Oct 10 '19

Is this for the remake of the Charmed TV show?

1

u/piotrulu Oct 10 '19

Soooo... You created black hole?

1

u/[deleted] Oct 10 '19

I think he just solved fusion

1

u/baWWR Oct 10 '19

Sauron!

1

u/wolfEXE57 Oct 10 '19

d-did you just create a new universe?

1

u/melanko Oct 10 '19

Do you want singularities? Because this is how you get singularities!

1

u/bongreaper666 Oct 10 '19

looked like a dope fillacello pendent there in the center for a second

1

u/Omaestre Oct 10 '19

Reminds me of the old windows media player or winamp

1

u/Schly Oct 10 '19

Error: Process failed successfully

1

u/MeltedWacks Oct 10 '19

And it's getting closer together

1

u/QLINQUENT Oct 10 '19

....tf I just transcended dimensions

1

u/[deleted] Oct 10 '19

Contact

1

u/cockroq Oct 10 '19

I’d say it was a success!

1

u/octavio2895 Oct 10 '19

The chaotic ending is probably due to a relatively large time-step when the bodies are moving fast. There are methods to implement variable size time-steps but I know nothing about those. Maybe you should time-step proportional to the speed of the bodies?

1

u/Hi_Im_A_Redditor Oct 10 '19

Half life three confirmed?

1

u/[deleted] Oct 10 '19

Our happy accident

1

u/[deleted] Oct 10 '19

How on earth did you go about creating this? It's a very cool misintention.

1

u/[deleted] Oct 10 '19

Ah yes Spirograph

1

u/ImagingNerd Oct 10 '19

He is the one...

1

u/just-a-reddit-user69 Oct 10 '19

I’m unsure what I just witnessed but it looked cool so I’m happy

1

u/[deleted] Oct 10 '19

The Bi Frost!

To battle Aesir! The Frost Giants will pay for their hubris!

1

u/[deleted] Oct 11 '19

1

u/[deleted] Oct 11 '19

You are a GOAT !!