Multi-touch help

I need to figure out a way to make the touch stay the color it started in. Run the code to see what i’m am talking about. I started with the example multi-touch project and modded it, in my attempts so far I ended up with this (but it still doesn’t work the way I wanted it to)
Code:


--# Main
-- Multi-touch Handeler

-- Use this function to perform your initial setup
function setup()
    print("This example tracks multiple touches and colors them based on their position")
    
    -- keep track of our touches in this table
    touches = {}
end

-- This function gets called whenever a touch
--  begins or changes state
function touched(touch)
    if touch.state == ENDED or touch.state == CANCELLED then
        -- When any touch ends, remove it from
        --  our table
        touches[touch.id] = nil

    else
        -- If the touch is in any other state 
        --  (such as BEGAN) we add it to our
        --  table
        touches[touch.id] = touch
                if touch.x <= WIDTH/2 and touch.y <= HEIGHT/2 then
        Color = color(26, 97, 145, 255)
        elseif touch.x >= WIDTH/2 and touch.y >= HEIGHT/2 then
        Color = color(67, 143, 33, 255)
        elseif touch.x <= WIDTH/2 and touch.y >= HEIGHT/2 then
        Color = color(167, 23, 23, 255)
        elseif touch.x >= WIDTH/2 and touch.y <= HEIGHT/2 then
        Color = color(171, 175, 22, 255)
        end
    end
end

function draw()
    background(127, 127, 127, 255)
    fill(255, 0, 0, 255)
    rect(0,HEIGHT/2,WIDTH/2,HEIGHT/2)
    fill(0, 135, 255, 255)
    rect(0,0,WIDTH/2,HEIGHT/2)
    fill(51, 181, 20, 255)
    rect(WIDTH/2,HEIGHT/2,WIDTH/2,HEIGHT/2)
    fill(255, 234, 0, 255)
    rect(WIDTH/2,0,WIDTH/2,HEIGHT/2)
    stroke(0, 0, 0, 255)
    strokeWidth(2)
    line(0,HEIGHT/2,WIDTH,HEIGHT/2)
    line(WIDTH/2,0,WIDTH/2,HEIGHT)
    noStroke()
    for k,touch in pairs(touches) do

        -- Use the touch id as the random seed
        math.randomseed(touch.id)

        -- This ensures the same fill color is used for the same id
        fill(Color)
        -- Draw ellipse at touch position
        ellipse(touch.x, touch.y, 80, 80)
    end
end

In the meantime i’ll try to find a way to do it myself.

@GameCoder Will this help.

displayMode(FULLSCREEN)

function setup()
    tch={}   
end

function draw()
    background(40, 40, 50)
    noStroke()
    fill(255,0,0)
    rect(0,HEIGHT/2,WIDTH/2,HEIGHT/2)
    fill(0,255,0)
    rect(WIDTH/2,HEIGHT/2,WIDTH/2,HEIGHT/2)
    fill(0,0,255)
    rect(0,0,WIDTH/2,HEIGHT/2)
    fill(255,0,255)
    rect(WIDTH/2,0,WIDTH/2,HEIGHT/2)
    for a,b in pairs(tch) do
        fill(b.col)
        stroke(255)
        strokeWidth(3)
        ellipse(b.x,b.y,100)
    end
end

function touched(t)
    if t.state==BEGAN then
        if t.x<WIDTH/2 and t.y<HEIGHT/2 then
            tch[t.id]={x=t.x,y=t.y,col=color(0,0,255)}
        elseif t.x>WIDTH/2 and t.y<HEIGHT/2 then
            tch[t.id]={x=t.x,y=t.y,col=color(255,0,255)}
        elseif t.x<WIDTH/2 and t.y>HEIGHT/2 then
            tch[t.id]={x=t.x,y=t.y,col=color(255,0,0)}
        elseif t.x>WIDTH/2 and t.y>HEIGHT/2 then
            tch[t.id]={x=t.x,y=t.y,col=color(0,255,0)}
        end
    elseif t.state==MOVING then
        tch[t.id].x=t.x
        tch[t.id].y=t.y
    elseif t.state==ENDED then
        tch[t.id]=nil
    end
end

Thanks :), this will help a lot, I wanted to make it so I could detect where touches started on the screeen for multiplayer same screen gestures.