Advertisement
JMANN2400

CircleMaker

Aug 13th, 2017
461
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.56 KB | None | 0 0
  1.  
  2.  
  3.  
  4. x = nil
  5.  
  6. y = nil
  7.  
  8. z = 0
  9.  
  10. function digHole()
  11.     while z < h do
  12.         turtle.digDown()
  13.         turtle.down()
  14.         z = z + 1
  15.     end
  16.     while z > 0 do
  17.         turtle.digUp()
  18.         turtle.up()
  19.         z = z - 1
  20.     end
  21. end
  22.  
  23. function testRange()
  24.     if math.sqrt(math.pow(x, 2) + math.pow(y, 2)) <= r then
  25.         return true
  26.     else
  27.         return false
  28.     end
  29. end
  30.  
  31. function search()
  32.     while y <= r do
  33.         if testRange() then
  34.             digHole()
  35.         end
  36.         while x < r do
  37.             turtle.dig()
  38.             turtle.forward()
  39.             x = x + 1
  40.             if testRange() then
  41.                 digHole()
  42.             end
  43.         end
  44.         turtle.turnRight()
  45.         turtle.dig()
  46.         turtle.forward()
  47.         y = y + 1
  48.         if testRange() then
  49.             digHole()
  50.         end
  51.         turtle.turnRight()
  52.         while x > -r do
  53.             turtle.dig()
  54.             turtle.forward()
  55.             x = x - 1
  56.             if testRange() then
  57.                 digHole()
  58.             end
  59.         end
  60.         turtle.turnLeft()
  61.         turtle.dig()
  62.         turtle.forward()
  63.         y = y + 1
  64.         if testRange() then
  65.             digHole()
  66.         end
  67.         turtle.turnLeft()
  68.     end
  69. end
  70.  
  71.  
  72.  
  73. print("+-------------------------------------+")
  74. print("| Circle Miner                        |")
  75. print("+-------------------------------------+")
  76.  
  77. print("+-------------------------------------+")
  78.  
  79. print("+-------------------------------------+")
  80. read()
  81. print("+-------------------------------------+")
  82. print("| Radius = ?                          |")
  83. print("+-------------------------------------+")
  84. r = tonumber(read())
  85.  
  86. x = -r
  87.  
  88. y = -r
  89.  
  90. print("+-------------------------------------+")
  91. print("| Height = ?                          |")
  92. print("+-------------------------------------+")
  93. h = tonumber(read())
  94.  
  95. search()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement