const Wind := 0 %Affects motion of particles
const FireWorkRate := 150 %Less is more.
class Partical
import Wind
export Create, Manage
const xdecay := 1.01
const ydecay := 0.03
var P : flexible array 1 .. 0 of
record
x, y, xs, ys, r, g, b : real
end record
var theta, rad : real
procedure Create (x_, y_, xs_, ys_, r_, g_, b_ : real, amount : int)
for i : 1 .. amount
new P, upper (P) + 1
theta := Rand.Int (0, 360)
rad := Rand.Int (0, 200) / 100
P (i).x := x_
P (i).y := y_
P (i).xs := xs_ / 2 + cosd (theta) * rad
P (i).ys := ys_ / 2 + sind (theta) * rad
P (i).r := r_
P (i).g := g_
P (i).b := b_
end for
end Create
procedure ReduceColour (var C : real)
if C > 0 then
C -= Rand.Int (3, 10) / 10
else
C := 0
end if
end ReduceColour
procedure Manage
for i : 1 .. upper (P)
drawdot (round (P (i).x), round (P (i).y), RGB.AddColour (P (i).r / 255, P (i).g / 255, P (i).b / 255))
P (i).x += P (i).xs
P (i).y += P (i).ys
P (i).xs /= xdecay
P (i).ys -= ydecay
P (i).xs += Wind
if P (i).ys < -1 then
P (i).ys += ydecay * 2
end if
ReduceColour (P (i).r)
ReduceColour (P (i).g)
ReduceColour (P (i).b)
if P (i).y < 0 or P (i).r = 0 and P (i).g = 0 and P (i).b = 0 then
P (i) := P (upper (P))
new P, upper (P) - 1
exit
end if
end for
end Manage
end Partical
View.Set ('offscreenonly')
Text.ColourBack (black)
cls
var P : flexible array 1 .. 0 of ^Partical
%new
%new Partical, P
%Partical (P).Create (maxx div 2, maxy div 2, 0, 0, 250)
var FireWork : flexible array 1 .. 0 of
record
x, y, xs, ys, r, g, b : real
end record
var c : int := FireWorkRate - 1
loop
c += 1
if c mod FireWorkRate = 0 then
new FireWork, upper (FireWork) + 1
FireWork (upper (FireWork)).x := Rand.Int (0, maxx)
FireWork (upper (FireWork)).y := 0
FireWork (upper (FireWork)).xs := 0
FireWork (upper (FireWork)).ys := Rand.Int (20, 55) / 10
FireWork (upper (FireWork)).r := Rand.Int (0, 1) * 255
FireWork (upper (FireWork)).g := Rand.Int (0, 1) * 255
FireWork (upper (FireWork)).b := Rand.Int (0, 1) * 255
c := 0
end if
for i : 1 .. upper (FireWork)
FireWork (i).x += FireWork (i).xs
FireWork (i).y += FireWork (i).ys
FireWork (i).xs += Wind / 2
FireWork (i).ys -= 0.03
if FireWork (i).ys <= 0 or FireWork (i).y > 230 then
new P, upper (P) + 1
%put FireWork (i).x, FireWork (i).y, FireWork (i).xs, FireWork (i).ys
new Partical, P (upper (P))
Partical (P (upper (P))).Create (FireWork (i).x, FireWork (i).y, FireWork (i).xs, FireWork (i).ys, FireWork (i).r, FireWork (i).g, FireWork (i).b, 200)
FireWork (i) := FireWork (upper (FireWork))
new FireWork, upper (FireWork) - 1
exit
end if
drawfilloval (round (FireWork (i).x), round (FireWork (i).y), 3, 3, RGB.AddColour (FireWork (i).r / 255, FireWork (i).g / 255, FireWork (i).b / 255))
end for
for i : 1 .. upper (P)
Partical (P (i)).Manage
end for
View.Update
Time.DelaySinceLast (30)
cls
end loop
|