```
#Region Project Attributes
#ApplicationLabel: B4A Example
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
End Sub
Sub Globals
Type PointXY(X As Int, Y As Int)
Dim PointList1 As List
Dim BC1 As BitmapCreator
Dim Button1 As Button
Dim PolyX1(1000) As Long
Dim PolyY1(1000) As Long
Dim PolyX2(1000) As Long
Dim PolyY2(1000) As Long
Dim PolyLen1 As Long
Dim PolyLen2 As Long
Dim PolyMap1 As Map
End Sub
Sub Activity_Create(FirstTime As Boolean)
Dim Duur0 As Long
Dim Duur1 As Long
Button1.Initialize("Button1")
Activity.AddView(Button1,10%x,10%y,80%x,80%y)
PointList1.Initialize
BC1.Initialize(Button1.Width, Button1.Height)
PolyMap1.Initialize
Dim BMP1 As B4XBitmap = Null
Duur0= DateTime.now
Duur1= DateTime.now
Drawline2(150,10,1000,1000,Colors.RGB(250,0,0),10)
Log("Line draw time= " & (DateTime.Now-Duur1) & " msec")
Duur1= DateTime.now
Drawline2(600,200,500,600,Colors.RGB(0,0,250),20)
Log("Line draw time= " & (DateTime.Now-Duur1) & " msec")
Duur1= DateTime.now
DrawCircleOpen(800,600,500,Colors.RGB(0,250,0),10)
Log("Circle Open time= " & (DateTime.Now-Duur1) & " msec")
Duur1= DateTime.now
DrawCircleFull(1280,600,300,Colors.RGB(0,250,250),10)
Log("Circle full time= " & (DateTime.Now-Duur1) & " msec")
PolyX1(0)=100
PolyY1(0)=100
PolyX1(1)=200
PolyY1(1)=200
PolyX1(2)=300
PolyY1(2)=150
PolyX1(3)=100
PolyY1(3)=400
PolyX1(4)=50
PolyY1(4)=200
PolyX1(5)=100
PolyY1(5)=100
PolyLen1=6
Duur1= DateTime.now
DrawPolyOpen(Colors.RGB(200,250,150),3)
Log("Poly Open time= " & (DateTime.Now-Duur1) & " msec")
PolyX1(0)=100
PolyY1(0)=700
PolyX1(1)=200
PolyY1(1)=900
PolyX1(2)=300
PolyY1(2)=850
PolyX1(3)=100
PolyY1(3)=1100
PolyX1(4)=50
PolyY1(4)=900
PolyX1(5)=100
PolyY1(5)=700
PolyLen1=6
Duur1= DateTime.now
DrawPolyFull(Colors.RGB(100,250,150),1)
Log("Poly full time= " & (DateTime.Now-Duur1) & " msec")
PolyX1(0)=40
PolyY1(0)=50
PolyX1(1)=80
PolyY1(1)=53
PolyX1(2)=82
PolyY1(2)=98
PolyX1(3)=36
PolyY1(3)=95
PolyX1(4)=40
PolyY1(4)=50
PolyLen1=5
Duur1= DateTime.now
For n=1 To 100
DrawPolyFull(Colors.RGB(180,180,180),1)
Next
Log("100 huisjes time= " & (DateTime.Now-Duur1) & " msec")
PolyX2(0)=700
PolyY2(0)=0
PolyX2(1)=800
PolyY2(1)=200
PolyX2(2)=1200
PolyY2(2)=150
PolyX2(3)=700
PolyY2(3)=600
PolyX2(4)=650
PolyY2(4)=200
PolyX2(5)=500
PolyY2(5)=100
PolyLen2=6
Duur1= DateTime.now
DrawRoad1(Colors.RGB(180,60,20),Colors.RGB(250,180,50),18, 10)
Log("Poly Road1 time= " & (DateTime.Now-Duur1) & " msec")
Duur1= DateTime.now
DrawTriangleOpen(330,550,450,800,180,700,Colors.RGB(200,200,20), 10)
Log("Poly Triangle time= " & (DateTime.Now-Duur1) & " msec")
Duur1= DateTime.now
DrawTriangleFull(530,650,650,920,420,990,Colors.RGB(250,250,60), 10)
Log("Poly Triangle time= " & (DateTime.Now-Duur1) & " msec")
Log("Total time1= " & (DateTime.Now-Duur0) & " msec")
BMP1= BC1.Bitmap
Button1.SetBackgroundImage(BMP1)
Log("Total time2= " & (DateTime.Now-Duur0) & " msec")
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub Drawline1(x1 As Int, y1 As Int, x2 As Int, y2 As Int, Color As Int) 'Faster for single lines (Wid=1)
Dim Dx,Dy,Diff As Int
Dim x,y As Float
Dim a As ARGBColor
BC1.ColorToARGB(Color, a)
Dx = x2 - x1
Dy = y2 - y1
Diff=Max(Abs(Dx),Abs(Dy))
x = x1
y = y1
Dim tx = Dx / Diff, ty = Dy / Diff As Float
For D=0 To Diff
If (x>=0 And x<BC1.mWidth) And (y>=0 And y<BC1.mHeight) Then BC1.SetARGB(x,y,a)
x = x + tx
y = y + ty
Next
End Sub
Sub Drawline2(x1 As Int, y1 As Int, x2 As Int, y2 As Int, Color As Int, Wid1 As Int)
Dim Dx,Dy,Diff As Int
Dim Rect1 As B4XRect
Dim x,y As Float
Dim a As ARGBColor
BC1.ColorToARGB(Color, a)
Dx = x2 - x1
Dy = y2 - y1
Diff=Max(Abs(Dx),Abs(Dy))
x = x1
y = y1
Dim Tx = Dx / Diff, Ty = Dy / Diff As Float
For D=0 To Diff
If (x>=0 And x<BC1.mWidth) And (y>=0 And y<BC1.mHeight) Then
Rect1.Initialize(x-Wid1/2,y-Wid1/2,x+Wid1/2,y+Wid1/2)
BC1.FillRect(Color,Rect1)
End If
x = x + Tx
y = y + Ty
Next
End Sub
Sub DrawCircleOpen(x As Int, y As Int, Radial As Int , Color As Int, Wid1 As Int)
Dim X1, Y1 As Double
Dim Rect1 As B4XRect
For i=0 To 720
X1 = X + Radial * CosD(i/2)
Y1 = Y + Radial * SinD(i/2)
Rect1.Initialize(X1-Wid1/2,Y1-Wid1/2,X1+Wid1/2,Y1+Wid1/2)
BC1.FillRect(Color,Rect1)
Next
End Sub
Sub DrawCircleFull(X As Int, Y As Int, Radial As Int , Color As Int, Wid1 As Int)
Dim Rect1 As B4XRect
Dim X1, Y1, X2, Y2, Hulp1 As Long
Dim XMin1, XMax1, YMin1, YMax1, Xwid1, Yhig1 As Long
XMin1=X-Radial
XMax1=Radial+X
YMin1=Y-Radial
YMax1=Radial+Y
Xwid1= XMax1-XMin1
Yhig1= YMax1-YMin1
Hulp1 =(Yhig1+1) * (Xwid1+1)
Dim Array1(Hulp1) As Int
For i=1 To 2160 Step 1
X1 = X + Radial * CosD(i/6)
Y1 = Y + Radial * SinD(i/6)
Array1((Y1-YMin1)*Yhig1 + (X1-XMin1)) = 1
Next
For Y=0 To Yhig1
For X=0 To Xwid1
If Array1(Y*Yhig1+X)=1 Then
X1=X + XMin1
Y1=Y + YMin1
Exit
End If
Next
For X=Xwid1 To 0 Step -1
If Array1(Y*Yhig1+X)=1 Then
X2= X + XMin1
Y2= Y + YMin1
Rect1.Initialize(X1,Y1,X2,Y2+1) 'Faster than using Drawline1(X1,Y,X,Y,Color)
BC1.FillRect(Color,Rect1)
Exit
End If
Next
Next
End Sub
Sub DrawRoad1(Color1 As Int, Color2 As Int, Wid1 As Int, Wid2 As Int)
Dim X1, Y1, X2, Y2 As Long
X1=PolyX2(0)
Y1=PolyY2(0)
If Wid1>0 Then
For i=1 To PolyLen2-1
X2=PolyX2(i)
Y2=PolyY2(i)
Drawline2(X1,Y1,X2,Y2,Color1,Wid1)
X1=X2
Y1=Y2
Next
End If
If Wid2>0 Then
X1=PolyX2(0)
Y1=PolyY2(0)
For i=1 To PolyLen2-1
X2=PolyX2(i)
Y2=PolyY2(i)
Drawline2(X1,Y1,X2,Y2,Color2,Wid2)
X1=X2
Y1=Y2
Next
End If
End Sub
Sub DrawPolyOpen(Color As Int, Wid1 As Int)
Dim X1, Y1, X2, Y2 As Long
X1=PolyX1(0)
Y1=PolyY1(0)
For i=1 To PolyLen1-1
X2=PolyX1(i)
Y2=PolyY1(i)
'Log("X2=" & X2 & ", Y2=" & Y2)
Drawline2(X1,Y1,X2,Y2,Color,Wid1)
X1=X2
Y1=Y2
Next
End Sub
Sub DrawPolyFull(Color As Int, Wid1 As Int)
Dim X0, X1, X2, Y0, Y1, Y2 As Long
Dim X, Y As Float
Dim XMin1, XMax1, YMin1, YMax1, Xwid1, Yhig1 As Long
Dim Hulp1 As Long
Dim SetPix1 As Int
Dim Rect1 As B4XRect
Dim Dx,Dy,Diff As Int
XMin1= PolyX1(0)
XMax1= PolyX1(0)
YMin1= PolyY1(0)
YMax1= PolyY1(0)
For i=0 To PolyLen1-1
X1=PolyX1(i)
Y1=PolyY1(i)
If X1<XMin1 Then XMin1 = X1
If X1>XMax1 Then XMax1 = X1
If Y1<YMin1 Then YMin1 = Y1
If Y1>YMax1 Then YMax1 = Y1
Next
Xwid1= XMax1-XMin1
Yhig1= YMax1-YMin1
Hulp1 =(Yhig1+1) * (Xwid1+1)
Dim Array1(Hulp1) As Int
X1=PolyX1(0)
Y1=PolyY1(0)
PolyMap1.Clear
For i=1 To PolyLen1-1
X2=PolyX1(i)
Y2=PolyY1(i)
'Log("X1= " & X1 & ", Y1= " & Y1 & ", X2= " & X2 & ", Y2= " & Y2)
Dx = X2 - X1
Dy = Y2 - Y1
Diff = Max(Abs(Dx),Abs(Dy))
X = X1
Y = Y1
Dim Tx = Dx / Diff, Ty = Dy / Diff As Float
For D=0 To Diff
X0=X
Y0=Y
Array1((Y0-YMin1)*Xwid1 + (X0-XMin1))=1
X = X + Tx
Y = Y + Ty
Next
X1=X2
Y1=Y2
Next
Y0=YMin1
Do While Y0<YMax1
SetPix1=0
X0=XMin1
Do While X0<XMax1
If Array1((Y0-YMin1)*Xwid1 + (X0-XMin1)) = 1 Then
'Log(SetPix1 & ": " & X0 & ", " & Y0)
If SetPix1=0 Then
X1=X0
SetPix1=1
Else
SetPix1=0
Rect1.Initialize(X1,Y0,X0,Y0+1) 'Hor.line: faster than with Drawline1(X1,Y,X,Y,Color)
BC1.FillRect(Color,Rect1)
End If
X0=X0+1
End If
X0=X0+1
Loop
Y0=Y0+1
Loop
End Sub
Sub DrawTriangleOpen(X1 As Int, Y1 As Int, X2 As Int, Y2 As Int, X3 As Int, Y3 As Int, Color As Int, Wid1 As Int)
PolyX1(0)=X1
PolyY1(0)=Y1
PolyX1(1)=X2
PolyY1(1)=Y2
PolyX1(2)=X3
PolyY1(2)=Y3
PolyX1(3)=X1
PolyY1(3)=Y1
PolyLen1=4
DrawPolyOpen(Color,Wid1)
End Sub
Sub DrawTriangleFull(X1 As Int, Y1 As Int, X2 As Int, Y2 As Int, X3 As Int, Y3 As Int, Color As Int, Wid1 As Int)
PolyX1(0)=X1
PolyY1(0)=Y1
PolyX1(1)=X2
PolyY1(1)=Y2
PolyX1(2)=X3
PolyY1(2)=Y3
PolyX1(3)=X1
PolyY1(3)=Y1
PolyLen1=4
DrawPolyFull(Color,Wid1)
End Sub
```