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?
Draw hollow circle / doughnut
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: Draw hollow circle / doughnut
You can do it using a series of segments & polygon.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?
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
Press <v> to get complete hollow circle.
Edit: OK! Way too complex. Don't need canvases, pixel effect, or stencils. Just use draw!
- Attachments
-
- lifesaver.love
- Simple hollow shapes
- (205.22 KiB) Downloaded 189 times
-
- mask_with_arc.love
- Circular mask
- (58.51 KiB) Downloaded 177 times
Re: Draw hollow circle / doughnut
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.
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.
- Attachments
-
- peppermint_lifesavor.love
- pseudo 3D shape
- (205.44 KiB) Downloaded 192 times
Re: Draw hollow circle / doughnut
Hi felix!felix24 wrote:have you tried using a png image?
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).
- Attachments
-
- star.love
- pixel effect to punch hole in a png image
- (219.88 KiB) Downloaded 229 times
- BlackBulletIV
- Inner party member
- Posts: 1261
- Joined: Wed Dec 29, 2010 8:19 pm
- Location: Queensland, Australia
- Contact:
Re: Draw hollow circle / doughnut
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):
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.
Code: Select all
love.graphics.setLineWidth(width)
love.graphics.circle("line", x, y, radius, segments)
To save performance, you may also want to draw the shape to a canvas and draw that each frame.
Re: Draw hollow circle / doughnut
hey man, i was replying toRef wrote:Hi felix!felix24 wrote:have you tried using a png image?
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).
kexisse wrote:How can I draw a hollow circle / doughnut shape?
Re: Draw hollow circle / doughnut
Can't you do this with an inverted stencil?
- kikito
- Inner party member
- Posts: 3153
- Joined: Sat Oct 03, 2009 5:22 pm
- Location: Madrid, Spain
- Contact:
Re: Draw hollow circle / doughnut
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)
When I write def I mean function.
Re: Draw hollow circle / doughnut
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.
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.
- Attachments
-
- falling_lifesavers.love
- Take not credit for original
- (27.81 KiB) Downloaded 183 times
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 3 guests