Android Question Need Advise how to make smooth arc scroll

Scantech

Well-Known Member
Licensed User
Longtime User
the codes below draws an arc in xGauges. I am trying to find ways to make the arc scroll (Draws) smoothly. I have failed on many attempts which the codes are not shown. For example, the needle can be scrolled smoothly using pnl.SetRotationAnimated but cannot figure out this DrawArc routine.

B4X:
Private Sub DrawArc(CenterX As Int, CenterY As Int, Radius As Int, StartAngle As Int, SweepAngle As Int, Color As Int, Strokewidth As Int)
    Private Angle, x1, y1, x2, y2 As Float
    Private i As Int

    Angle = StartAngle
    
    x1 = CenterX + Radius * CosD(Angle)
    y1 = CenterY + Radius * SinD(Angle)

    For i = StartAngle + 1 To StartAngle + SweepAngle
        Angle = Angle + 1
        x2 = CenterX + Radius * CosD(Angle)
        y2 = CenterY + Radius * SinD(Angle)
        cvsGauge.DrawLine(x1, y1, x2, y2, Color, Strokewidth)
        x1 = x2
        y1 = y2
    Next
End Sub
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Might be useful: https://www.b4x.com/android/forum/threads/b4x-xui-custom-view-circularprogressbar.81604/#content

CircularProgressBar.gif
 
Upvote 0

Scantech

Well-Known Member
Licensed User
Longtime User
Thanks Erel. It works really well with the Drawarc. I might even consider using this for my needles instead of SetRotationAnimated. I will compare the smoothness. Also the Text label can be updated with the newvalue which SetRotationAnimated cannot do.
 
Upvote 0
Top