Half of a circle

dkarnik

Member
Licensed User
Longtime User
whole circle can be made with this
Canvas1.DrawCircle(150dip, 150dip, 20dip, Colors.Red, False, 10dip)

but how to draw a half of that same circle?
 

GMan

Well-Known Member
Licensed User
Longtime User
First issue can be:
draw a black (color of background) rectangle over the half of the circle
 
Upvote 0

yttrium

Active Member
Licensed User
Longtime User
First issue can be:
draw a black (color of background) rectangle over the half of the circle

Or maybe draw the full circle with twice the height (or width) and then crop with a Rect redraw.

That way, transparency stays intact.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
You can do it with the ABExtDrawings library.
B4X:
Sub Globals
    Dim ExtDrawing As ABExtDrawing
    Dim cvsMain As Canvas
End Sub

Sub Activity_Create(FirstTime As Boolean)
    cvsMain.Initialize(Activity)
End Sub

Sub Activity_Resume
    DrawCircleArc(150dip, 100dip, 20dip, 0, 180, Colors.Red, False, 3, True)
    DrawCircleArc(150dip, 150dip, 20dip, 90, 180, Colors.Blue, False, 3, False)
    DrawCircleArc(150dip, 200dip, 20dip, 0, -180, Colors.Green, True, 3, True)
    DrawCircleArc(120dip, 250dip, 20dip, 0, -235, Colors.Green, False, 3, False)
    DrawCircleArc(180dip, 250dip, 20dip, 0, -235, Colors.Green, False, 3, True)
    DrawCircleArc(120dip, 300dip, 20dip, 0, -235, Colors.Green, True, 3, False)
    DrawCircleArc(180dip, 300dip, 20dip, 0, -235, Colors.Green, True, 3, True)
End Sub

Sub DrawCircleArc(cx As Float, cy As Float, Radius As Float, StartAngle As Float, SweepAngle As Float, col As Int, Filled As Boolean, StrokeWidth As Float, UseCenter As Boolean)
    Dim r As ABRectF
    r.Initialize(cx - Radius, cy - Radius, cx + Radius, cy + Radius) 
    Dim paint As ABPaint
    paint.Initialize
    If Filled = True Then
        paint.SetStyle(paint.Style_FILL)
    Else
        paint.SetStyle(paint.Style_STROKE)
    End If
    paint.SetColor(col)
    paint.SetStrokeWidth(StrokeWidth)
    ExtDrawing.drawArc(cvsMain, r, StartAngle, SweepAngle, UseCenter, paint)
End Sub
Angle 0 is the trigonometric 0 (3 o'clock)
SweepAngle direction: positive clockwise.

The arc in the drawArc function is defined by the surrounding rectangle that means it allows also to draw eliptic arcs.

Attached a small test program.

Best regards.
 

Attachments

  • HalfCircle.zip
    6.1 KB · Views: 337
Upvote 0

GMan

Well-Known Member
Licensed User
Longtime User
I was sure that there is the possibilty - nearly nothing, what 4ba NOT can :sign0098:
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Another option with Path:
B4X:
Sub Activity_Create(FirstTime As Boolean)
   Dim cvs As Canvas
   cvs.Initialize(Activity)
   Dim cx = 150dip, cy = 150dip As Int
   Dim r As Int = 50dip
   Dim rt As Int = r + 10dip 'stroke width
   Dim p As Path
   p.Initialize(cx - rt, cy - rt)
   p.LineTo(cx + rt, cy - rt)
   p.LineTo(cx + rt, cy)
   p.LineTo(cx - rt, cy)
   cvs.ClipPath(p)
   cvs.DrawCircle(cx, cy, r, Colors.Red, False, 10dip)
   cvs.RemoveClip
   Activity.Invalidate
End Sub
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…