Microsoft Small Basic

Program Listing: DMB122
' SmallBasic Version 1.2
' Program: TurtleWorldWalk
' Changelog:
' Author: Pappa Lapub
' Website: https://social.msdn.microsoft.com/Forums/en-US/694293e5-bcb4-46ba-9680-52bec7646c9b/turtle-background
' https://social.msdn.microsoft.com/Forums/en-US/f7e0310e-f7ad-4706-a8a7-b882e58b7d0e/how-to-create-good-collision-box-without-lagging-for-a-platformer-game
' ImportURL: http://smallbasic.com/program/?
' SBOnline: http://smallbasic-publicwebsite-dev.azurewebsites.net/Program/view.aspx?
' Extension: LitDev (, SBColor)
' Comment:
'
' Variables:
' ToDo:
' ==============================================================================
'https://commons.wikimedia.org/w/index.php?search=Equirectangular+Projection&title=Special%3ASearch&profile=default&fulltext=1&ns0=1&ns6=1&ns12=1&ns14=1&ns100=1&ns106=1
'https://commons.wikimedia.org/w/index.php?search=equirectangular+earth+projection

distLong = -18
gw = GraphicsWindow.Width
gh = GraphicsWindow.Height
img = ImageList.LoadImage("https://upload.wikimedia.org/wikipedia/commons/thumb/d/df/Worldmap_location_NED_50m.svg/1024px-Worldmap_location_NED_50m.svg.png")
' The following line could be harmful and has been automatically commented.
' 'img = ImageList.LoadImage(LDFile.PicturesFolder +"\Planeten-Sonnensystem\Projections\WorldMap_Location_NED_50m_1024x512.png")
GraphicsWindow.DrawResizedImage(img, 0,0, gw,gh)

'Turtle.Show()
'w = LDShapes.Width("_turtle")
'h = LDShapes.Height("_turtle")
'GraphicsWindow.Title = w +" x "+ h

'cursor = Program.Directory +"\_turtle.cur"
'turt = ImageList.LoadImage("_turtle")
'LDIcon.CreateCursor(turt, cursor, 32, 16,16)
'cur = LDCursors.CreateCursor(turt, 0,0)
'LDCursors.SetUserCursor(turt)
'LDCursors.SetUserCursor(cursor)

GraphicsWindow.PenWidth = 1
GraphicsWindow.PenColor = "Blue"
GraphicsWindow.DrawLine(gw/2+distLong,0, gw/2+distLong,gh) ' 0° Greenwich Latitude (INCORRECT)
GraphicsWindow.DrawLine(0,gh/2, gw,gh/2) ' Equator

GraphicsWindow.PenColor = "Red" ' Line color

'dist = SBColor.GetDistance("White", "#808080") ' 49.8039215686274
'dist = SBColor.GetDistance("Black", "#808080") ' 50.1960784313726
'dist = SBColor.GetDistance("Black", "White")
'TextWindow.WriteLine(dist)

GraphicsWindow.KeyDown = OnKeyDown

' Random walk
While "True"
If bPause Then
Program.Delay(20)

Else
x = Math.GetRandomNumber(gw)-1
y = Math.GetRandomNumber(gh)-1

cG = LDColours.GetGreen(LDGraphicsWindow.GetPixel(x,y))
If cG > 250 Then ' target is on a continent (~White)
GetLatLong()
Turtle.MoveTo(x,y)
Program.Delay(1000)
EndIf

EndIf
EndWhile


' //////////////////// SUBs ////////////////////
Sub GetLatLong
'long = 180*(2*x/gw - 1) ' 360*x/gw - 180 (-180 W bis 180° E)
'long = 0.01 * Math.Round(100*long)
long = 0.01 * Math.Round(18000*(2*(x-distLong)/gw - 1))

If long < 0 Then
long = Math.Abs(long) +"°W"
Else
long = long +"°O" ' "°E"
EndIf

''lat = 90*(2*y/gh - 1) ' 180*y/gh - 90 (-90 N bis 90 ° S)
'lat = 0.01 * Math.Round(100*lat)
lat = 0.01 * Math.Round(9000*(2*y/gh - 1))

If lat < 0 Then
lat = Math.Abs(lat) +"°N"
Else
lat = lat +"°S"
EndIf

'TextWindow.WriteLine(x +", "+ y +" | "+ long +", "+ lat)
GraphicsWindow.Title = x +", "+ y +" | "+ long +", "+ lat
EndSub

Sub Pause
bPause = LDLogic.Not(bPause)
EndSub



' ////////////////// EVENTs ///////////////////
Sub OnKeyDown
lastKey = GraphicsWindow.LastKey

If lastKey = "Escape" Then
Program.End()

ElseIf lastKey = "P" Then
Pause()

EndIf
EndSub