Solar system phyisics
Author |
Message |
Homer_simpson
|
Posted: Tue Dec 02, 2008 12:42 am Post subject: Solar system phyisics |
|
|
random objects appear in space with random velocities as the older ones lose orbit..
Quote: View.Set ("offscreenonly,graphics:1000;800")
const gconst := .005
function distance (x1, y1, x2, y2 : real) : real
result sqrt (((x2 - x1) ** 2) + ((y2 - y1) ** 2)) %y
end distance
type Particle_Type :
record
x, y, vx, vy, w : real
end record
const MaxParticles := 30
var Particles : array 1 .. MaxParticles of Particle_Type
procedure RenewParticle (var p : Particle_Type, x, y : int, a, r, w : real)
p.x := x
p.y := y
p.vx := a
p.vy := r
p.w := w
end RenewParticle
for i : 1 .. MaxParticles
RenewParticle (Particles (i), Rand.Int (1, 1000), Rand.Int (0, 1000), Rand.Int (0, 8) - 4, Rand.Int (0, 8) - 4, Rand.Int (10, 100))
end for
colorback (black)
cls
var chars : array char of boolean
var gx, gy := 400
var forceg : real
color (white)
loop
Input.KeyDown (chars)
if chars ('+') then
end if
% put Math.Distance (gx, gy, Particles (1).x, Particles (1).y)
% put distance (gx, gy, Particles (1).x, Particles (1).y, false)
for i : 1 .. MaxParticles
if gx > Particles (i).x then
Particles (i).vx += ((gconst) * (Particles (i).w * 10000) / (distance (gx, gy, Particles (i).x, Particles (i).y)) ** 2) / 1
else
Particles (i).vx -= ((gconst) * (Particles (i).w * 10000) / (distance (gx, gy, Particles (i).x, Particles (i).y)) ** 2) / 1
end if
if gy > Particles (i).y then
Particles (i).vy += ((gconst) * (Particles (i).w * 10000) / (distance (gx, gy, Particles (i).x, Particles (i).y)) ** 2) / 1
else
Particles (i).vy -= ((gconst) * (Particles (i).w * 10000) / (distance (gx, gy, Particles (i).x, Particles (i).y)) ** 2) / 1
end if
if distance (gx, gy, Particles (i).x, Particles (i).y) > 1000 then
RenewParticle (Particles (i), Rand.Int (1, 1000), Rand.Int (0, 1000), Rand.Int (0, 8) - 4, Rand.Int (0, 8) - 4, Rand.Int (10, 100))
end if
%put Particles (i).vx
%put Particles (i).vy
drawfilloval (round (Particles (i).x), round (Particles (i).y), 2, 2, black)
drawdot (round (Particles (i).x), round (Particles (i).y), 15+round (Particles (i).w)mod 40)
Particles (i).x += Particles (i).vx
Particles (i).y += Particles (i).vy
drawfilloval (round (Particles (i).x), round (Particles (i).y), 2, 2, white)
%drawdot (round (Particles (i).x), round (Particles (i).y), white)
%drawfillstar (round (Particles (i).x) - 5, round (Particles (i).y) - 5, round (Particles (i).x) + 5, round (Particles (i).y) + 5, white)
%drawline (round (Particles (i).x), round (Particles (i).y), round (Particles (i).x) + round (Particles (i).v -> x) * 5, round (Particles (i).y) + round (Particles (i).v -> y) * 5, white)
%drawfillbox (round (Particles (i).x), round (Particles (i).y), round (Particles (i).x) + round (Particles (i).v -> x) * 5, round (Particles (i).y) + round (Particles (i).v -> y) * 5, white)
%drawfilloval (round (Particles (i).x), round (Particles (i).y), round (Particles (i).v -> x) * 3, round (Particles (i).v -> y) * 3, white)
%drawfilloval (round (Particles (i).x), round (Particles (i).y), 1, 1, white)
end for
drawfilloval (gx, gy, 10, 10, 14)
View.Update
%cls
end loop
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
Nick
|
Posted: Tue Dec 02, 2008 7:20 am Post subject: RE:Solar system phyisics |
|
|
bad:
1) the code's messy
2) there seems to be a slight glitch when the objects collide with the planet (they pick up too much momentum and zoom across the screen)
good:
1) I like the physics
improvements:
1) fix the glitch
2) add collision with the objects |
|
|
|
|
|
SNIPERDUDE
|
Posted: Tue Dec 02, 2008 8:16 am Post subject: RE:Solar system phyisics |
|
|
I think Nick just about covered it. |
|
|
|
|
|
Parker
|
Posted: Tue Dec 02, 2008 8:29 am Post subject: RE:Solar system phyisics |
|
|
I think you did quite a good job. I wish I knew the mathmatics to make a program like that
I did notice how they fly across the screen but was unsure if that was supposed to happen or not lol |
|
|
|
|
|
[Gandalf]
|
Posted: Tue Dec 02, 2008 8:40 am Post subject: Re: RE:Solar system phyisics |
|
|
Nick @ 2008-12-02, 7:20 am wrote: 2) there seems to be a slight glitch when the objects collide with the planet (they pick up too much momentum and zoom across the screen)
No, that's how the physics are supposed to work, it's just an extreme case of the normal orbit motion. Well, unless the particle crashes into the object.
If you want to learn about the physics behind this, this Wikipedia article should have everything relevant. |
|
|
|
|
|
Homer_simpson
|
Posted: Tue Dec 02, 2008 11:17 am Post subject: Re: Solar system phyisics |
|
|
objects pick up momentum as they get close to the large mass because the closer the distance between the two objects the greater the gravitational force become between the objects and therefore greater acceleration...
added collision to the star to the code:
Quote: View.Set ("offscreenonly,graphics:1000;800")
const gconst := .005
function distance (x1, y1, x2, y2 : real) : real
result sqrt (((x2 - x1) ** 2) + ((y2 - y1) ** 2)) %y
end distance
type Particle_Type :
record
x, y, vx, vy, w : real
end record
const MaxParticles := 30
var Particles : array 1 .. MaxParticles of Particle_Type
procedure RenewParticle (var p : Particle_Type, x, y : int, a, r, w : real)
p.x := x
p.y := y
p.vx := a
p.vy := r
p.w := w
end RenewParticle
for i : 1 .. MaxParticles
RenewParticle (Particles (i), Rand.Int (1, 1000), Rand.Int (0, 1000), Rand.Int (0, 8) - 4, Rand.Int (0, 8) - 4, Rand.Int (10, 100))
end for
colorback (black)
cls
var chars : array char of boolean
var gx, gy := 400
var forceg : real
color (white)
loop
for i : 1 .. MaxParticles
if gx > Particles (i).x then
Particles (i).vx += ((gconst) * (Particles (i).w * 10000) / (distance (gx, gy, Particles (i).x, Particles (i).y)) ** 2) / 1
else
Particles (i).vx -= ((gconst) * (Particles (i).w * 10000) / (distance (gx, gy, Particles (i).x, Particles (i).y)) ** 2) / 1
end if
if gy > Particles (i).y then
Particles (i).vy += ((gconst) * (Particles (i).w * 10000) / (distance (gx, gy, Particles (i).x, Particles (i).y)) ** 2) / 1
else
Particles (i).vy -= ((gconst) * (Particles (i).w * 10000) / (distance (gx, gy, Particles (i).x, Particles (i).y)) ** 2) / 1
end if
if distance (gx, gy, Particles (i).x, Particles (i).y) > 1000 then
RenewParticle (Particles (i), Rand.Int (1, 1000), Rand.Int (0, 1000), Rand.Int (0, 8) - 4, Rand.Int (0, 8) - 4, Rand.Int (10, 100))
end if
if distance (gx, gy, Particles (i).x, Particles (i).y) <= 12 then
drawfilloval (round (Particles (i).x), round (Particles (i).y), 5, 5, red)
RenewParticle (Particles (i), Rand.Int (1, 1000), Rand.Int (0, 1000), Rand.Int (0, 8) - 4, Rand.Int (0, 8) - 4, Rand.Int (10, 100))
end if
drawfilloval (round (Particles (i).x), round (Particles (i).y), 2, 2, black)
drawdot (round (Particles (i).x), round (Particles (i).y), 15 + round (Particles (i).w) mod 40)
Particles (i).x += Particles (i).vx
Particles (i).y += Particles (i).vy
drawfilloval (round (Particles (i).x), round (Particles (i).y), 2, 2, white)
end for
drawfilloval (gx, gy, 10, 10, 14)
View.Update
%cls
end loop
|
|
|
|
|
|
kishan25
|
Posted: Tue Jan 13, 2009 7:27 pm Post subject: RE:Solar system phyisics |
|
|
nice program, just needs some modification |
|
|
|
|
|
syntax_error
|
Posted: Tue Jan 13, 2009 7:31 pm Post subject: Re: RE:Solar system phyisics |
|
|
kishan25 @ Tue Jan 13, 2009 7:27 pm wrote: nice program, just needs some modification
necroposting bad. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
saltpro15
|
Posted: Fri Jan 16, 2009 4:24 pm Post subject: RE:Solar system phyisics |
|
|
actually necroposting is quite helpful in this case, this program just gave me a great idea |
|
|
|
|
|
[Gandalf]
|
Posted: Fri Jan 16, 2009 6:09 pm Post subject: RE:Solar system phyisics |
|
|
Yes necroposting is bad, but in this case the topic wasn't even that old, and spamming is worse than necroposting. Keep that in mind for the future.
I don't want to move this topic down, so I'm not locking it but consider it locked for posting purposes! |
|
|
|
|
|
|
|