Not a member of Pastebin yet?
                        Sign Up,
                        it unlocks many cool features!                    
                - local tArgs = {...}
 - local dim = tonumber( tArgs[1] )
 - local startDir = tArgs[2] == "l"
 - local coord = { 0, 0, 0 }
 - local dir = 0
 - coord[1] = math.ceil( -dim / 2 )
 - coord[3] = math.ceil( -dim / 2 )
 - local startCoord = { coord[1], coord[2], coord[3] }
 - if not startDir then coord[3] = -coord[3] end
 - function curMoveAxis()
 - if dir % 2 == 0 then
 - return 1
 - else
 - return 3
 - end
 - end
 - function curMoveDir()
 - if math.floor( dir / 2 ) % 2 == 0 then
 - return 1
 - else
 - return -1
 - end
 - end
 - function forward()
 - while not turtle.forward() do sleep( 1 ) end
 - local axis = curMoveAxis()
 - coord[ axis ] = coord[ axis ] + curMoveDir()
 - end
 - function backward()
 - while not turtle.back() do sleep( 1 ) end
 - local axis = curMoveAxis()
 - coord[ axis ] = coord[ axis ] - curMoveDir()
 - end
 - function turnLeft()
 - turtle.turnLeft()
 - dir = ( dir + 1 ) % 4
 - end
 - function turnRight()
 - turtle.turnRight()
 - dir = ( dir - 1 ) % 4
 - end
 - function turn( _dir )
 - if _dir then
 - turnLeft()
 - else
 - turnRight()
 - end
 - end
 - function moveToSlot( to, fromMin, fromMax )
 - if not fromMax then fromMax = 16 end
 - for i = fromMin, fromMax do
 - if turtle.getItemCount( to ) == 64 then break end
 - if not i == to and turtle.getItemCount( i ) > 0 then
 - turtle.select( i )
 - turtle.transferTo( to, 64 )
 - end
 - end
 - turtle.select( to )
 - end
 - function inRange()
 - return coord[1] * coord[1] + coord[3] * coord[3] < ( dim / 2 ) * ( dim / 2 )
 - end
 - for i = 1, dim do
 - local hasPlaced = false
 - print("Nextline")
 - while inRange() or not hasPlaced do
 - if inRange() then
 - --print( "!!", coord[1], coord[3] )
 - moveToSlot( 1, 2 )
 - turtle.placeDown()
 - hasPlaced = true
 - end
 - forward()
 - end
 - turn( startDir )
 - forward()
 - turn( startDir )
 - while inRange() do
 - backward()
 - end
 - startDir = not startDir
 - end
 - function sign( t )
 - if t < 0 then return -1 else return 1 end
 - end
 - function stepsToPos( newCoord )
 - local axis = curMoveAxis()
 - return ( coord[ axis ] - newCoord[ axis ] ) * curMoveDir()
 - end
 - function moveTo( newCoord )
 - for i = 1, 2 do
 - local axis = curMoveAxis()
 - while stepsToPos( newCoord ) > 0 do
 - backward()
 - end
 - while stepsToPos( newCoord ) < 0 do
 - forward()
 - end
 - if i == 1 then turn(true) end
 - end
 - turn(false)
 - end
 - moveTo( startCoord )
 
Advertisement
 
                    Add Comment                
                
                        Please, Sign In to add comment