Build1=Default,b4a.bitmapdrawer2 File1=bitmapdrawer.bal FileGroup1=Default Group Group=Default Group Library1=core Library2=bitmapcreator Library3=xui Library4=xui2d Library5=javaobject Library6=gps Library7=runtimepermissions ManifestCode='This code will be applied to the manifest file during compilation.~\n~'You do not need to modify it in most cases.~\n~'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136~\n~AddManifestText(~\n~~\n~)~\n~SetApplicationAttribute(android:icon, "@drawable/icon")~\n~SetApplicationAttribute(android:label, "$LABEL$")~\n~CreateResourceFromFile(Macro, Themes.DarkTheme)~\n~'End of default text.~\n~ Module1=|relative|..\sideextra Module2=Starter NumberOfFiles=1 NumberOfLibraries=7 NumberOfModules=2 Version=9.9 @EndOfDesignText@ #Region Project Attributes #ApplicationLabel: b4amod #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 'todo 'set location start to center of bc 'turn on dads bc rotation bmc2 'current position in x,y=origin(x,y)+delta(x,y) times (current lat long - origin lat long 'increae bc size 'fire iteration on location changed, not on 1000ms timer 'breaking code up into seperate files"b4a break ''wait for could be removed in its entirety and program should still be good Sub Process_globals End Sub Sub Globals Type coordX (y As Float,x As Float) Type coordxx (lat As Float,lng As Float) Private mapsize As coordX 'Private fx As JFX 'Private MainForm As Form Private xui As XUI Private timerx As Int Private rectanglewholeb4x As B4XRect Private pnlGraph As Panel Private cvsGraph As B4XCanvas Private imvGraph As ImageView Private pthGraph As BCPath Private bmcGraph As BitmapCreator Private bmc2ndgraph As BitmapCreator Private PointX(6), PointY(6) As Double ' Private BtnClear As B4XView ' Private BtnDraw As B4XView ' Private BtnFast As B4XView ' Private BtnStop As B4XView ' Private BtnSlow As B4XView ' Private BtnLeft As B4XView ' Private BtnRight As B4XView Private timeriterate As Timer Private xpos, ypos, xposnew, yposnew As Float Private xposleft, yposleft, xposright, yposright, widthsection As Float Private velocity, heading, headingrate As Float ' Private BtnActivateTimerTick As B4XView '///// Private tractor1 As coordX 'location of tractor Private trailer1 As coordX 'location of center of trailer Private tractor0 As coordX 'location of tractor Private trailer0 As coordX 'location of center of trailer Private hitch1 As coordX 'location of tractor hitch Private Offset_hitch As Float Private offset_trailertoboom As Float Private offset_trailerlength As Float Private boomsectionwidth(4) As Float 'center is 1 Private vector1 As coordX Private vectorlength1 As Float Private boompoint0 As coordX Private boompoint00 As coordX Private boompoint01 As coordX 'leading point Private boompoint1 As coordX Private boompoint10 As coordX Private boompoint11 As coordX Private boompoint2 As coordX Private boompoint20 As coordX Private boompoint21 As coordX Private boompoint3 As coordX Private boompoint30 As coordX Private boompoint31 As coordX Private boompoint4 As coordX Private boompoint40 As coordX Private boompoint41 As coordX Private boompoint5 As coordX Private boompoint50 As coordX Private boompoint51 As coordX 'leading point Private boomcenter1 As coordX Private unitvector1 As coordX Private boomcolor(5) As Int ' Private boom1color As Int ' Private boom2color As Int ' Private boom3color As Int ' Private boom4color As Int Public x1 As Int Public x2 As Int Public y1 As Int Public y2 As Int Public P1 As coordX Public P2 As coordX Public P3 As coordX Public P4 As coordX Public a0 As coordX Public a1 As coordX Public b0 As coordX Public b1 As coordX Public rectanglewhole As Rect Public canvas1 As Canvas Private rp As RuntimePermissions Dim displayoutlines As Boolean Dim displayfill As Boolean 'Public boomcolour As String Public boomon As Boolean Private Panel1 As B4XView Type coord (lat As Long,lng As Long) ' Private location1 As Location Public origin As coordxx Private deltalat As Float Private deltalong As Float Private xposorigin As Int Private yposorigin As Int Private b4arect1 As B4XRect Private section1colour As Panel Private section2colour As Panel Private section3colour As Panel Private section4colour As Panel Private section5colour As Panel End Sub Sub activity_create (FirstTime As Boolean)'(Form1 As Form, Args() As String) 'MainForm = Form1 'MainForm.RootPane.LoadLayout("Main") 'Load the layout file. 'MainForm.Show Activity.LoadLayout("bitmapdrawer.bal") 'timeriterate.Initialize("IterateTimer",1000) 'timeriterate.Enabled = True b4arect1.Initialize(0,0,imvGraph.Width,imvGraph.Height) mapsize.Initialize mapsize.x=1200 mapsize.y=1200 xposorigin=mapsize.x/2 yposorigin=mapsize.y/2 xpos = xposorigin ypos = yposorigin unitvector1.Initialize Offset_hitch = 0 offset_trailerlength = 1 offset_trailertoboom = 1 boomsectionwidth(1) = 8 boomsectionwidth(2) = 8 boomsectionwidth(3) = 8 rp.CheckAndRequest(rp.PERMISSION_ACCESS_FINE_LOCATION) a0.Initialize a1.Initialize b0.Initialize b1.Initialize trailer0.x=xpos trailer0.y=ypos-Offset_hitch-offset_trailerlength velocity = 10 heading = 180 ' bmcGraph..b boompoint50.Initialize boompoint5.Initialize boompoint0.Initialize boompoint00.Initialize boompoint51.Initialize boompoint01.Initialize boompoint1.Initialize boompoint10.Initialize boompoint11.Initialize boompoint2.Initialize boompoint20.Initialize boompoint21.Initialize boompoint3.Initialize boompoint30.Initialize boompoint31.Initialize boompoint4.Initialize boompoint40.Initialize boompoint41.Initialize boompoint00.x=0 boompoint50.x=0 boompoint10.x=0 boompoint20.x=0 boompoint30.x=0 boompoint40.x=0 headingrate = 0 widthsection = 100 cvsGraph.Initialize(imvGraph) boomon=True boomcolor(0)=xui.Color_Green boomcolor(1)=xui.Color_Green boomcolor(2)=xui.Color_Green boomcolor(3)=xui.Color_Green boomcolor(4)=xui.Color_Green Initialize(1) 'location_center Do While Starter.ValidGPS = False Sleep (100) Loop ''Log("a") location_center End Sub Sub LocationChanged(Location1 As Location)'IterateTimer_Tick If Starter.Location2.BearingValid = True Then heading=Starter.Location2.Bearing End If 'Log("b") 'heading = heading + headingrate ' If heading < 0 Then ' heading = heading + 360 'Else If heading >360 Then ' heading = heading - 360 'End If timerx=DateTime.now 'Log("deltalong"&deltalong) xposnew=xposorigin+deltalong*(Starter.Location2.Longitude-origin.lng)/2 yposnew=yposorigin+deltalat*(Starter.Location2.latitude-origin.lat)/2 'xposnew = xpos + velocity * SinD(heading) 'yposnew = ypos - velocity * CosD(heading) Log("xposnew: " & NumberFormat(xposnew,0,0) & " yposnew: " & NumberFormat(yposnew,0,0) & " heading: " & NumberFormat(heading,0,0)) 'bmcGraph.DrawLine(xpos,ypos,xposnew,yposnew,xui.Color_Black,10) ' xposright = xposnew + widthsection*CosD(heading)/2 ' yposright = yposnew + widthsection*SinD(heading)/2 ' xposleft = xposnew - widthsection*CosD(heading)/2 ' yposleft = yposnew - widthsection*SinD(heading)/2 bmcGraph.DrawCircle(xposnew,yposnew,4,xui.Color_red,True,1) 'hiden by jack bmcGraph.DrawLine(xposleft,yposleft,xposright,yposright,xui.Color_Blue,4) '/////// 'convert all tractor positions to cartesian on our map tractor0.x=xpos tractor0.y=ypos tractor1.x=xposnew tractor1.y=yposnew 'find hitch position of tractor(1) hitch1.x=tractor1.x-Offset_hitch*CosD(heading+90) hitch1.y=tractor1.y-Offset_hitch*SinD(heading+90) 'Log(hitch1.x) 'Log(hitch1.y) vector1.x = hitch1.x-trailer0.x vector1.y = hitch1.y-trailer0.y vectorlength1=Power(Power(vector1.x,2)+Power(vector1.y,2),.5) unitvector1.x=vector1.x/vectorlength1 unitvector1.y=vector1.y/vectorlength1 trailer1.x=hitch1.x-vector1.x*offset_trailerlength/vectorlength1 trailer1.y=hitch1.y-vector1.y*offset_trailerlength/vectorlength1 boomcenter1.x=-unitvector1.x*offset_trailertoboom+trailer1.x boomcenter1.y=-unitvector1.y*offset_trailertoboom+trailer1.y 'perpvect.x=vec.y 'perpvect.y=-vec.x ' Log("new1"&boompoint0) ' Log("old1"&boompoint00) boompoint0.x=-(boomsectionwidth(1)/2+boomsectionwidth(2)+boomsectionwidth(3))*unitvector1.y+boomcenter1.x boompoint0.y=-(boomsectionwidth(1)/2+boomsectionwidth(2)+boomsectionwidth(3))*-unitvector1.x+boomcenter1.y boompoint01.x=boompoint0.x+ boompoint0.x-boompoint00.x boompoint01.y=boompoint0.y+ boompoint0.y-boompoint00.y boompoint1.x=-(boomsectionwidth(1)/2+boomsectionwidth(2))*unitvector1.y+boomcenter1.x boompoint1.y=-(boomsectionwidth(1)/2+boomsectionwidth(2))*-unitvector1.x+boomcenter1.y boompoint11.x=boompoint1.x+ boompoint1.x-boompoint10.x boompoint11.y=boompoint1.y+ boompoint1.y-boompoint10.y boompoint2.x=-(boomsectionwidth(1)/2)*unitvector1.y+boomcenter1.x boompoint2.y=-(boomsectionwidth(1)/2)*-unitvector1.x+boomcenter1.y boompoint21.x=boompoint2.x+ boompoint2.x-boompoint20.x boompoint21.y=boompoint2.y+ boompoint2.y-boompoint20.y boompoint3.x=(boomsectionwidth(1)/2)*unitvector1.y+boomcenter1.x boompoint3.y=(boomsectionwidth(1)/2)*-unitvector1.x+boomcenter1.y boompoint31.x=boompoint3.x+ boompoint3.x-boompoint30.x boompoint31.y=boompoint3.y+ boompoint3.y-boompoint30.y boompoint4.x=(boomsectionwidth(1)/2+boomsectionwidth(2))*unitvector1.y+boomcenter1.x boompoint4.y=(boomsectionwidth(1)/2+boomsectionwidth(2))*-unitvector1.x+boomcenter1.y boompoint41.x=boompoint4.x+ boompoint4.x-boompoint40.x boompoint41.y=boompoint4.y+ boompoint4.y-boompoint40.y boompoint5.x=(boomsectionwidth(1)/2+boomsectionwidth(2)+boomsectionwidth(3))*unitvector1.y+boomcenter1.x boompoint5.y=(boomsectionwidth(1)/2+boomsectionwidth(2)+boomsectionwidth(3))*-unitvector1.x+boomcenter1.y boompoint51.x=boompoint5.x+ boompoint5.x-boompoint50.x boompoint51.y=boompoint5.y+ boompoint5.y-boompoint50.y 'boompoint51.x=boompoint5.x+ (boompoint0.x-boompoint00.x+boompoint5.x-boompoint50.x)/2 'boompoint51.y=boompoint5.y+ (boompoint0.y-boompoint00.y+boompoint5.y-boompoint50.y)/2 'boompoint01.x=boompoint0.x+ (boompoint0.x-boompoint00.x+boompoint5.x-boompoint50.x)/2 'boompoint01.y=boompoint0.y+ (boompoint0.y-boompoint00.y+boompoint5.y-boompoint50.y)/2 bmcGraph.DrawLine(boompoint0.x,boompoint0.y,boompoint1.x,boompoint1.y,xui.Color_Gray,1) bmcGraph.DrawLine(boompoint1.x,boompoint1.y,boompoint2.x,boompoint2.y,xui.Color_Cyan,1) bmcGraph.DrawLine(boompoint2.x,boompoint2.y,boompoint3.x,boompoint3.y,xui.Color_Green,1) bmcGraph.DrawLine(boompoint3.x,boompoint3.y,boompoint4.x,boompoint4.y,xui.Color_Magenta,1) bmcGraph.DrawLine(boompoint4.x,boompoint4.y,boompoint5.x,boompoint5.y,xui.Color_Black,1) ''Log(bmcGraph.GetColor(1,1))'(boompoint0.x+boompoint01.x+boompoint5.x+boompoint51.x)/4,(boompoint0.y+boompoint01.y+boompoint5.y+boompoint51.y)/4)) bmcGraph.DrawCircle(hitch1.x,hitch1.y,2,xui.Color_black,True,1) trailer0.x=trailer1.x trailer0.y=trailer1.y If boompoint00.x <>0 Then 'Log("boomon"&boomon) 'If boomon=True Then ' Wait For(rectanglefiller(boompoint0, boompoint00, boompoint10, boompoint1,0)) complete '(result As Int) ' Wait For(rectanglefiller(boompoint1, boompoint10, boompoint20, boompoint2,1)) complete '(result As Int) ' Wait For(rectanglefiller(boompoint2, boompoint20, boompoint30, boompoint3,2)) complete '(result As Int) ' Wait For(rectanglefiller(boompoint3, boompoint30, boompoint40, boompoint4,3)) complete '(result As Int) ' Wait For(rectanglefiller(boompoint4, boompoint40, boompoint50, boompoint5,4)) complete '(result As Int) ' End If ' Wait For(rectanglechecker(boompoint01, boompoint0,boompoint1,boompoint11,0)) complete ' Wait For(rectanglechecker(boompoint11, boompoint1,boompoint2,boompoint21,1)) complete ' Wait For(rectanglechecker(boompoint21, boompoint2,boompoint3,boompoint31,2)) complete ' Wait For(rectanglechecker(boompoint31, boompoint3,boompoint4,boompoint41,3)) complete ' Wait For(rectanglechecker(boompoint41, boompoint4,boompoint5,boompoint51,4)) complete Wait For (lineintersect(boompoint00,boompoint0,boompoint01,boompoint10,boompoint1,boompoint11,0)) complete Wait For (lineintersect(boompoint10,boompoint1,boompoint11,boompoint20,boompoint2,boompoint21,1)) complete Wait For (lineintersect(boompoint20,boompoint2,boompoint21,boompoint30,boompoint3,boompoint31,2)) complete Wait For (lineintersect(boompoint30,boompoint3,boompoint31,boompoint40,boompoint4,boompoint41,3)) complete Wait For (lineintersect(boompoint40,boompoint4,boompoint41,boompoint50,boompoint5,boompoint51,4)) complete timerx=DateTime.Now-timerx Log("timerx"&timerx) bmcGraph.DrawLine(boompoint01.x,boompoint01.y,boompoint51.x,boompoint51.y,xui.Color_red,1) bmcGraph.DrawLine(boompoint01.x,boompoint01.y,boompoint0.x,boompoint0.y,xui.Color_magenta,1) 'bmcGraph.DrawLine(boompoint0.x,boompoint0.y,boompoint5.x,boompoint5.y,xui.Color_red,1)'shows up too much on trail bmcGraph.DrawLine(boompoint51.x,boompoint51.y,boompoint5.x,boompoint5.y,xui.Color_blue,1) '(boompoint0, boompoint00, boompoint50, boompoint5)) '(boompoint0.x,boompoint0.y, boompoint00.x,boompoint00.y, boompoint50.x,boompoint50.y, boompoint5.x,boompoint5.y)) End If boompoint00.x=boompoint0.x'custom type issue, equating one boompoint to another just refers rather than copying over, this is in reference to primitive and nonprimitive variables boompoint00.y=boompoint0.y boompoint10.x=boompoint1.x boompoint10.y=boompoint1.y boompoint20.x=boompoint2.x boompoint20.y=boompoint2.y boompoint30.x=boompoint3.x boompoint30.y=boompoint3.y boompoint40.x=boompoint4.x boompoint40.y=boompoint4.y boompoint50.x=boompoint5.x boompoint50.y=boompoint5.y 'rectanglefiller(boompoint0.x)', boompoint00, boompoint50, boompoint5) '/////// Jacks transform bitmapcreator 'Sleep(2000) Dim r As B4XRect r.Initialize(xposnew-400,yposnew-400,xposnew+400,yposnew+400)'defines the square that is observed and copied from bc bmc2ndgraph.Initialize(imvGraph.Width, imvGraph.Height) Dim dt As DrawTask = bmcGraph.CreateDrawTask(bmcGraph,r,imvGraph.Width/2,imvGraph.Height/2,True) dt.SrcScaleX=4 dt.SrcScaleY=4 dt.Degrees=-Starter.Location2.Bearing 'Log("bearing"&Starter.Location2.Bearing) ''Log("bmc"&bmcGraph.mHeight) ''Log("imvgraph.width"&imvGraph.Width) bmc2ndgraph.DrawBitmapCreatorTransformed(dt) cvsGraph.DrawBitmap(bmc2ndgraph.Bitmap,b4arect1) imvGraph.Invalidate section1colour.Color=boomcolor(0) section2colour.Color=boomcolor(1) section3colour.Color=boomcolor(2) section4colour.Color=boomcolor(3) section5colour.Color=boomcolor(4) '/// 'Dim r As B4XRect 'r.Initialize(450,450, 550,550)'xposnew+bmcGraph.mWidth/20,yposnew+bmcGraph.mHeight/20) 'Dim dt As DrawTask = bmcGraph.CreateDrawTask(bmcGraph, r, 100, 100, True) '(50, 50) defines the target center 'dt.SrcScaleX = .5 'dt.SrcScaleY = .5 'Log(bmcGraph.mWidth) 'dt.Degrees = -heading ' dt.TargetX=200 ' dt.TargetY=200 ' dt.SkipBlending=True ' dt.Source=bmcGraph ' dt.SrcRect=r ' bmcGraph.DrawCircle(100,100,30,Colors.Black,True,1) ' bmcGraph.DrawLine(3,3,100,100,xui.Color_red,3) 'bmcGraph.DrawBitmapCreatorTransformed(dt) ' imvGraph.SetBitmap(bmcGraph.Bitmap) ' bmc2ndgraph.Initialize(pnlGraph.Width, pnlGraph.Height) 'need to clear bmc2ndgraph above before writing a clean image onto it. Otherwise DrawBitmapCreatorTransformed(dt) just draws over the top ' bmc2ndgraph.DrawBitmapCreatorTransformed(dt) ' canv.DrawBitmap(bc.Bitmap,Null,b4arect) 'imvGraph.SetBitmap(bmcGraph.Bitmap) ' cvsGraph.DrawBitmap(bmcGraph.Bitmap,rectanglewholeb4x) ' imvGraph.Invalidate 'imvGraph.Bitmap=(bmc2ndgraph.Bitmap) ', xposright, yposright, width ''Log("color"&bmcGraph.GetColor(100,100)) 'r.Initialize(0, 0, bmcGraph.mWidth, bmcGraph.mHeight) 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 'ABOVE WORKS, BELOW DOSEN'T. i THINK IT IS BEACUSE RECTANGLE CAN'T HAVE NEGATIVE COORDS 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 'FIXED BY ENLARGING MAIN BC AND STARTING IN MIDDLE. cRASHES WHEN AN ATTEMPT IS MADE TO DRAW OUTSIDE THIS BC. 'NEED TO CHECK THAT HEADING IS CORRECT. 'ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZXXXXXXXXXXXXXXXXXXCCCCCCCCCCCCCCCCCCVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV xpos = xposnew ypos = yposnew End Sub Sub BtnFast_Click velocity = velocity + 1 End Sub Sub BtnStop_Click velocity = 0 End Sub Sub BtnSlow_Click velocity = velocity - 1 End Sub Sub BtnLeft_Click headingrate = headingrate -1 End Sub Sub BtnRight_Click headingrate = headingrate +1 End Sub Sub BtnClear_Click 'timeriterate.Enabled = False 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX bmcGraph.Initialize(pnlGraph.Width*10, pnlGraph.Height*10) imvGraph.Bitmap=(bmcGraph.Bitmap) 'timeriterate.Enabled = True End Sub 'Sub BtnActivateTimerTick_Click 'timeriterate.Enabled = True 'IterateTimer_Tick 'End Sub Sub BtnDraw_Click Dim intcolour As Int For i=0 To pnlGraph.Width-1 For j=0 To pnlGraph.Height-1 intcolour = bmcGraph.GetColor(i,j) 'don't know why white is showing up as =0 in this test. Testing for color white doesn't work If bmcGraph.GetColor(i,j) <> 0 Then 'fx.Colors.To32Bit(fx.Colors.White) and xui.Color_White don't work 'bmcGraph.SetColor(i,j,fx.Colors.To32Bit(fx.Colors.Green)) End If Next Next bmcGraph.DrawLine(0,0,pnlGraph.Width, 0,xui.Color_Magenta,100) Dim r As B4XRect 'r.Initialize(0, 0, bmcGraph.mWidth, bmcGraph.mHeight) r.Initialize(bmcGraph.mWidth/4, bmcGraph.mHeight/4, bmcGraph.mWidth*0.75, bmcGraph.mHeight*0.75) Dim dt As DrawTask = bmcGraph.CreateDrawTask(bmcGraph, r, pnlGraph.Width/2, pnlGraph.Height/2, True) '(50, 50) defines the target center dt.SrcScaleX = 1 dt.SrcScaleY = 1 dt.Degrees = 15 ' bmcGraph.DrawBitmapCreatorTransformed(dt) ' imvGraph.SetBitmap(bmcGraph.Bitmap) bmc2ndgraph.DrawBitmapCreatorTransformed(dt) imvGraph.Bitmap=(bmc2ndgraph.Bitmap) 'the inclusion of the following line results in unexpected behaviour 'bmcGraph = bmc2ndgraph End Sub 'points must be in order Sub rectanglechecker(point1 As coordX, point2 As coordX, point3 As coordX, point4 As coordX, k As Int)As ResumableSub Dim RC_ACWmap As Map Dim RC_CWmap As Map Dim RC_line1xvalues As List Dim RC_line2xvalues As List Dim RC_line2yvalues As List Dim RC_line1yvalues As List 'Dim boomcolor As Int RC_ACWmap.Initialize 'used to progress clockwise and anticlockwise around rectangle RC_ACWmap.Put(point1,point2) RC_ACWmap.Put(point2,point3) RC_ACWmap.Put(point4,point1) RC_ACWmap.Put(point3,point4) RC_CWmap.Initialize RC_CWmap.Put(point1,point4) RC_CWmap.Put(point2,point1) RC_CWmap.Put(point4,point3) RC_CWmap.Put(point3,point2) RC_line1xvalues.Initialize RC_line2xvalues.Initialize RC_line1yvalues.initialize RC_line2yvalues.Initialize Dim pmax As coordX Dim pmin As coordX Dim temp As coordX Dim Pmap As Map 'lets us grab the maxY and minY after finding the min and max value Pmap.Initialize Pmap.Put(point1.y,point1) Pmap.Put(point2.y,point2) Pmap.Put(point4.y,point4) Pmap.Put(point3.y,point3) pmax.Initialize pmin.Initialize Dim temp3 As Float temp3 = Max(point1.y,Max(point2.y,Max(point4.y,point3.y))) Dim temp4 As Float temp4 = Min(point1.y,Min(point2.y,Min(point4.y,point3.y))) pmax=Pmap.Get(temp3) 'temp variable required, otherwise pmax is null pmin=Pmap.Get(temp4) Dim temp2 As coordX temp = pmax RC_line1xvalues.add(pmax.x)'initial point to both line lists RC_line1yvalues.add(pmax.y) RC_line2xvalues.add(pmax.x) RC_line2yvalues.add(pmax.y) Do While temp <> pmin 'cwloop temp2=RC_CWmap.Get(temp)'gets second point for line Wait For(calcline(temp.x,temp.y, temp2.x,temp2.y,RC_line1xvalues,RC_line1yvalues)) complete 'RC_line2xvalues generated temp = RC_CWmap.Get(temp) 'changes the first line point to the second Loop temp = pmax Do While temp <> pmin 'acwloop temp2=RC_ACWmap.Get(temp)'gets second point for line wait for (calcline(temp.x,temp.y, temp2.x,temp2.y,RC_line2xvalues,RC_line2yvalues)) complete 'RC_line2xvalues generated temp = RC_ACWmap.Get(temp) 'changes the first line point to the second Loop RC_line1xvalues.add(pmin.x)'adds final point to both line lists RC_line1yvalues.add(pmin.y) RC_line2xvalues.add(pmin.x) RC_line2yvalues.add(pmin.y) Dim ytemp As Int Dim pixelchecked As Int pixelchecked=0 'Dim loop1cycles As Int ' loop1cycles=0 ' Dim loop2onetake2 As Double ' loop2onetake2=0 ' bmcGraph.DrawLine(line1xvalues.Get(i),ytemp,line2xvalues.get(i),ytemp,boomcolour,1) ' ytemp=ytemp-1 ytemp=pmax.y 'could choose to save both x and y values to RC_line1xvalues rather than just x. For i=0 To (Min(RC_line1xvalues.Size,RC_line2xvalues.Size)-1) 'iterates from top point to bottom of polygone, drawing a level line from left to right For j=RC_line2xvalues.Get(i) To RC_line1xvalues.Get(i) Step 1'issue solved, was counting from a higher number to a lower number rather than lower to higher 'Log("j="&j) pixelchecked=pixelchecked+1 ' loop2onetake2=loop2onetake2+RC_line1xvalues.Get(i)-RC_line2xvalues.Get(i) ' Log("1 "&RC_line1xvalues.Get(i)) ' Log("2 "&RC_line2xvalues.Get(i)) ' Log("ytemp"&ytemp) ' Log("color"&bmcGraph.GetColor(j,ytemp)) 'bmcGraph.DrawCircle(RC_line1xvalues.Get(i),ytemp,6,-16711936,False,2)'-7829368 is gray If bmcGraph.GetColor(j,ytemp)=-1 Then boomon=True boomcolor(k)=xui.Color_Green Log("pixelchecked"&pixelchecked) ' Log("loop2"&loop2onetake2) ' Log("boomon"&boomon) Return boomcolor(k) End If ' bmcGraph.setColor(j,ytemp,xui.Color_Yellow) Next ' loop1cycles=loop1cycles+1 'bmcGraph.DrawLine(RC_line1xvalues.Get(i),ytemp,RC_line2xvalues.get(i),ytemp,xui.Color_green,1) ytemp=ytemp-1 Next Log("pixelchecked"&pixelchecked) boomcolor(k)=xui.Color_yellow 'Log("line1size"&RC_line1xvalues.size) ' Log("line2size"&RC_line2xvalues.size) ' Log("loop1cycles"&loop1cycles) ' Log("loop2 "&loop2onetake2) boomon=False Log("boomon"&boomon) ' Log("pauselinefalse") Return boomcolor(k) End Sub 'Return true to allow the default exceptions handler to handle the uncaught exception. Sub Application_Error (Error As Exception, StackTrace As String) As Boolean Return True End Sub Private Sub Initialize(Index As Int) 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX bmcGraph.Initialize(1000,1000) 'the following line 'bmc2ndgraph.Initialize(pnlGraph.Width/2, pnlGraph.Height/2) ' results in the following commands enlarging the bmc2ndgraph to fit 'bmc2ndgraph.DrawBitmapCreatorTransformed(dt) 'imvGraph.SetBitmap(bmc2ndgraph.Bitmap) bmc2ndgraph.Initialize(mapsize.x, mapsize.y) rectanglewhole.Initialize(0,0,mapsize.x,mapsize.y) rectanglewholeb4x.Initialize(0,0,1000,1000) bmcGraph.DrawRect(rectanglewholeb4x,xui.Color_white,True,1) bmcGraph.DrawLine(5,900,900,5,xui.Color_green,60) bmcGraph.DrawLine(5,300,300,5,xui.Color_green,40) 'cvsGraph.DrawBitmap(bmcGraph.bitmap,rectanglewholeb4x) 'imvGraph.Invalidate End Sub 'points must be in order Sub rectanglefiller(point1 As coordX, point2 As coordX, point3 As coordX, point4 As coordX,k As Int)As ResumableSub 'find pmax, find pmin 'construct line clockwise from pmax to pmin 'construct line anticlockwise from pmax to pmin 'pull list of x values and draw canvas line between all Dim timer As Long timer=DateTime.Now ' point1.x=boompoint00.x ' point1.y=boompoint00.y ' point2.x=boompoint0.x ' point2.y=boompoint0.y ' point4.x=boompoint50.x ' point4.y=boompoint50.y ' point3.x=boompoint5.x ' point3.y=boompoint5.y Dim line1xvalues As List Dim line2xvalues As List Dim line1yvalues As List Dim line2yvalues As List Dim CWmap As Map Dim ACWmap As Map ACWmap.Initialize 'used to progress clockwise and anticlockwise around rectangle ACWmap.Put(point1,point2) ACWmap.Put(point2,point3) ACWmap.Put(point4,point1) ACWmap.Put(point3,point4) CWmap.Initialize CWmap.Put(point1,point4) CWmap.Put(point2,point1) CWmap.Put(point4,point3) CWmap.Put(point3,point2) line1xvalues.Initialize line2xvalues.Initialize line1yvalues.initialize line2yvalues.Initialize Dim pmax As coordX Dim pmin As coordX Dim temp As coordX Dim Pmap As Map 'lets us grab the maxY and minY after finding the min and max value Pmap.Initialize Pmap.Put(point1.y,point1) Pmap.Put(point2.y,point2) Pmap.Put(point4.y,point4) Pmap.Put(point3.y,point3) '// 'line1:y1=g1x1+h2 'line2:y2=g2x2+h2 'Dim g0 As Float 'Dim g1 As Float 'Dim h0 As Float 'Dim h1 As Float 'Dim Inter As floatcoord 'If point1.x = point4.x Then 'line is verticle, ie;x=2 ' 'find line2(x=2) which is intercect point 'End If 'If point2.x = point3.x Then 'line2 is verticle' ' 'find line2(x=2) which is intercect point 'End If 'g0=(point1.y-point4.y)/(point1.x-point4.x) 'g1=(point2.y-point3.y)/(point2.x-point3.x) 'h0=point1.y-point1.x*(point1.y-point4.y)/(point1.x-point4.x) 'h1=point2.y-point2.x*(point2.y-point3.y)/(point2.x-point3.x) 'Inter.x=(h1-h0)/(g1-g0) 'Inter.y=g0*Inter.x+h0 '// vector form '// 'pmax=Max(point1.y,Max(point2.y,Max(point4.y,point3.y))) 'pmin=Min(point1.y,Min(point2.y,Min(point4.y,point3.y))) pmax.Initialize pmin.Initialize ' Log(Max(point1.y,Max(point2.y,Max(point4.y,point3.y)))) Dim temp3 As Float temp3 = Max(point1.y,Max(point2.y,Max(point4.y,point3.y))) Dim temp4 As Float temp4 = Min(point1.y,Min(point2.y,Min(point4.y,point3.y))) ' Log(Pmap.Get(temp3)) pmax=Pmap.Get(temp3) 'temp variable required, otherwise pmax is null pmin=Pmap.Get(temp4) Dim temp2 As coordX temp = pmax line1xvalues.add(pmax.x)'initial point to both line lists line1yvalues.add(pmax.y) line2xvalues.add(pmax.x) line2yvalues.add(pmax.y) Do While temp <> pmin 'cwloop temp2=CWmap.Get(temp)'gets second point for line Wait For(calcline(temp.x,temp.y, temp2.x,temp2.y,line1xvalues,line1yvalues)) complete 'line2xvalues generated temp = CWmap.Get(temp) 'changes the first line point to the second 'Log("line1") Loop temp = pmax Do While temp <> pmin 'acwloop temp2=ACWmap.Get(temp)'gets second point for line wait for (calcline(temp.x,temp.y, temp2.x,temp2.y,line2xvalues,line2yvalues)) complete 'line2xvalues generated temp = ACWmap.Get(temp) 'changes the first line point to the second 'Log("line2") Loop line1xvalues.add(pmin.x)'final point to both line lists line1yvalues.add(pmin.y) line2xvalues.add(pmin.x) line2yvalues.add(pmin.y) Dim ytemp As Int 'bitmap1.InitializeMutable(40dip,40dip) 'canvas1.Initialize2(bitmap1) ytemp=pmax.y 'could choose to save both x and y values to line1xvalues rather than just x. For i=0 To Min(line1xvalues.Size,line2xvalues.Size)-1 bmcGraph.DrawLine(line1xvalues.Get(i),ytemp,line2xvalues.get(i),ytemp,boomcolor(k),1) ytemp=ytemp-1 ' Log(line1xvalues.size) ' Log(xposnew) ' Log(yposnew) ' Log(heading) ' Log(point1) ' Log(point2) ' Log(point4) ' Log(point3) ' bitmap2.Initializemutable(1000dip,1000dip) ' bitmap2=bitmap1.Resize(1000,1000,False) 'Label1.SetBackgroundImage(bitmap1) ' ImageView1.Color=(Colors.White) ' ImageView1.Bitmap = bitmap2 Next 'End If ' timer=DateTime.Now-timer ' Log("timer") ' Log(timer) ' bitmap2.Initializemutable(1000dip,1000dip) ' bitmap2=bitmap1.Resize(1000,1000,False) 'Label1.SetBackgroundImage(bitmap1) ' ImageView1.Color=(Colors.White) ' ImageView1.Bitmap = bitmap2 ' Log($"line1size ${line1yvalues.size}"$) ' Log($"line2size ${line2yvalues.size}"$) Return 2 End Sub Sub calcline (tx1 As Int,ty1 As Int,tx2 As Int, ty2 As Int, linenumber As List, lineynumber As List) As ResumableSub 'initialy a duplicate of bresenham Dim x As Int = tx1 Dim y As Int = ty1 Dim dx As Int = Abs(tx2 - tx1) Dim dy As Int = Abs(ty2 - ty1) Dim signx As Int = (tx2-tx1)/dx Dim signy As Int = (ty2-ty1)/dy Dim changed As Boolean = False If (dy>=dx) Then Dim dy As Int = Abs(tx2 - tx1) 'swap Dim dx As Int = Abs(ty2 - ty1) changed = True ' Log(changed) Else ' Log(changed) End If Dim e As Float = (2*dy)-dx For i=1 To dx 'canvas1.DrawPoint((x),(y),Colors.Black) If lineynumber.Get(lineynumber.size-1)<>y Then linenumber.add(x) lineynumber.add(y) End If Do While e>=0 If changed=True Then ' If signx<0 Then x=x+signx 'Else ' x=x+1 'End If Else ' If signy<0 Then y=y+signy ' Else ' y=y+1 ' End If End If e=e-2*dx Loop If changed=True Then y =y+signy Else x =x+signx End If e=e+(2*dy) Next ' canvas1.DrawPoint(x2,y2,Colors.Black) ' linenumber.Add(tx2) ' lineynumber.add(ty2) Return Null End Sub Sub location_center 'to convert lat and long into 0.5m bitmap location 'get current location Private distance As Float Private radius As Float Private H1 As Float 'long Private O1 As Float 'lat Private H2 As Float 'long Private O2 As Float 'lat Dim location6 As Location location6.Initialize ' location6.Latitude=(-32.6661) ' location6.Longitude=(118.1861) Dim location7 As Location location7.Initialize ' location7.Latitude=(-32.666) ' location7.Longitude=(118.1861) origin.Initialize radius =6372300 origin.lat =Starter.location2.Latitude ' Log("lat"&Starter.location2.Latitude) origin.lng =Starter.location2.Longitude ' Log("long"&Starter.location2.Longitude) H1=(origin.lng)/360*2*cPI H2=(origin.lng+.01)/360*2*cPI 'Log(origin.lat) O1=(origin.lat)/360*2*cPI O2=(origin.lat+.01)/360*2*cPI 'Dim disttohouse As Float location6.Latitude=O1 location6.Longitude=H1 location7.Latitude=O1 location7.Longitude=H2 deltalat=-2*radius*ASin(Power(Power(Sin((O2-O1)/2),2)+Cos(O1)*Cos(O2)*Power(Sin((0)/2),2),.5))/.01*2'111000 deltalong=2*radius*ASin(Power(Cos(O1)*Cos(O1)*Power(Sin((H2-H1)/2),2),.5))/.01*2'fudge'94000 'therefore 1 change in longitude equals deltalong in m 'and 1 change in latitude equals deltalat in m 'Log("det "&deltalat) ' Log("del "&deltalong) ' Log("location6 "&(location6.DistanceTo(location7)/.01)) ' Log("house"&disttohouse) ' deltalat=-2*radius*ASin(Power(Power(Sin((O2-O1)/2),2)+Cos(O1)*Cos(O2)*Power(Sin((H1-H1)/2),2),.5))'111000 End Sub Sub Activity_Resume If Starter.GPS1.GPSEnabled = False Then ToastMessageShow("Please enable the GPS device.", True) StartActivity(Starter.GPS1.LocationSettingsIntent) 'Will open the relevant settings screen. Else Starter.rp.CheckAndRequest(Starter.rp.PERMISSION_ACCESS_FINE_LOCATION) Wait For Activity_PermissionResult (Permission As String, Result As Boolean) If Result Then CallSubDelayed(Starter, "StartGPS") End If End Sub Sub Activity_Pause (UserClosed As Boolean) CallSubDelayed(Starter, "StopGPS") End Sub Sub lineintersect (point1p As coordX, point1c As coordX,point1f As coordX, point2p As coordX, point2c As coordX,point2f As coordX,k As Int) As ResumableSub 'pointp=past: pointc=current: pointf=future 'filler(boompoint0, boompoint00, boompoint10, boompoint1,0)) '// 'line1:y1=g1x1+h2 'line2:y2=g2x2+h2 Dim U As Float Dim V As Float Dim denominat As Float Dim intersectpoint As coordX intersectpoint.Initialize denominat=(point2c.x-point1c.x)*(point2f.y-point1f.y)-(point2c.y-point1c.y)*(point2f.x-point1f.x) If denominat=0 Then 'lines are parrallel, do rectangle find rectanglefiller(point1c,point1p,point2p,point2c,k) rectanglechecker(point1f,point1c,point2c,point2f,k) Return End If U=((point1c.y-point1f.y)*(point2f.x-point1f.x)-(point2f.y-point1f.y)*(point1c.x-point1f.x))/denominat v=((point1c.y-point1f.y)*(point2c.x-point1c.x)-(point2c.y-point1c.y)*(point1c.x-point1f.x))/denominat If (U>0 And U<1 And v<1 And v>0) Then 'lines intersect, therefore need to calculate areas inside two triangles rather than one rectangle intersectpoint.x=point1c.x+(point2c.x-point1c.x)*U intersectpoint.y=point1c.y+(point2c.y-point1c.x)*V trianglefiller(point1c,point1p,intersectpoint,k) trianglefiller(point2c,point2p,intersectpoint,k) '!!need the case to be that if either of the following checkers return a "gap" then section needs to be on boomcolor(k)=Colors.yellow wait for (trianglechecker(point1f,point1p,intersectpoint,k)) complete If boomcolor(k)=Colors.Yellow Then wait for (trianglechecker(point2f,point2p,intersectpoint,k)) complete End If Return Else 'lines are not parrellel, but dont intersect wait for (rectanglefiller(point1c,point1p,point2p,point2c,k)) complete wait for (rectanglechecker(point1f,point1c,point2c,point2f,k)) complete Return End If End Sub Sub trianglefiller(point1 As coordX, point2 As coordX, point3 As coordX,k As Int)As ResumableSub 'find pmax, find pmin 'construct line clockwise from pmax to pmin 'construct line anticlockwise from pmax to pmin 'pull list of x values and draw canvas line between all Dim timer As Long timer=DateTime.Now Dim line1xvalues As List Dim line2xvalues As List Dim line1yvalues As List Dim line2yvalues As List Dim CWmap As Map Dim ACWmap As Map ACWmap.Initialize 'used to progress clockwise and anticlockwise around rectangle ACWmap.Put(point1,point2) ACWmap.Put(point2,point3) ACWmap.Put(point3,point1) CWmap.Initialize CWmap.Put(point1,point3) CWmap.Put(point2,point1) CWmap.Put(point3,point2) line1xvalues.Initialize line2xvalues.Initialize line1yvalues.initialize line2yvalues.Initialize Dim pmax As coordX Dim pmin As coordX Dim temp As coordX Dim Pmap As Map 'lets us grab the maxY and minY after finding the min and max value Pmap.Initialize Pmap.Put(point1.y,point1) Pmap.Put(point2.y,point2) Pmap.Put(point3.y,point3) pmax.Initialize pmin.Initialize Dim temp3 As Float temp3 = Max(point1.y,Max(point2.y,point3.y)) Dim temp4 As Float temp4 = Min(point1.y,Min(point2.y,point3.y)) pmax=Pmap.Get(temp3) 'temp variable required, otherwise pmax is null pmin=Pmap.Get(temp4) Dim temp2 As coordX temp = pmax line1xvalues.add(pmax.x)'initial point to both line lists line1yvalues.add(pmax.y) line2xvalues.add(pmax.x) line2yvalues.add(pmax.y) Do While temp <> pmin 'cwloop temp2=CWmap.Get(temp)'gets second point for line Wait For(calcline(temp.x,temp.y, temp2.x,temp2.y,line1xvalues,line1yvalues)) complete 'line2xvalues generated temp = CWmap.Get(temp) 'changes the first line point to the second 'Log("line1") Loop temp = pmax Do While temp <> pmin 'acwloop temp2=ACWmap.Get(temp)'gets second point for line wait for (calcline(temp.x,temp.y, temp2.x,temp2.y,line2xvalues,line2yvalues)) complete 'line2xvalues generated temp = ACWmap.Get(temp) 'changes the first line point to the second 'Log("line2") Loop line1xvalues.add(pmin.x)'final point to both line lists line1yvalues.add(pmin.y) line2xvalues.add(pmin.x) line2yvalues.add(pmin.y) Dim ytemp As Int ytemp=pmax.y 'could choose to save both x and y values to line1xvalues rather than just x. For i=0 To Min(line1xvalues.Size,line2xvalues.Size)-1 bmcGraph.DrawLine(line1xvalues.Get(i),ytemp,line2xvalues.get(i),ytemp,boomcolor(k),1) ytemp=ytemp-1 Next Return 2 End Sub Sub trianglechecker(point1 As coordX, point2 As coordX, point3 As coordX, k As Int)As ResumableSub Dim ACWmap As Map Dim CWmap As Map Dim line1xvalues As List Dim line2xvalues As List Dim line2yvalues As List Dim line1yvalues As List ACWmap.Initialize 'used to progress clockwise and anticlockwise around rectangle ACWmap.Put(point1,point2) ACWmap.Put(point2,point3) ACWmap.Put(point3,point1) CWmap.Initialize CWmap.Put(point1,point3) CWmap.Put(point2,point1) CWmap.Put(point3,point2) line1xvalues.Initialize line2xvalues.Initialize line1yvalues.initialize line2yvalues.Initialize Dim pmax As coordX Dim pmin As coordX Dim temp As coordX Dim Pmap As Map 'lets us grab the maxY and minY after finding the min and max value Pmap.Initialize Pmap.Put(point1.y,point1) Pmap.Put(point2.y,point2) Pmap.Put(point3.y,point3) pmax.Initialize pmin.Initialize Dim temp3 As Float temp3 = Max(point1.y,Max(point2.y,point3.y)) Dim temp4 As Float temp4 = Min(point1.y,Min(point2.y,point3.y)) pmax=Pmap.Get(temp3) 'temp variable required, otherwise pmax is null pmin=Pmap.Get(temp4) Dim temp2 As coordX temp = pmax line1xvalues.add(pmax.x)'initial point to both line lists line1yvalues.add(pmax.y) line2xvalues.add(pmax.x) line2yvalues.add(pmax.y) Do While temp <> pmin 'cwloop temp2=CWmap.Get(temp)'gets second point for line Wait For(calcline(temp.x,temp.y, temp2.x,temp2.y,line1xvalues,line1yvalues)) complete 'line2xvalues generated temp = CWmap.Get(temp) 'changes the first line point to the second Loop temp = pmax Do While temp <> pmin 'acwloop temp2=ACWmap.Get(temp)'gets second point for line wait for (calcline(temp.x,temp.y, temp2.x,temp2.y,line2xvalues,line2yvalues)) complete 'line2xvalues generated temp = ACWmap.Get(temp) 'changes the first line point to the second Loop line1xvalues.add(pmin.x)'adds final point to both line lists line1yvalues.add(pmin.y) line2xvalues.add(pmin.x) line2yvalues.add(pmin.y) Dim ytemp As Int Dim pixelchecked As Int pixelchecked=0 ytemp=pmax.y 'could choose to save both x and y values to line1xvalues rather than just x. For i=0 To (Min(line1xvalues.Size,line2xvalues.Size)-1) 'iterates from top point to bottom of polygone, drawing a level line from left to right For j=line2xvalues.Get(i) To line1xvalues.Get(i) Step 1'issue solved, was counting from a higher number to a lower number rather than lower to higher pixelchecked=pixelchecked+1 If bmcGraph.GetColor(j,ytemp)=-1 Then boomon=True boomcolor(k)=xui.Color_Green Return boomcolor(k) End If Next ytemp=ytemp-1 Next boomcolor(k)=xui.Color_yellow boomon=False Log("boomon"&boomon) Return boomcolor(k) End Sub