jseely

circle

Jan 2nd, 2013
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. local tArgs = { ... }
  2.  
  3. local radius = { tonumber( tArgs[1] ), tonumber(tArgs[1])^2 }
  4. local radians = tonumber( tArgs[2] )
  5. local fill = tArgs[3]
  6.  
  7. local xPos, zPos = radius[1],0
  8. local xDir, zDir = -1,0
  9.  
  10. if radians == 2 then
  11. xPos, zPos = radius[1], radius[1]
  12. xDir, zDir = -1,0
  13. elseif radians == 1 then
  14. xPos, zPos = radius[1], 0
  15. xDir, zDir = -1,0
  16. end
  17.  
  18. local circle = {}
  19. for i = -radius[1], radius[1], 1 do
  20. circle[i] = {}
  21. for j = -radius[1], radius[1], 1 do
  22. circle[i][j] = 0
  23. end
  24. end
  25.  
  26. local z = radius[1]
  27.  
  28. for x = 0, radius[1], 1 do
  29. if math.abs((z^2 + x^2)^0.5 - radius[1]) > math.abs(((z-1)^2 + x^2)^0.5 - radius[1]) then
  30. z = z-1
  31. end
  32. if z < x then
  33. break
  34. end
  35. circle[x][z] = 1
  36. circle[z][x] = 1
  37. circle[x][-z] = 1
  38. circle[z][-x] = 1
  39. circle[-x][z] = 1
  40. circle[-z][x] = 1
  41. circle[-x][-z] = 1
  42. circle[-z][-x] = 1
  43. end
  44.  
  45. for x = 0, radius[1] - 1, 1 do
  46. for z = 0, radius[1] - 1, 1 do
  47. if circle[x][z] == 1 then
  48. break
  49. end
  50. circle[x][z] = 2
  51. circle[x][-z] = 2
  52. circle[-x][z] = 2
  53. circle[-x][-z] = 2
  54. end
  55. end
  56.  
  57. local done = false
  58. local curSlot = 1
  59.  
  60. local function selectResource()
  61. while turtle.getItemCount(curSlot) == 0 do
  62. curSlot = curSlot + 1
  63. if curSlot > 16 then
  64. return false
  65. end
  66. end
  67. turtle.select(curSlot)
  68. end
  69.  
  70. local function place()
  71. selectResource()
  72. turtle.place()
  73. end
  74.  
  75. local function placeUp()
  76. selectResource()
  77. turtle.placeUp()
  78. end
  79.  
  80. local function placeDown()
  81. selectResource()
  82. turtle.placeDown()
  83. end
  84.  
  85. local function move()
  86. if xPos == -radius[1] and math.abs(xDir+xPos) > radius[1] then
  87. if zPos == radius[1] then
  88. done = true
  89. else
  90. turtle.turnRight()
  91. if turtle.forward() then
  92. zPos = zPos + 1
  93. end
  94. turtle.turnRight()
  95. xDir = 1
  96. end
  97. elseif xPos == radius[1] and math.abs(xDir+xPos) > radius[1] then
  98. if zPos == radius[1] then
  99. done = true
  100. else
  101. turtle.turnLeft()
  102. if turtle.forward() then
  103. zPos = zPos + 1
  104. end
  105. turtle.turnLeft()
  106. xDir = -1
  107. end
  108. else
  109. if turtle.forward() then
  110. xPos = xDir + xPos
  111. end
  112. end
  113. end
  114.  
  115. while not done do
  116. if circle[xPos][zPos] == 1 or (circle[xPos][zPos] == 2 and fill) then
  117. placeDown()
  118. print("(" .. xPos .. ", " .. zPos .. ") -> " .. circle[xPos][zPos])
  119. end
  120.  
  121. move()
  122. end
Advertisement
Add Comment
Please, Sign In to add comment