сек
unit uCloud;
interface
type
tCloudParticle = record
x: real;
y: real;
size: real;
end;
tCloudGen = object
private
centerX, centerY: real;
ms: real;
mr: real;
particles: array of tCloudParticle;
procedure reborn(n: integer);
public
procedure init(x, y: real; n: integer; radius: real; max_size: real);
function getParticle(n: integer): tCloudParticle;
procedure reset(n: integer);
procedure moveTo(x, y: real);
procedure tick(quant: real);
function count: integer;
end;
const
pix2 = pi * 2;
third = 1 / 5;
implementation
function tCloudGen.count: integer;
begin
result := high(particles) + 1;
end;
function tCloudGen.getParticle(n: integer): tCloudParticle;
begin
result.x := 0;
result.y := 0;
result.size := 0;
if n > high(particles) then exit;
result := particles[n];
end;
procedure tCloudGen.init(x, y: real; n: integer; radius: real; max_size: real);
var
i: integer;
begin
moveTo(x, y);
reset(n);
ms := max_size;
mr := radius;
for i := 0 to n do
tick(1);
end;
procedure tCloudGen.moveTo(x, y: real);
begin
centerX := x;
centerY := y;
end;
procedure tCloudGen.reborn(n: integer);
var
a, r: real;
begin
a := random * pix2;
r := random * mr;
particles[n].x := centerX + cos(a) * r;
particles[n].y := centerY + sin(a) * r;
particles[n].size := (random * 0.5 + 0.5) * ms;
end;
procedure tCloudGen.reset(n: integer);
var
i: integer;
begin
setLength(particles, n);
n := high(particles);
for i := 0 to n do begin
reborn(i);
particles[i].size := sqr(random) * ms;
end
end;
procedure tCloudGen.tick(quant: real);
var
i, n: integer;
begin
n := high(particles);
for i := 0 to n do begin
particles[i].size := particles[i].size * (1 - third * quant);
if particles[i].size < 1
then reborn(i);
end;
end;
end.
облако частиц
заставишь двигаться - будет смачный фаербол
каждую частицу рисуешь спрайтом в режиме Add