Page 1 of 2

Draw hollow circle / doughnut

Posted: Thu Aug 23, 2012 12:26 am
by kexisse
I thought this might be possible with setStencil but it doesn't seem to make sense for hollow stuff.

How can I draw a hollow circle / doughnut shape?

Re: Draw hollow circle / doughnut

Posted: Thu Aug 23, 2012 2:31 am
by Ref
kexisse wrote:I thought this might be possible with setStencil but it doesn't seem to make sense for hollow stuff.

How can I draw a hollow circle / doughnut shape?
You can do it using a series of segments & polygon.

Code: Select all

function arc_seg()
    local acx, acy    = mask.width/2, mask.height/2    -- arc center
    local rado, radi = 1.5 * mask.size, mask.size          -- outer & inner radius
    local arco, arci  = {}, {}                                         -- tables of arc points
    local arcs, arce  = mask.angle, mask.angle + mask.circle	-- start & ending angle
    local idx            = mask.size / 4                            -- steps in arc
    local val            = 1
    for i = arcs, arce,pi / idx do
         local xo       = rado * math.cos(i) + acx
         local yo       = rado * math.sin(i) + acy
         local xi        = radi * math.cos(i) + acx
         local yi        = radi * math.sin(i) + acy
         arco[val]      = { xo, yo }
         arci[val]       = { xi, yi }
         val               = val + 1
        end
     for i = 1, #arco - 1 do        -- polygon can't handle all the points at once
         gr.polygon('fill',
            arco[i][1],    arco[i][2],    arco[i+1][1],    arco[i+1][2],
            arci[i+1][1], arci[i+1][2], arci[i][1],	         arci[i][2])
            end
    end
This is the code I used for demo script 'mask_with_are.love
Press <v> to get complete hollow circle.
Edit: OK! Way too complex. Don't need canvases, pixel effect, or stencils. Just use draw!

Re: Draw hollow circle / doughnut

Posted: Sat Aug 25, 2012 11:08 pm
by Ref
Just trying things out.
Tried to make a doughnut shape have a pseudo 3D apperance.
Nothing optimized - used canvas & pixel effect.
Same effect can obviously be done with mapPixel and no caanvas.
<a><s> alters effect & <q><w> changes object size.

Re: Draw hollow circle / doughnut

Posted: Mon Aug 27, 2012 4:07 pm
by felix24
have you tried using a png image?

Re: Draw hollow circle / doughnut

Posted: Tue Aug 28, 2012 12:19 am
by Ref
felix24 wrote:have you tried using a png image?
Hi felix!
Not sure to whom you are replying.
The demo I supplied (peppermint_lifesaver) can be used with a png file in place of creating a canvas.
The pixel effect works just as well.
It punches a hole in the center of the image and applies shading effects to the remaining portion of the image (see attached demo).

Re: Draw hollow circle / doughnut

Posted: Tue Aug 28, 2012 3:15 am
by BlackBulletIV
I'm not quite sure if I'm understanding the problem correctly, but it sounds like you could make a donut shape by using code like this (note that I haven't tested it):

Code: Select all

love.graphics.setLineWidth(width)
love.graphics.circle("line", x, y, radius, segments)
Replace x, y, and radius with their appropriate values, make sure to replace segments with a value that ensures the donut looks smooth enough, and replace width with how wide you want the "solid part" of the donut to be.

To save performance, you may also want to draw the shape to a canvas and draw that each frame.

Re: Draw hollow circle / doughnut

Posted: Tue Aug 28, 2012 9:04 pm
by felix24
Ref wrote:
felix24 wrote:have you tried using a png image?
Hi felix!
Not sure to whom you are replying.
The demo I supplied (peppermint_lifesaver) can be used with a png file in place of creating a canvas.
The pixel effect works just as well.
It punches a hole in the center of the image and applies shading effects to the remaining portion of the image (see attached demo).
hey man, i was replying to
kexisse wrote:How can I draw a hollow circle / doughnut shape?
^^

Re: Draw hollow circle / doughnut

Posted: Wed Aug 29, 2012 9:42 pm
by Kadoba
Can't you do this with an inverted stencil?
doughnut.love
(242 Bytes) Downloaded 177 times

Re: Draw hollow circle / doughnut

Posted: Thu Aug 30, 2012 1:53 pm
by kikito
Modifying the line width and then drawing a "line" circle is considered cheating, right?

Code: Select all

-- draw a doughnut of internal radius 10, external radius 40, centered on 100, 100
love.graphics.setLineWidth(20)
love.graphics.circle("line", 100, 100, 30)

Re: Draw hollow circle / doughnut

Posted: Thu Aug 30, 2012 3:00 pm
by Ref
Boy!
We sure have beat this one to death!
Seems like the only one not too interested in it is Kexisse.
Felix's idea seems best for static textured holely objects while line width - circle for procedurally generated plain objects.
Couldn't resist another cobbed up demo.