Finger Painting v1.1

Another one I’ve thrown together for my toddlers. It’s a very simple multitouch painting thing. Only tested landscape on IPad2.

I also always have the multitouch OS level stuff turned off, so it’ll go up to 10 touch points (great for toddlers mashing their hands on the screen)

function setup()
    displayMode(FULLSCREEN)
    --supportedOrientations(LANDSCAPE_ANY)
    --myFPSReporter = FPSReporter(4)
    noSmooth()
    
    touches = {}
    
    nextball = 0
    backingMode(RETAINED)
    
    palette = {}
    palette[1] = { r=0, g=0, b=0 }
    palette[2] = { r=0xff, g=0xff, b=0 }
    palette[3] = { r=0xff, g=0, b=0 }
    palette[4] = { r=0xff, g=0xa5, b=0 }
    palette[5] = { r=0xff, g=0, b=0xff }
    palette[6] = { r=0x8b, g=0, b=0xff }
    palette[7] = { r=0x00, g=0xff, b=0x00 }
    palette[8] = { r=0xa5, g=0x2a, b=0x2a }
    palette[9] = { r=0xff, g=0xff, b=0xff }
    palette[10] = { r=0, g=0, b=0xff }
    
    strokeWidth(0)
    local piclist = spriteList("Dropbox")
    numpics = 0
    pics = {}
    currentpic = 1
    for k,v in pairs(piclist) do
        if string.find(v, "colouring", 1, true) == 1 then
            numpics = numpics + 1
            pics[numpics] = v
        end
    end
    size = vec2()
    if numpics > 0 then
        size.x, size.y = spriteSize("Dropbox:"..pics[currentpic])
        if size.x > WIDTH - 70 then
            size.y = size.y / size.x * (WIDTH - 70)
            size.x = WIDTH - 70
        end
        if size.y > HEIGHT then
            size.x = size.x / size.y * HEIGHT
            size.y = HEIGHT
        end
    end
    drawpalette = true
    startup = true
    currentColour = 1
end

function drawPalette()
    fill(75, 75, 75, 255)
    rect( WIDTH-70, 0, WIDTH, HEIGHT)
    for i=1,10 do
        fill( palette[i].r, palette[i].g, palette[i].b, 255)
        ellipse(WIDTH-35, i*70-15, 60)
    end
    if numpics > 0 then
        sprite("Cargo Bot:Command Left", WIDTH - 50, HEIGHT - 15, 30, 30)
        sprite("Cargo Bot:Command Right", WIDTH - 20, HEIGHT - 15, 30, 30)
    end
    drawpalette = false
end

function checkPalette(x, y)
    if x < WIDTH - 65 or x > WIDTH - 5 then
        return nil
    end
    for i=1,10 do
        if math.sqrt((x - (WIDTH-35))^2 + (y - (i*70-15))^2) < 60 then
            return i
        end 
    end     
end

function touched(touch)
    if touch.state == BEGAN then
        i = checkPalette(touch.x, touch.y)
        if i ~= nil then
            currentColour = i
        end
        if touch.x > WIDTH-65 and touch.x < WIDTH-5 and touch.y > HEIGHT - 30 and numpics > 0 then
            if touch.x > WIDTH - 35 then
                currentpic = currentpic + 1
                if currentpic > numpics then 
                    currentpic = 1
                end
            else
                currentpic = currentpic - 1
                if currentpic == 0 then
                    currentpic = numpics
                end
            end
            size.x, size.y = spriteSize("Dropbox:"..pics[currentpic])
            if size.x > WIDTH - 70 then
                size.y = size.y / size.x * (WIDTH - 70)
                size.x = WIDTH - 70
            end
            if size.y > HEIGHT then
                size.x = size.x / size.y * HEIGHT
                size.y = HEIGHT
            end
            startup = true
            drawpalette = true
        end
    end
    if touch.state == ENDED then
        touches[touch.id] = nil
    end
    if touches[touch.id] ~= nil then
        steps = math.abs(touches[touch.id].x - touch.x)
        if steps < math.abs(touches[touch.id].y - touch.y) then
            steps = math.abs(touches[touch.id].y - touch.y)
        end
        steps = math.floor(steps)
        for i = 1, steps do
            x = touches[touch.id].x + (touch.x - touches[touch.id].x)/steps * i
            y = touches[touch.id].y + (touch.y - touches[touch.id].y)/steps * i
            if x < WIDTH - 70 then
                ellipse(x, y, 15)
            end 
        end
    end
    touches[touch.id] = touch
        
end    

function draw()
    if CurrentTouch.state == ENDED then
        for k,v in pairs(touches) do 
            --if there are no current touches then we kill all current touches
            touches[k] = nil
        end
    end
    
    if startup then
        background(255,255,255,0)
        startup = false
    end
    if numpics > 0 then
        sprite("Dropbox:"..pics[currentpic], (WIDTH-70)/2, HEIGHT/2, size.x, size.y)
    end
    if drawpalette then
        drawPalette()
    end
    --fill(0,0,0,255)
    --ellipse(WIDTH, 0, 80)
    --myFPSReporter:draw(3)
    fill(palette[currentColour].r, palette[currentColour].g, palette[currentColour].b, 255)
    
end

Modified so it now can have an image to draw on. Basically load images into Dropbox which are black outlines with transparent backgrounds. They need to be named beginning with “colouring” eg “colouringLion.png”

You can google for coloring pictures and the image search will give you loads, converting them is as simple as loading them into paint.net (free) and use the magic wand to delete all the white background and save.

The images need transparency as they are painted over the top every frame.

Merge this with “liquid line flow” post here :slight_smile:

Edit: just merged it, pretty fun!