Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Radial gradient

edited August 2014 in General Posts: 142

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

Comments

  • Jmv38Jmv38 Mod
    Posts: 3,295

    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
    
    
    
  • Posts: 142

    @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!

  • dave1707dave1707 Mod
    Posts: 7,924

    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
  • Posts: 2,820

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

Sign In or Register to comment.