Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / Gravitational Balls

Author
Message
CornStalks
20
Years of Service
User Offline
Joined: 12th Feb 2004
Location: Utah
Posted: 22nd Jun 2005 03:36 Edited at: 22nd Jun 2005 03:40
This is a little simple program I made. All the balls (there are 100 of them) are gravitationaly attracted to eachother. When they collide, they merge, and their mass increases, causing them to have more gravity. No, their distance does not affect their gravity, however I did include the code just incase you want to. The reason for this is because when you use it, the fps goes way way way down.



Hope you enjoy it!

You are welcome to use any of it in your programs, just please give me credit.
ALPHA ZERO PRODUCTIONS
21
Years of Service
User Offline
Joined: 28th Sep 2003
Location: Mom ! I forgot where we live !
Posted: 22nd Jun 2005 15:11 Edited at: 22nd Jun 2005 15:12
nice balls

BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 22nd Jun 2005 18:31 Edited at: 22nd Jun 2005 18:46
Nice little demo!

I have tried to optimise it slightly for you. The code below has the number of spheres put into a variable (called spheres) so that you can change the number in one place and recompile to see the effect. My optimistaions are marked up as SV01, and are simple reductions of the number of loops.

I don't understand exactly how you get the effect, my brain can't work that one out! So I don't know if my changes made a significant difference. I did find that I had to change the global attraction, because the compound effect of the multiple calculations was removed.

Again, nice work!



BatVink
CornStalks
20
Years of Service
User Offline
Joined: 12th Feb 2004
Location: Utah
Posted: 23rd Jun 2005 01:02 Edited at: 23rd Jun 2005 01:07
I have no clue what you just did with that code...I tried running it and all I saw was a black screen with the fps in the top left corner. But how the spheres are attracted to eachother is it gets their x speed, and adds the difference of their x position, and multiplies it by 1400-their x distnace. Then it divides that by the attraction amount, then multiplies by the other objects mass. Well thats what this updated code does. Its hard to understand if you don't know what the Universal Law of Gravity is, or how it works.


(universal gravitation constant =(6.6742 ± 0.0010) × 10^−11 N m^2 kg^-2)

Well, here is the new code. It's a little slower, but their distances now have a little bit of an affect.

ALPHA ZERO PRODUCTIONS
21
Years of Service
User Offline
Joined: 28th Sep 2003
Location: Mom ! I forgot where we live !
Posted: 23rd Jun 2005 04:35
my head hurts

dj blackdragon3710
20
Years of Service
User Offline
Joined: 5th Nov 2004
Location: In LaLa land
Posted: 23rd Jun 2005 09:12
mine doesn't actually, which is amazing....

<<<<<Used to be "djblackdragon" with being registered in January, 2003, no matter what it says on the left<<<<<
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 25th Jun 2005 05:40
My code works for me

BatVink
TEH_CODERER
21
Years of Service
User Offline
Joined: 12th Nov 2003
Location: Right behind you!
Posted: 27th Jun 2005 00:03
Works for me too. Pretty cool.

[url]andrewneale2004@yahoo.com[/url]
http://www.elbsoftware.dbspot.com
CornStalks
20
Years of Service
User Offline
Joined: 12th Feb 2004
Location: Utah
Posted: 27th Jun 2005 01:24
I'm glad it works.
mm0zct
21
Years of Service
User Offline
Joined: 18th Nov 2003
Location: scotland-uk
Posted: 27th Jun 2005 11:39 Edited at: 27th Jun 2005 11:39
since it looks such a good screen saver i'll convert it into a more accurate version in c++ which will run faster and i'll do it in 2d to increase speed more.
nice work and thanks for the idea

http://www.larinar.tk
AMD athlon 64 3000+, 512mb ddr400, abit kv8, 160gb hdd, gigabit lan, ati radeon 9800se 128mb.
CornStalks
20
Years of Service
User Offline
Joined: 12th Feb 2004
Location: Utah
Posted: 27th Jun 2005 12:34
Haha, thats funny, since I got my idea from a 2D version written in c++. I used to be learning c++, but I don't have a few hundred dollars just to spend on the compiler, or the patience to load an object.
mm0zct
21
Years of Service
User Offline
Joined: 18th Nov 2003
Location: scotland-uk
Posted: 28th Jun 2005 02:09 Edited at: 28th Jun 2005 06:50
devc++ is free with the gnu compiler and it can be easier to write your own model format, that's what i did and then wrote a converter for (almost) .x to my format (the .x file required some tweaking)

attached c++ version, the colour indicates the energy of the particle, the version attached has 1000 particles as default but go to file>num bits to set the numer of particles. the size of the dot corresponds to the percentage of the total mass in it's universe it contains.

http://www.larinar.tk
AMD athlon 64 3000+, 512mb ddr400, abit kv8, 160gb hdd, gigabit lan, ati radeon 9800se 128mb.

Attachments

Login to view attachments
mm0zct
21
Years of Service
User Offline
Joined: 18th Nov 2003
Location: scotland-uk
Posted: 28th Jun 2005 07:45 Edited at: 28th Jun 2005 07:57
i removed the colour buffer clear so it looks quite good now
(everything leavs a permanant trail, it clears when you change the number of particles but not when you first load so i recommend you set the number of particles at the start rather than just accept what's there)

fixed exes for up to 10000 particles, first has no trails, second does
[href]www.lochviewwest.plus.com/dbforum/gravity_sim.exe[/href]
[href]www.lochviewwest.plus.com/dbforum/gravity_draw.exe[/href]

http://www.larinar.tk
AMD athlon 64 3000+, 512mb ddr400, abit kv8, 160gb hdd, gigabit lan, ati radeon 9800se 128mb.

Attachments

Login to view attachments

Login to post a reply

Server time is: 2024-11-23 10:42:00
Your offset time is: 2024-11-23 10:42:00