Light trail

I made this code just to try and learn making joints but it’s pretty mesmerizing to watch. If I wanted to add a light trail to each ball how could I do that to make it look even nicer?

i came across this demo project previously, it should have what you’re looking for

@Dezmo Here’s your code, modified, with a trail for each ball. Tap or swipe the screen to clear the current trails and start new ones. If this isn’t exactly what you want, maybe it will give you an idea. What you’re after is the viewer.retainedBacking=true statement instead of background(0) to leave trails. I also reduced the speed variable.

viewer.mode=FULLSCREEN

function setup()
    size=20
    physics.gravity(vec2(0,-10))    
    one=physics.body(CIRCLE,size)
    one.x,one.y=WIDTH/2,HEIGHT/2
    one.type=DYNAMIC
    one.restitution=2
    one.friction=0    
    two=physics.body(CIRCLE,size)
    two.x,two.y=WIDTH/2,HEIGHT/2
    two.type=DYNAMIC
    two.restitution=2
    two2=physics.body(CIRCLE,size)
    two2.x,two.y=WIDTH/2,HEIGHT/2
    two2.type=DYNAMIC
    two2.restitution=2
    wall={  w1=physics.body(EDGE,vec2(0,0),vec2(WIDTH,0)),
            w2=physics.body(EDGE,vec2(0,0),vec2(0,HEIGHT)),
            w3=physics.body(EDGE,vec2(WIDTH,0),vec2(WIDTH,HEIGHT)),
            w4=physics.body(EDGE,vec2(0,HEIGHT),vec2(WIDTH,HEIGHT))}
    wall.friction=2    
end

function draw()
    if not trail then
        background(0)
    end
    ball()    
    physics.joint(ROPE,one,two,vec2(one.x,one.y),vec2(two.x,two.y),100)
    physics.joint(ROPE,two,two2,vec2(two.x,two.y),vec2(two2.x,two2.y),100)
end

function ball()
    fill(255, 14, 0)
    ellipse(one.x,one.y,size)
    fill(67, 68, 236)
    ellipse(two.x,two.y,size,size)
    fill(135, 236, 67)
    ellipse(two2.x,two2.y,size,size)
end

function touched(t)
    speed=1
    if t.state ==BEGAN  then
        tx,ty=t.x,t.y
        trail,size=true,5
        viewer.retainedBacking=true
    end
    if t.state==CHANGED then
        ttx,tty=t.x,t.y
        vx,vy=tx-ttx,ty-tty
        one.linearVelocity=vec2(vx*speed,vy*speed)
    end
end