
-----------------------------------
iker
Sun Feb 12, 2006 8:54 pm

[source] - PARTICLE SPRAY by IKER
-----------------------------------
here is a little particle system that I put together, thought I might share the source with everyone here. Its actualy quite fun to watch, especialy when you screw around with the constants. The bursts dicipate after a while, and the particles spray at a constant rate, which is better. Anyways, have fun and edit at will :)

setscreen ("graphics:max;max,offscreenonly,nobuttonbar")
% Particle Spray by : Chris "Iker" Iaconis
% A basic Particle Spray,
% particles spawn at mouse coordinates
% have different speeds, directions
% may take a few seconds to not come out in "bursts"

% consts are editable for speed purposes
const aOP := 512 % amount of particles
const dT := 0 % delay time (1/1000 seconds)
const pS := 6 % particle size
const pG := 3 % particle gravity
const pF := .2 % particle fade
const pD := 6 %particle distance

type particles :
    record
        PX : array 0 .. aOP of int
        PY : array 0 .. aOP of int
        PD : array 0 .. aOP of int
        PC : array 0 .. aOP of real
        PS : array 0 .. aOP of int
    end record
var aO : particles
var r, g, b : real
var count, countDelay, mouseX, mouseY, mouseButton : int := 0
for i : 0 .. aOP
    aO.PX (i) := 0
    aO.PY (i) := 0
    aO.PC (i) := 0
end for

proc spawnParticle (pN : int)
    Mouse.Where (mouseX, mouseY, mouseButton)
    aO.PX (pN) := mouseX
    aO.PY (pN) := mouseY
    randint (aO.PD (pN), 1, 359)
    randint (aO.PS (pN), 0, pD)
    aO.PC (pN) := 31
end spawnParticle

proc particleGravity (pN : int)
    if aO.PD (pN) > 0 and aO.PD (pN) < 180 then
        aO.PD (pN) += pG
    elsif aO.PD (pN) < 360 and aO.PD (pN) > 180 then
        aO.PD (pN) -= pG
    end if
end particleGravity

proc particleFade (pN : int)
    aO.PC (pN) -= pF
end particleFade

proc particleShow (pN : int)
    drawfilloval (aO.PX (pN), aO.PY (pN), pS, pS, round (aO.PC (pN)))
end particleShow

proc particleMove (pN : int)
    aO.PX (pN) += round (sind (aO.PD (pN)) * aO.PS (pN))
    aO.PY (pN) += round (cosd (aO.PD (pN)) * 5)
end particleMove

proc particleJudge (pN : int)
    if aO.PD (pN) = 0 then
        spawnParticle (pN)
    end if
    if aO.PC (pN) = .05 then
                aO.PR (Num) -= pFS (Num)
            end if
            if aO.PG (Num) >= .05 then
                aO.PG (Num) -= pFS (Num)
            end if
            if aO.PB (Num) >= .05 then
                aO.PB (Num) -= pFS (Num)
            end if
            if aO.PR (Num) 