Help with draw() function

@possibleAdam Here’s an example using CAMERA and get/set to alter the image. There image bug isn’t fixed yet, but here’s something that gets around it. Aim the camera at something and tap the screen. Tap the screen again to show a normal live image. You can alter the slider value to change how the image is processed. The lower the value, the more colorful it is. There’s no need to close the parameter window. It will close and open depending on what’s happening.

viewer.mode=OVERLAY

function setup()
    parameter.integer("div",1,25,10)
end

function draw()
    background(0)
    img=image(CAMERA)
    collectgarbage()
    if img1~=nil then
        sprite(img1,WIDTH/2,HEIGHT/2)
    elseif img~=nil then
        sprite(img,WIDTH/2,HEIGHT/2)
    end 
end

function touched(t)
    if t.state==BEGAN then
        if img1~=nil then
            img1=nil
            viewer.mode=OVERLAY
        else
            img1=img:copy()
            iw=img1.width
            ih=img1.height
            process()
        end
    end    
end
                    
function process()
    viewer.mode=FULLSCREEN
    for x=3,iw,5 do
        for y=3,ih,5 do
            tr,tg,tb=0,0,0
            for a=-2,2 do
                for b=-2,2 do
                    if (x+a)<iw and (y+b)<ih then
                        r,g,b=img1:get(x+a,y+b)
                        tr=tr+r
                        tg=tg+g
                        tb=tb+b
                    end
                end
            end
            for a=-2,2 do
                for b=-2,2 do
                    if (x+a)<iw and (y+b)<ih then
                        img1:set(x+a,y+b,tr//div,tg//div,tb//div)
                    end
                end
            end
        end
    end
end

@dave1707 thank you. Could someone please explain to me again how to format the code. It doesn’t seem to be working.

I tried this and other variants:

Code

@possibleAdam Where are you posting code from. The tildes only seem to work when using an iPad.