Howdy, Stranger!

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

Fun With Circles

I was in a project yesterday and gave a circle a negative value. The result was a cool shape, so I figured I would share a small project showcasing the result.

function setup()
    print("Hello World!")
    x = 0
    pos = vec2(WIDTH/2,HEIGHT/2)
    parameter.integer("size",20,400,225)
end

-- This function gets called once every frame
function draw()
    -- This sets a dark background color 
    background(0, 0, 0, 255)
    fill(255, 81, 0, 255)
    translate(pos.x,pos.y)
    blendMode(ADDITIVE)
    pushMatrix()
        rotate(x)
        ellipse(0,0,-1*size)
    popMatrix()
    fill(0, 153, 255, 255)
    pushMatrix()
        rotate(2*x)
        ellipse(0,0,-1*size)
    popMatrix()
    x = x + 0.75
end
function touched(t)
    pos.x = t.x
    pos.y = t.y
end
Tagged:

Comments

  • dave1707dave1707 Mod
    Posts: 8,456

    @thebombdiggity You also get some odd circles by having a large circle size. I posted this back in April 2014. Changing the circle size gives different images, but not all values show something. This is for a Retina display. I don't know if anything will show on a non Retina display.

    displayMode(OVERLAY)
    
    function setup()
        parameter.integer("size",20000000,90000000,64659584)
    end
    
    function draw()
        background(0)
        noFill()
        stroke(255)
        strokeWidth(2)
        ellipse(WIDTH/2,HEIGHT/2,size)
    end
    
  • @dave1707 My iPad has a Retina display, but nothing shows up. Strange...

  • dave1707dave1707 Mod
    edited October 2015 Posts: 8,456

    @thebombdiggity Do you see anything when you use the slider to change values. I'm using an iPad Air. Maybe it's seen only on an iPad Air, because I get different images as I use the slider.

  • No, I don't see anything when I use the slider. I'm on an iPad 4th generation so maybe it's just the fact that the iPad is older

  • dave1707dave1707 Mod
    Posts: 8,456

    Just have to wait and see if anyone else can see something and what they're using.

  • Posts: 216

    Non retina, iPad mini 1, latest codea release, just get a black screen.

  • IgnatzIgnatz Mod
    Posts: 5,396

    iPad Air 2, dave's not imagining things, I get a grainy black and white circular pattern

  • dave1707dave1707 Mod
    edited October 2015 Posts: 8,456

    Here's a video of what I see. The image changes as I move the slider. Not all slider values creates an image.

    
    
  • IgnatzIgnatz Mod
    Posts: 5,396

    yep, I get that too

    not sure what you can do with it, though

  • dave1707dave1707 Mod
    Posts: 8,456

    @Ignatz If I'm drawing a circle with a radius of 64,000,000 , why should I be seeing something on the screen at all. @thebombdiggity Sorry for hijacking your discussion. Your program shows that giving functions unusual values sometimes gives interesting results. Try setting up 2 parameters for the 2 sizes of an ellipse in your program. Set the 2 size values to run from -400 to 400 and see what you get as you change the values.

  • @dave1707 Wow! There are some amazing designs that can be gotten from messing with those parameters! I added more colors and it looks even more amazing. I can't believe I hadn't already tried that.

  • SimeonSimeon Admin Mod
    Posts: 5,386

    The reason for the differences is because the GPU in the iPad Air 2 and previous generations differ. The extreme size of the circle is probably causing floating-point overflows, and different GPUs handle it differently.

  • dave1707dave1707 Mod
    Posts: 8,456

    @Simeon Thanks for the explanation. @thebombdiggity Can you post your new program when you get finished.

  • Posts: 289

    funny and interesting, a circle a negative value, extreme size

  • @dave1707 Here you go

    displayMode(OVERLAY)
    function setup()
        print("Hello World!")
        x = 0
        pos = vec2(WIDTH/2,HEIGHT/2)
        parameter.watch("math.floor(1/DeltaTime)")
        parameter.integer("size",-400,400,225)
        parameter.integer("size2",-400,400,225)
        colors = {
        color(255, 81, 0, 255),
        color(0, 153, 255, 255),
        color(215, 0, 255, 255),
        color(0, 255, 64, 255),
        color(0, 255, 205, 255),
        color(107, 0, 255, 255),
        }
        parameter.integer("amount",1,#colors,2)
    end
    -- This function gets called once every frame
    function draw()
        -- This sets a dark background color 
        background(0, 0, 0, 255)
        translate(pos.x,pos.y)
        blendMode(ADDITIVE)
        for i = 1,amount do
            create(0,0,i*x,colors[i])
        end
        x = x + 0.75
    end
    function create(x1,y1,r,c)
        pushMatrix()
        pushStyle()
            fill(c)
            rotate(r)
            ellipse(x1,y1,-1*size,-1*size2)
        popStyle()
        popMatrix()
    end
    function touched(t)
        pos.x = t.x
        pos.y = t.y
    end  
    
  • dave1707dave1707 Mod
    Posts: 8,456

    Nice job. Really shows some interesting designs.

  • edited June 16 Posts: 193
    I need help with a delay fx, PGM runs at 60fps a sec. I would like to slow it down with a time elapsed fx

    ~~~
    -- Ellipse

    function setup()
    ellipseMode(CENTER)
    displayMode(FULLSCREEN)
    t=ElapsedTime
    end

    function draw()
    background(0)
    t=t+2
    -- Draw a random color
    fill(math.random(255),math.random(255),math.random(255))
    -- Line thickness
    strokeWidth(3)
    -- Color stroke(41, 21, 196)
    -- Shape location along the x, y axis ;
    -- Size along the x, y axis
    ellipse(400,200,300,200)
    end
    ~~~
  • dave1707dave1707 Mod
    Posts: 8,456

    Here your code with a 2 second delay.

    displayMode(FULLSCREEN)
    
    function setup()
        ellipseMode(CENTER) 
        strokeWidth(3)
        t=ElapsedTime
    end
    
    function draw()
        background(0)
        if ElapsedTime>t+2 then      -- 2 second delay
            colr=color(math.random(255),math.random(255),math.random(255))
            fill(colr)
            t=ElapsedTime
        end
        ellipse(400,200,300,200)
    end
    
  • Posts: 193
    Is there any trick to make the ellipse stay on the screen instead of being cleared away by the background CMD ?...
  • dave1707dave1707 Mod
    Posts: 8,456

    @kendog400 Like this.

    displayMode(FULLSCREEN)
    
    function setup()
        ellipseMode(CENTER) 
        strokeWidth(3)
        t=ElapsedTime
        backingMode(RETAINED)
    end
    
    function draw()
        --background(0)
        if ElapsedTime>t+1 then      -- 1 second delay
            colr=color(math.random(255),math.random(255),math.random(255))
            fill(colr)
            t=ElapsedTime
            ellipse(math.random(WIDTH),math.random(HEIGHT),300,200)
        end
    end
    
  • Posts: 193
    Another question : does codea have overlay modes like in photoshop's ?....
  • dave1707dave1707 Mod
    Posts: 8,456

    Not sure what photoshop does. You can create multiple pages and display one over the other or move one in relation to the other.

  • edited June 21 Posts: 1,752
    @kendog400 - Codea does have overlays. You can specify them, I think they may be called levels - possibly z level, haven't actually used them. Look in the graphics section of the reference within the Codea app or on the web.

    Edit - just checked the web ref and it's zlevel, check it out.
  • Posts: 193
    I checked and codea has 3 blend modes, normal, additive, and multiply....
  • dave1707dave1707 Mod
    Posts: 8,456

    While we’re on the subject, here’s a program I wrote long ago. It creates random colored circles and grows them a random size or until they touch another circle.

    displayMode(FULLSCREEN)
    
    function setup()
        tab={}
        x=math.random(WIDTH)
        y=math.random(HEIGHT)
        d=math.random(20,80)
        table.insert(tab,vec3(x,y,d))
        col={}
        table.insert(col,color(math.random(255),math.random(255),math.random(255)))
        makeCircle=true
        growCircle=false
    end
    
    function draw()
        background(0)
        for a,b in pairs(tab) do
            fill(col[a])
            ellipse(b.x,b.y,b.z)
        end
        if makeCircle then
            x=math.random(WIDTH)
            y=math.random(HEIGHT)
            d=0
            table.insert(tab,vec3(x,y,d))
            table.insert(col,color(math.random(255),math.random(255),math.random(255)))
            checkLimit(x,y)
        end
        if growCircle then
            tab[#tab].z=tab[#tab].z+1  
            if tab[#tab].z>size then
                growCircle=false
                makeCircle=true
            end
        end
    end
    
    function checkLimit(x,y)
        --print("checklimit")
        d=9999
        for a,b in pairs(tab) do
            if a<#tab then
                v1=vec2(x,y)
                dis=v1:dist(vec2(b.x,b.y))
                if dis<b.z/2 then
                    table.remove(tab,#tab) 
                    table.remove(col,#col)
                    makeCircle=true  
                    growCircle=false           
                    return
                else
                    dis=dis-b.z/2
                    if dis<d then
                        d=dis
                    end
                end
            end  
        end
        size=d*2+4
        if size>160 then
            size=math.random(20,80)
        end 
        makeCircle=false
        growCircle=true           
    end
    
  • Posts: 1,752
    @kendog400 - those modes are for merging graphics, is that what you need? The zlevel is for 2D overlapping of graphics so you can move graphics in 2.5D formats to simulate 3D without interfering with graphics in other levels.
  • Posts: 193
    Yes, I'm looking to blend and merge to spice up animations...
  • edited June 21 Posts: 1,752
    @kendog400 - if you search the forum for blend modes you should find several goods demos on this. Needed them recently to cut out a circle within a built up graphic.
  • Posts: 193
    I did check the blend modes and only the additive one worked, .multiply didn't work....So I'll take that with a smile....
  • edited June 22 Posts: 1,752

    @kendog400 - did you check out the following thread?

    Blendmode Demos

    Demos there for you.

Sign In or Register to comment.