
-----------------------------------
Homer_simpson
Tue Dec 02, 2008 2:14 pm

collision particles
-----------------------------------
i was messing around with the numbers on one of my old physics program and accidentally got a neat effect. particles stick together until they are broken again when they collide with eachother 
View.Set ("offscreenonly,graphics:700;350")

function distance (x1, y1, x2, y2 : real) : real
    result sqrt (((x2 - x1) ** 2) + ((y2 - y1) ** 2)) %y

end distance
function findangle (x1, y1, x2, y2 : real) : real
    var ang, slope : real
    if not (x2 = x1) then
        slope := (y2 - y1) / (x2 - x1)
    else
        slope := 999999999
    end if
    ang := arctand (slope)
    if slope > 0 then
        if y2 < y1 then
            ang := 180 + ang
        end if
    end if
    if slope < 0 then
        if x2 < x1 then
            ang := 180 + ang
        end if
        if x2 > x1 then
            ang := 360 + ang
        end if
    end if
    if slope = 0 then
        if x2 > x1 then
            ang := 0
        end if
        if x2 < x1 then
            ang := 180
        end if
    end if
    result ang
end findangle
type Particle_Type :
    record
        x, y, vx, vy, w : real
    end record

const MaxParticles := 50

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, 700), Rand.Int (0, 350), 0, 0, Rand.Int (10, 100))
end for
colorback (black)
cls

RenewParticle (Particles (1), 20, 150, 4, 2, Rand.Int (10, 100))
RenewParticle (Particles (2), 500, 150, -4, 2, Rand.Int (10, 100))
var chars : array char of boolean

color (white)
var col := false
var temp1, temp2, temp3, magnitude : real
loop
    Input.KeyDown (chars)
    if chars ('+') then
    end if

    for i : 1 .. MaxParticles
        if not col then

            Particles (i).x += Particles (i).vx
            Particles (i).y += Particles (i).vy
        end if
        drawfilloval (round (Particles (i).x), round (Particles (i).y), 10, 10, gray)

        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%ball collision%%%%%%%%%%%%%%%%%%%%%%%%
        for ii : 1 .. MaxParticles
            if distance (Particles (i).x, Particles (i).y, Particles (ii).x, Particles (ii).y) = 690 and Particles (i).vx > 0 then
            Particles (i).vx := -Particles (i).vx
        end if
        if Particles (i).x = 340 and Particles (i).vy > 0 then
            Particles (i).vy := -Particles (i).vy
        end if
        if Particles (i).y 