Draw a semicircle shape

Is there a way to draw a semicircle ShapeObject?

You mean like this?

semicircle.png

Yes, you should be able to ‘approximate’ a semicircle with: https://docs.coronalabs.com/daily/api/library/display/newPolygon.html

-- CREDIT: modification of original code by: rmbsoft (Corona Forums Member) -- local function polyArc(group, x, y, params ) local group = group or display.currentStage local params = params or {} local aw = params.w or 100 local ah = params.h or 80 local s = params.s or 0 local e = params.e or 360 local rot = params.rot or 0 local fillColor = params.fillColor or { 1, 1, 1, 1 } local strokeColor = params.strokeColor or { 1, 1, 1, 1 } local strokeWidth = params.strokeWidth or 4 local incr = params.incr or 0.02 local points = {} local xc,yc,xt,yt = 0,0,0,0 s,e = math.rad(s),math.rad(e) aw,ah = aw/2,ah/2 for t=s,e,incr do local cx,cy = xc + aw\*mCos(t), yc - ah\*mSin(t) points[#points+1] = cx points[#points+1] = cy --print(cx,cy) end -- EFM half-ellipses don't look quite right --points[#points-1] = points[1] + aw/2 --points[#points] = points[2] + ah print(#points) local theArc = display.newPolygon( group, aw/2, ah/2, points ) theArc.x = x theArc.y = y theArc.rotation = rot theArc:setFillColor( unpack( fillColor ) ) theArc:setStrokeColor( unpack( strokeColor ) ) theArc.strokeWidth = strokeWidth return theArc end

Note: I haven’t used that code for a bit, so you may need to tweak it.

polyArc( nil, display.contentCenterX, display.contentCenterY, { w = 200, h = 200, s = -90, e = 90, rot = 0 } )

This look promising, thank you! I just tried exactly this snippet, and it appears there is a bit missing at the bottom:

1iCLc5qt8.png

Any idea how I can fix that?

See also the other links mentioned recently here, or this shader.

Experiment with the code.  It’s pretty close to right.

See my comment in the code and the commented out lines.  It’s just math, so it should be pretty straightforward.  If you solve it, please post back the solution.

-Ed

Folks,

I should mention, SSK2 has a completely re-written function to create two kinds of arcs: http://roaminggamer.github.io/RGDocs/pages/SSK2/libraries/display_arcs/

I’m working on getting it released, but for now, just know it is coming.

Arcs

colorswitch.gif

PolyArcs

chomp.gif

You mean like this?

semicircle.png

Yes, you should be able to ‘approximate’ a semicircle with: https://docs.coronalabs.com/daily/api/library/display/newPolygon.html

-- CREDIT: modification of original code by: rmbsoft (Corona Forums Member) -- local function polyArc(group, x, y, params ) local group = group or display.currentStage local params = params or {} local aw = params.w or 100 local ah = params.h or 80 local s = params.s or 0 local e = params.e or 360 local rot = params.rot or 0 local fillColor = params.fillColor or { 1, 1, 1, 1 } local strokeColor = params.strokeColor or { 1, 1, 1, 1 } local strokeWidth = params.strokeWidth or 4 local incr = params.incr or 0.02 local points = {} local xc,yc,xt,yt = 0,0,0,0 s,e = math.rad(s),math.rad(e) aw,ah = aw/2,ah/2 for t=s,e,incr do local cx,cy = xc + aw\*mCos(t), yc - ah\*mSin(t) points[#points+1] = cx points[#points+1] = cy --print(cx,cy) end -- EFM half-ellipses don't look quite right --points[#points-1] = points[1] + aw/2 --points[#points] = points[2] + ah print(#points) local theArc = display.newPolygon( group, aw/2, ah/2, points ) theArc.x = x theArc.y = y theArc.rotation = rot theArc:setFillColor( unpack( fillColor ) ) theArc:setStrokeColor( unpack( strokeColor ) ) theArc.strokeWidth = strokeWidth return theArc end

Note: I haven’t used that code for a bit, so you may need to tweak it.

polyArc( nil, display.contentCenterX, display.contentCenterY, { w = 200, h = 200, s = -90, e = 90, rot = 0 } )

This look promising, thank you! I just tried exactly this snippet, and it appears there is a bit missing at the bottom:

1iCLc5qt8.png

Any idea how I can fix that?

See also the other links mentioned recently here, or this shader.

Experiment with the code.  It’s pretty close to right.

See my comment in the code and the commented out lines.  It’s just math, so it should be pretty straightforward.  If you solve it, please post back the solution.

-Ed

Folks,

I should mention, SSK2 has a completely re-written function to create two kinds of arcs: http://roaminggamer.github.io/RGDocs/pages/SSK2/libraries/display_arcs/

I’m working on getting it released, but for now, just know it is coming.

Arcs

colorswitch.gif

PolyArcs

chomp.gif