Advertisement
Damp_Owl

Untitled

Mar 20th, 2025 (edited)
231
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.62 KB | Gaming | 0 0
  1. local bit32 = require("bit32")
  2.  
  3. -- going clockwise direction is 1 for 12 oclock 2 for 3, 3 for 6 and 4 for 9
  4. local direction = 1
  5.  
  6. term.clear()
  7. term.setCursorPos(0, 0)
  8. print("Welcome to HilbertTurtle the turtle mining program which uses a sudo HilbertCurve")
  9. print("Please input an order for the hilbert curve:")
  10.  
  11. local order = io.read()
  12. print("Please input a thickness between tunnels:")
  13. local thick = io.read()
  14. local N = 2^order
  15. local total = N*N
  16. local volume = total*(thick*2)
  17. local pathX = {}
  18. local pathY = {}
  19.  
  20. print("Thank you, Estimate blocks mined is: " .. volume)
  21.  
  22. local function digforward(num)
  23.     local k = num
  24.     for i = 1, k, 1 do
  25.         while turtle.detect() == true do
  26.             turtle.dig()
  27.         end
  28.         turtle.forward()
  29.         turtle.digDown()
  30.     end
  31. end
  32.  
  33. local function turnTo(targetDir)
  34.     local tDir = targetDir
  35.     while direction ~= tDir do
  36.         turtle.turnRight()
  37.         direction = direction + 1
  38.         if direction > 4 then
  39.             direction = 1
  40.         end
  41.     end
  42. end
  43.  
  44. local function goTo(x,y,u,v)
  45.     local xx = x
  46.     local yy = y
  47.     local uu = u
  48.     local vv = v
  49.     local targetDir
  50.     if uu > xx then
  51.         targetDir = 2
  52.     elseif uu < xx then
  53.         targetDir = 4
  54.     elseif vv > yy then
  55.         targetDir = 1
  56.     elseif vv < yy then
  57.         targetDir = 3
  58.     end
  59.     if direction ~= targetDir then
  60.         turnTo(targetDir)
  61.     end
  62.  
  63.     local num = (math.abs(xx - uu)) + (math.abs(yy - vv))
  64.     digforward(num)
  65. end
  66.  
  67. local function hilbert(k)
  68.     local i = k
  69.     local pointsX = {0,0,1,1}
  70.     local pointsY = {0,1,1,0}
  71.     local index = bit32.band(i,3)
  72.     local vx = pointsX[index+1]
  73.     local vy = pointsY[index+1]
  74.  
  75.     for j = 1, order, 1 do
  76.         i = bit32.rshift(i,2)
  77.         index = bit32.band(i,3)
  78.  
  79.         local len = 2^j
  80.         if  index == 0 then
  81.             local tmp = vx
  82.             vx = vy
  83.             vy = tmp
  84.         elseif index == 1 then
  85.             vy = vy + len
  86.         elseif index == 2 then
  87.             vx = vx + len
  88.             vy = vy + len
  89.         else
  90.             local tmp = len - 1 - vx
  91.             vx = len - 1 - vy
  92.             vy = tmp
  93.             vx = vx + len
  94.         end
  95.     end
  96.  
  97.     return vx,vy
  98. end
  99.  
  100. local function createPoints()
  101.     for i = 0, total, 1 do
  102.         local path = table.pack(hilbert(i))
  103.         pathX[i+1] = path[1]
  104.         pathY[i+1] = path[2]
  105.         local len = thick
  106.         pathX[i+1] = pathX[i+1] * len
  107.         pathY[i+1] = pathY[i+1] * len
  108.     end    
  109. end
  110.  
  111. createPoints()
  112.  
  113. for i = 1, total, 1 do
  114.     goTo(pathX[i],pathY[i],pathX[i+1],pathY[i+1])
  115. end
Advertisement
Comments
  • responsive02
    14 hours
    # text 0.78 KB | 0 0
    1. https://bigwarp.io/7txvvw88j47z
    2.  
    3. https://bigwarp.io/37cal9qxtkfd
    4.  
    5. https://bigwarp.io/yojwi7en1pvq
    6.  
    7. https://bigwarp.io/qijd9p456n3q
    8.  
    9. https://bigwarp.io/8q8rweiy8jbr
    10.  
    11. https://bigwarp.io/twu7014koab0
    12.  
    13. https://bigwarp.io/a52gx3me2yb6
    14.  
    15. https://bigwarp.io/vbg8tr63zpg7
    16.  
    17. https://bigwarp.io/0buj2xybbiya
    18.  
    19. https://bigwarp.io/bpkjblxxvcne
    20.  
    21. https://bigwarp.io/2uybz9tn4ylx
    22.  
    23. https://bigwarp.io/zgj5po6pvxzi
    24.  
    25. https://bigwarp.io/mku1zg635c3p
    26.  
    27. https://bigwarp.io/ehrx7oehy8dz
    28.  
    29. https://bigwarp.io/sgrz07aqfp65
    30.  
    31. https://bigwarp.io/xrhv7lzwf1lg
    32.  
    33. https://bigwarp.io/lng31yy8nn5t
    34.  
    35. https://bigwarp.io/1m2pzph656py
    36.  
    37. https://bigwarp.io/qigrntkn99pb
    38.  
    39. https://bigwarp.io/8zndb2n6jiwy
    40.  
    41. https://bigwarp.io/8ekzkk952yu3
    42.  
    43. https://bigwarp.io/1u99fslfyel0
    44.  
    45. https://bigwarp.io/n6cq48ytrt2i
Add Comment
Please, Sign In to add comment
Advertisement