Try this
function setup()
    --create an image
    img=image(600,600)
    setContext(img)
    stroke(255,255,0)
    strokeWidth(2)
    fill(0,0,0,0)
    ellipse(300,300,300)
    ellipse(375,325,300)
    setContext()
    --fill the three parts of the image
    Flood(img,color(255,0,0),color(0),300,300)
    Flood(img,color(0,0,255),color(0),200,300)
    Flood(img,color(0,255,0),color(0),500,300)
end
function draw()
    background(0)
    sprite(img,WIDTH/2,HEIGHT/2)
end
--p is the image
--c is the new colour 
--r is the colour to replace
--x,y are the x,y values of the pixel to start from 
--(any pixel inside the area you want filled)
function Flood(p,c,r,x,y,tbl)
    if tbl==nil then 
        tbl={}
        for i=1,p.width do tbl[i]={} end
    end
    if tbl[x][y]==nil then 
        local r,g,b=p:get(x,y)
        tbl[x][y]=color(r,g,b)
    end
    if tbl[x][y]==r then 
        p:set(x,y,c)
        tbl[x][y]=c
        --now check the neighbours around
        local w,h=p.width,p.height
        if x>1 then Flood(p,c,r,x-1,y,tbl) end
        if x<w then Flood(p,c,r,x+1,y,tbl) end
        if y>1 then Flood(p,c,r,x,y-1,tbl) end
        if y<h then Flood(p,c,r,x,y+1,tbl) end
        if x>1 and y>1 then Flood(p,c,r,x-1,y-1,tbl) end
        if x<w and y<h then Flood(p,c,r,x+1,y+1,tbl) end
        if y>1 and x<w then Flood(p,c,r,x+1,y-1,tbl) end
        if x>1 and y<h then Flood(p,c,r,x-1,y+1,tbl) end
    end
end