Radial gradient

How can I make a radial gradient? I looked around the forums, but couldn’t find anything clearly explaining how to do so.

here is one

-- radial gradient

function setup()
    c1 = color(255,0,0)
    c2 = color(0,0,255)
    s = radial( 300, c1, c2)
end
function radial(w,c1,c2)
    local img = image(2*w,2*w)
    ellipseMode(RADIUS)
    strokeWidth(2)
    fill(0,0)
    setContext(img)
        background(c1)
        local wmax = math.ceil(math.sqrt(2) * w)
        for i =1,wmax do
            stroke( c1:mix(c2,i/wmax) )
            ellipse(w,w,i)
        end
    setContext()
    img:set(2,2,c2)
    return img
end

function draw()
    background(40, 40, 50)
    sprite(s, 350,350)
end


@Jmv38 works great! Just what I needed. If there are any other ways to make radial gradients, please post them here too. Not that I need them, but just to help me and anyone reading this thread how gradients work!


displayMode(FULLSCREEN)

function setup()  
    rectMode(CENTER) 
end

function draw()
    background(0,0,0)
    r=255
    b=0
    for z=255,1,-1 do
        fill(r,0,b)
        ellipse(WIDTH/2,HEIGHT-300,z)
        rect(WIDTH/2,300,z,z)
        r=r-1
        b=b+1
    end
end

See line 1517 here: https://gist.github.com/Zoyt/8194326#file-main-lua-L1517 (It should jump to that line automatically.) Hope that helps!