Howdy, Stranger!

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

The Shading Affect

edited June 2016 in Code Sharing Posts: 3

`Hi guys. This is a code that I call the shading affect. I think it is very cool and I hope you enjoy.

--The Shading Affect
-- These lines happen at the start to setup the program
function setup()
    background(0,0,0,255)           -- This sets the background color to black

    s = 700                         -- This sets the size to a variable that we can change
    x = WIDTH/2                     -- These set the x and y coordinates to a number that we can change                     
    y = HEIGHT/2                    -- during the code. These values make the shading affect.
    one = color(255, 0, 247, 255)   -- These next 4 lines set the colors. We need these so that it doesnt 
    two = color(255, 0, 6, 255)     -- glitch after the end of the shading affect.
    three = color(255, 140, 0, 255)   
    four = color(255, 255, 255, 255)   
end

-- These lines of code get called 60 times per second
function draw()

    ellipse(x, y, s)    -- All of the 4 sets of code (staring will ellipse and ending with s =) are very
    fill(one)           -- similar. they all create an ellipse at ("x","y") with the size of "s". This
    y = y+1             -- allowes the circle to be differnt every time. Then it either adds or subracts 1
    s = s-0.5           -- from "x" or "y". This makes the circle change it's postion evry time and makes the 
    ellipse(x, y, s)    -- shading affect. Next it reduces "s" (the size) by 1 so the next is a bit smaller.
    fill(two)           -- This repeats until the value "s" gets to 0.
    x = x+1
    s = s-0.5
    ellipse(x, y, s)
    fill(three)
    y = y-1
    s = s-0.5
    ellipse(x, y, s)
    fill(four)
    x = x-1
    s = s-0.5

    if s == 0 then                          -- This is checking if the size of the circle is 0. If it is 0
        one = color(255, 159, 0, 0)         -- then change all the colors to transparent so we cant see them.
        two = color(255, 255, 255, 0)       -- Feel free to change the colors at the top to make your own,
        three = color(255, 255, 0, 0)       -- unique circle. Hope you enjoy.
        four = color(255, 197, 0, 0)
    end

end
Tagged:

Comments

  • IgnatzIgnatz Mod
    Posts: 5,396

    Nice effect, but the picture flickers after it is finished drawing

    If you put this line at the top of the draw function, it gets rid of the flicker

    if s==0 then return end
    
  • edited June 2016 Posts: 3

    Sooty about how it turned out. You can copy the whole thing into Codea and then it should work.

  • dave1707dave1707 Mod
    Posts: 6,831

    Nice. I can see the individual circles still flickering a little even after adding the if s==0 code. So I added the line backingMode(RETAINED) at the end of the setup function. That seemed to smooth out the circles and blend the colors more.

Sign In or Register to comment.