Report as inappropriate.

No_avatar_thumb

Krendil presents ...

2008/10/18

Gravitation

A framework that simulates gravity in space. Everything with gravity should be a subclass of Matter.
To make something affected by gravity, add gravitate() in its act method.
In this example, the sun has a mass of 300 and the planets of 0.5.

Update 20/10/08: Adjusted the orbits of planets, caused the sun to be affected by gravity, and fixed a bug in the getBearing function

2327 views / 6 in the last 7 days

4 votes | 0 in the last 7 days

Tags: space simulation physics with-source orbit

This scenario is a member of: Space Simulations


open in greenfoot
Your browser is ignoring the <APPLET> tag.
No_avatarFinn Kerr

2008/10/18

HAHA This is SWEET! I love it ^^ It just gets a bit buggy when the planets get too close to each other and around the edges
No_avatarkenshinakh

2008/10/18

Wow, very nice, nice concept! But yeah, it does act a little funny when you let it run for a while (I would hate to live in that solar system XD, because the planets go near the sun, and then springs out of orbit after a while), but other than that, nice simulation of gravity.
Canada-face-only-smallmik

2008/10/19

The problem with the funny display around the edges is a Greenfoot restriction: You cannot place actors outside of the world area. (Maybe we should allow that?) And if you remove them from the world while they are out of view, they wouldn't get their act method called. There are two possible solutions to this: either you (temporarily) remove them from the world and enter them in an 'off-screen-actor' list of your own, where you call the objects' act method yourself (from the World act method); or you leave them in the world, but give them (temporarily) an empty image.
No_avatarKrendil

2008/10/19

This particular scenario is just an example, and wasn't meant to have particularly stable orbits. In the game I'm making with it, I made everything bounce off the edges of the screen. If I were to allow things to go off the edge, I would probably use your second solution.
A new version of this scenario was uploaded on Mon Oct 20 09:36:53 UTC 2008
No_avatarMikeW

2010/12/2

I thought of doing something similar as a learning exercise for me trying to figure out how to get objects to read varaibles from each other this will help alot - Thanks for shairing it

Want to leave a comment? You must first log in.

Who likes this?

Aaaargh_thumb No_avatar_thumb No_avatar_thumb