; PROJECT : Echo or Motion Effect
; AUTHOR : Kev Picone - http://PlayBasic.com
; CREATED : 14/11/2021
; EDITED : 14/11/2021
; ---------------------------------------------------------------------
// -------------------------------------------------------
// ---------------------- MAIN LOOP ----------------------
// -------------------------------------------------------
type tobject
X#(10)
Y#(10)
SpeedX#
SpeedY#
Colour
endtype
Dim Objects(35) as tobject
for lp=1 to getarrayelements(Objects())
Objects(lp)= new tobject
x#=rnd(800)
y#=rnd(600)
for poslp=0 to 10
Objects(lp).x#(poslp) = x#
Objects(lp).y#(poslp)= y#
next
Speed#=rndrange#(10,20)
Angle#=Rnd(360)
Objects(lp).speedx#=cos(Angle#)*Speed#
Objects(lp).speedy#=sin(Angle#)*Speed#
Objects(lp).Colour =rndrgb()
next
Screen=Newfximage(GetScreenWidth(),GetScreenheight())
// -------------------------------------------------------
do // -------------------- MAIN LOOP ---------------------
// -------------------------------------------------------
for lp=1 to getarrayelements(Objects())
x#=Objects(lp).x#(0)
y#=Objects(lp).y#(0)
x#+=Objects(lp).speedx#
y#+=Objects(lp).speedy#
// scroll old positions down
for oldpos=10 to 1 step -1
Objects(lp).x#(oldpos)=Objects(lp).x#(oldpos-1)
Objects(lp).y#(oldpos)=Objects(lp).y#(oldpos-1)
next
if x#<0 then x#=0 : Objects(lp).speedx#*= -1
if x#>800 then x#=800 : Objects(lp).speedx#*= -1
if y#<0 then y#=0 : Objects(lp).speedy#*= -1
if y#>600 then y#=600 : Objects(lp).speedy#*= -1
Objects(lp).x#(0)=x#
Objects(lp).y#(0)=y#
next
rendertoimage Screen
cls 0
// render
lockbuffer
; set ink pen drawing mode to Alpha Addition / Alpha ADD
inkmode 1+64
; step through the objects and the draw the oldest ones first
; looping to the last down to first.
for pass=10 to 0 step -1
blendlevel#=cliprange#(pass/10.0,0,1)
BlendColour =255-(255*BlendLevel#)
BlendColour=Rgb(BlendColour,BlendColour,BlendColour)
// Draw all the objects from this pass in one group
for lp=1 to getarrayelements(Objects())
x#=Objects(lp).x#(pass)
y#=Objects(lp).y#(pass)
// Compute the objects colour with the fade level
ThisRGB = rgbAlphamult (Objects(lp).Colour, BlendColour)
// draw it as a circle
circlec x#,y#,32,true,ThisRGB
next
next
unlockbuffer
; set inkmode back to normal
inkmode 1
rendertoscreen
drawimage screen,0,0,false
sync
wait 10
loop spacekey()