@Henrik
I knocked together a very simple example of 2d particles. Basically, there are 2 functions that will control the position of the emitter.
If you click on the left button and move the mouse around, the emitter's position will follow the mouse and the particles will only reset their position after their life has ended. This gives the effect of waving a sparkler in the air.
If you click the RIGHT mouse button and move the mouse around, the emitter will move and all of the particles' positions will change based on that positional offset. I think this would be the effect you are describing.
REMSTART
==============================================================
= TITLE : small particle engine
= Author : latch
= Date : 11/29/2013
= UPDATE :
= Version:
==============================================================
Comments
==============================================================
REMEND
REM =============================================================
REM = SET UP DISPLAY
REM =============================================================
AUTOCAM OFF
SET DISPLAY MODE 800,600,32
SYNC ON
SYNC RATE 60
REM =============================================================
REM = MAIN
REM =============================================================
_main:
gosub _init
DO
cls
gosub _draw_particles
move_emitter()
offset_with_emitter(maxpart)
SYNC
LOOP
END
REM =============================================================
REM = SUBROUTINES - PROCEDURES
REM ============================================================
_init:
rem create arrays to hold particle information
maxpart=100
dim partlife(maxpart,1) : rem how many iterations is the particle moving?
dim partvelocity#(maxpart,1) : rem how fast in x and y does it move
dim partposition#(maxpart,1) : rem current particle position
dim emitterpos(1) : rem the x and y position of the emitter
rem initialize the particle "engine"
rem put the emitter in the center of the screen
emitterpos(0)=screen width()/2
emitterpos(1)=screen height()/2
rem set a series of random life cycles
for n=1 to maxpart
rem max life will be a number of iterations
partlife(n,0)=rnd(60)
rem set random x y speed the particle will move each frame
rem up to 5
partvelocity#(n,0)=((rnd(1000)-500)/100.0)
partvelocity#(n,1)=((rnd(1000)-500)/100.0)
`partvelocity#(n,1)=(rnd(500)/100.0)
rem set the starting point of all particles at the emitter's position
partposition#(n,0)=emitterpos(0)
partposition#(n,1)=emitterpos(1)
next n
ink rgb(255,255,0),0
return
`================================================================
_draw_particles:
rem loop through the particles and update their position
for p=1 to maxpart
rem draw the current particle
box partposition#(p,0),partposition#(p,1),partposition#(p,0)+1,partposition#(p,1)+1
rem update it's position. If it's past it's life cycle, then set it to emitter
partlife(p,1)=partlife(p,1)+1
if partlife(p,1)>partlife(p,0)
partposition#(p,0)=emitterpos(0)
partposition#(p,1)=emitterpos(1)
rem reset particle life and velocity
partlife(p,1)=0
partvelocity#(p,0)=((rnd(1000)-500)/100.0)
partvelocity#(p,1)=((rnd(1000)-500)/100.0)
`partvelocity#(p,1)=(rnd(500)/-100.0)
else
partposition#(p,0)=partposition#(p,0)+partvelocity#(p,0)
partposition#(p,1)=partposition#(p,1)+partvelocity#(p,1)
endif
next p
return
REM =============================================================
REM = FUNCTIONS
REM =============================================================
function move_emitter()
rem reposition the wherever you left click
if mouseclick()=1
emitterpos(0)=mousex()
emitterpos(1)=mousey()
endif
endfunction
function offset_with_emitter(maxpart)
rem position emitter and offset the paticles with right click
if mouseclick()=2
oldx=emitterpos(0)
oldy=emitterpos(1)
emitterpos(0)=mousex()
emitterpos(1)=mousey()
for p=1 to maxpart
xoffset#=partposition#(p,0)-oldx
yoffset#=partposition#(p,1)-oldy
partposition#(p,0)=emitterpos(0)+xoffset#
partposition#(p,1)=emitterpos(1)+yoffset#
next p
endif
endfunction
REM =============================================================
REM = DATA STATEMENTS
REM =============================================================
Enjoy your day.