Challenge: 
Version: 
5
Winner?: 
No
Code Snippet: 
sync on : sync rate 0
hide mouse

`Constants
#constant nr = 10
#constant Trails = 30
#constant St = 5
#constant col = rgb(0, 128, 255)

`Arrays
type pos
    x as integer
    y as integer
endtype
dim T(nr, Trails) as pos
dim S(nr) as integer

dim P(nr) as pos

global angle# as float : angle# = 0.0
global radius# as float : radius# = 200.0
global speed# as float : speed# = 1.0

do

    cls

    `Update first trail point
    angle# = wrapvalue(angle# + speed#)
    
    `Calculate position
    for p = 1 to nr

        `Calculate positions
        P(p).x = mousex() + (cos(angle# + (360.0 / nr * p)) * radius#)
        P(p).y = mousey() + (sin(angle# + (360.0 / nr * p)) * radius#)

        `Update trail positions
        T(p, 1).x = curvevalue(P(p).x, T(p, 1).x, 10.0)
        T(p, 1).y = curvevalue(P(p).y, T(p, 1).y, 10.0)

    next p

    `update trails
    for a = 1 to nr
        UpdateTrails(a)
    next a

    sync
loop

function UpdateTrails(a)

    `If the trail has to update itself
    if timer() - S(a) > St
    
        `Reset timer
        S(a) = timer()

        `Update all trails
        for t = Trails to 2 step -1
        
            `Copy the x and y coordinates of its parent trail point
            T(a, t).x = T(a, t - 1).x
            T(a, t).y = T(a, t - 1).y
            
        next t
    endif

    `Draw all trail parts
    for t = 2 to Trails
    
        `Calculate appropriate color for the fading effect
        f# = 0.1 * Trails * 10.0 / (Trails - t)
        tcol = rgb( rgbr(col) / f#, rgbg(col) / f#, rgbb(col) / f#)
        ink tcol, 0
        
        `Connect it with its parent
        line T(a, t).x, T(a, t).y, T(a, t - 1).x, T(a, t - 1).y
    next t

endfunction