Hacker News new | past | comments | ask | show | jobs | submit login
Gravity: An orbital simulation game written in Elm (github.com/stephenbalaban)
62 points by of on Nov 15, 2014 | hide | past | favorite | 22 comments



I have a soft spot for gravity simulators, my first BASIC program that wasn't a variation on INPUT "Your Age";A :PRINT "You are ", A*52, " weeks old." was a gravity simulator with a rocket in orbit and your capsule needed to dock with it by apply forward or reverse thrust (2D only!) What made mine a bit different was that you launched from the planet so you had to take into account where the other rocket was before launching or you wouldn't have enough fuel to dock.

What this example in Elm and all reasonably implemented simulators provoke is a sense of awe in just how hard it is to "drive" in orbit.


I always enjoy playing with these kinds of simulations, but this one seems to be pretty bad at respecting conservation of energy. The closer you are to the sun, the more rapidly your spacecraft mysteriously gains energy from nowhere, causing it to spiral outward instead of maintaining a stable orbit. I'm not sure yet whether it's a consequence of using naive Euler integration or some other bug.


I too wasted lots of time playing with these simulations. The feyman lecture on physics have a great chapter on this stuff. The orbit does tend to pick up energy due to errors coming from euler's method. A relatively simple way to make your orbits a bit more stable is to normalize your velocity vectors using conservation of energy.


I'd say the newly gained acceleration is due to [1] the force of attraction suddenly disappearing.

[1] https://github.com/stephenbalaban/Gravity/blob/master/Gravit...


Because of the nature of FRP, you can't do much except for Euler integration.


How about http://en.wikipedia.org/wiki/Symplectic_Euler_method ?

That's what I used in http://wry.me/t/gravity/gravity.html (Which is not in Elm; it simulates a solar sail instead of a rocket.)


Why not, precisely?


I wasn't familiar with Elm prior to seeing this submission. To save others a few minutes of web searching, it appears at first glance to be a marriage of Haskell and Dart... a functional programming language that transpiles into JavaScript. It's primary use cases seem to include browser-based games, and reactive widgets.

http://elm-lang.org/


Nothing to do with Dart. It's a Haskell + FRP signals, that compiles to JS.


He means it's like Dart in the sense that it compiles to JS.


Some time ago I played a bit with elm and made this: http://share-elm.com/sprout/5467ef7de4b00800031feadf, not a simulation of course but the effect it's nice. It's cool to see an actual simulation, now. Well done.


The way the lines of force are illustrated (even the colors used) is very reminiscent of New Orbit, which is still one of the most innovative games I have seen for Android.

http://blackish-games.com/neworbit/


Similar to some of the worlds in the hit game Osmos: http://www.osmos-game.com/


I came here to say that. The orbital levels in Osmos are excellent.


Cool, for some reason unplayable in FF, fine Chrome.


Yeah, I was really big into elm until I started noticing how slow many of my programs were on Firefox. Everything runs great in Chrome however.


I've been keeping an eye on Elm for a while; it's a very intriguing idea, but I've yet to see much other than little demos like this done with it. This seems to be the chronic case of gaming in the FP and Lisp worlds. Lots of little demos and experiments, very few mature projects.




When making gravity simulations you need to "cheat" a little to make the planets and the stars keep a stable orbit. It makes one amaze over how stable our own star system is.


Much of that is due to issues of numerical approximation, which isn't an issue for our actual planets.

Though, unlike newtonian planets, our planets can precess slightly due to general relativity thingies.


Do the simulations include the asteroid belts? Wouldn't those have a stabilising effect on the rest of the bodies in the system?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: