a small drawing tool

function setup()
    backingMode(RETAINED)
    capmode = {}
    capmode[0] = ROUND
    capmode[1] = SQUARE
    capmode[2] = PROJECT
    iparameter("endstyle", 0,2,0)
    iparameter("s", 5, 100,40)
    iparameter("opacity", 10, 255, 255)
end

function draw()
    lineCapMode(capmode[endstyle])
    stroke(255, 255, 255, opacity)
end

function touched(touch)
    current = vec2(CurrentTouch.x, CurrentTouch.y)
    previus = vec2(touch.prevX, touch.prevY)
    dist = current:dist(previus)
    size = s-dist
    if size<=5 then size = 5 end
    strokeWidth(size)
    if(touch.state == MOVING) then
        line(current.x, current.y, previus.x, previus.y)
    end
    if(touch.state == BEGAN) then 
        ellipse(current.x, current.y, s)
    end
end