Is a bug on Drawline command ?

strat

Active Member
Licensed User
Longtime User
B4X:
Sub Process_Globals
   
End Sub

Sub Globals
   Dim Canvas1 As Canvas
   Dim i,r,g,b,rx,bx,gx,y  As Int
End Sub

Sub Activity_Create(FirstTime As Boolean)
   canvas1.Initialize(Activity)
   r=4
   g=128
   b=180
   y=400
   globe
End Sub


Sub Globe
  'Canvas1.DrawColor(Colors.Black)
  For i=290 To 510 
   Canvas1.DrawLine(0,i,479,y, Colors.RGB(r,g,b),1)
  Next
  Activity.Invalidate
  
End Sub

By this code, a filled triangle must be drawn in the center of the screen but almost half of filled triangle appears. Is this a bug or the code is wrong ? Changing y variable you can see the result.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
1 pixel drawings sometimes disappear because of internal rounding. Change the stroke width to 2. Note that it is better to specify all dimensions with dpi units.

A much (much) faster way to draw a filled triangle using Path and ClipRegion:
B4X:
Sub Process_Globals
    
End Sub

Sub Globals
    Dim Canvas1 As Canvas
    Dim i,r,g,b,rx,bx,gx,y  As Int
End Sub

Sub Activity_Create(FirstTime As Boolean)
    canvas1.Initialize(Activity)
    r=4
    g=128
    b=180
    globe
End Sub


Sub Globe
    Dim p As Path
    p.Initialize(0, 50%y)
    p.LineTo(100%x, 25%y)
    p.LineTo(100%x, 75%y)
     canvas1.ClipPath(p)
    canvas1.DrawColor(Colors.RGB(r, g, b))
    canvas1.RemoveClip
      Activity.Invalidate
End Sub
 

strat

Active Member
Licensed User
Longtime User
@Erel, thanks for reply.
I tried both using dip units and 2 size line but the result hasn't satisfied me. When I use dip unit variables, lines drawn out of screen, and when I use '2' size line, appearance of graphic doesn't look good.

This is what I'm trying to do.

If you compile the code, you will see at the the bottom of the screen, some lines disappear.

B4X:
Sub Process_Globals
   
End Sub

Sub Globals
   Dim Canvas1 As Canvas
   Dim i,r,g,b  As Int
End Sub

Sub Activity_Create(FirstTime As Boolean)
   canvas1.Initialize(Activity)
   r=4
   g=128
   b=180
   globe
End Sub


Sub Globe
 For i=1 To 59 
    Canvas1.DrawLine(i*8,0,479 ,i*8, Colors.RGB(r+i*4,g,b),1)
    Canvas1.DrawLine(479-i*8,479,0,479-i*8, Colors.RGB(r+i*4,g,b),1)
  Next
    Activity.Invalidate
End Sub
 
Top