Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local vecMods = { {0,-1}, { 1,0}, { 0,1}, {-1,0} }
- local dir = 2
- local out = 0
- local currentLoc = {0,0}
- function processField()
- print("Processed!")
- end
- function moveOn()
- currentLoc[1] = currentLoc[1] + vecMods[dir][1]
- currentLoc[2] = currentLoc[2] + vecMods[dir][2]
- end
- function isEdge(loc)
- local edgeLocs = {
- { -out, -out },
- { out, -out },
- { -out, out },
- { out, out }
- }
- for _,v in pairs( edgeLocs ) do
- if v[1] == loc[1] and v[2] == loc[2] then return true end
- end
- return false
- end
- function moveOut()
- dir = 2
- moveOn()
- out = out + 1
- end
- processField()
- while true do
- moveOut()
- startLoc = {}
- startLoc.x = currentLoc[1]
- startLoc.y = currentLoc[2]
- processField()
- dir = 3
- moveOn()
- processField()
- while (currentLoc[1] ~= startLoc.x or currentLoc[2] ~= startLoc.y) do
- if isEdge(currentLoc) then dir = dir % 4 + 1 end
- moveOn()
- processField()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment