Advertisement
Guest User

Untitled

a guest
Sep 21st, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.70 KB | None | 0 0
  1.  
  2. function setpixel(table, n, x, y)
  3. local tx = math.floor(n/2)+x
  4. local ty = math.floor(n/2)+y
  5.  
  6. table[ty+1][tx+1] = 'x'
  7. end
  8.  
  9. function init(pixels, radius)
  10.  
  11. intRadius = math.floor(radius)
  12. n = 2*(intRadius+1) + 1
  13.  
  14. -- go up and move past the circle
  15. turtle.up()
  16. for i=1,intRadius+1 do
  17. turtle.forward()
  18. end
  19. turtle.turnLeft()
  20.  
  21. -- set empty spaces to dot
  22. for y=1,n do
  23. pixels[y] = {}
  24. for x=1,n do
  25. pixels[y][x] = '.'
  26. end
  27. end
  28.  
  29. -- fill in circle pixels
  30. local l = math.floor(radius * math.cos(math.pi/4))
  31.  
  32. for x=0,l do
  33. y = math.floor(math.sqrt(radius*radius - x*x))
  34. setpixel(x, y)
  35. setpixel(-x, y)
  36. setpixel(x, -y)
  37. setpixel(-x, -y)
  38. setpixel(y, x)
  39. setpixel(-y, x)
  40. setpixel(y, -x)
  41. setpixel(-y, -x)
  42. end
  43.  
  44. end
  45.  
  46. function printGrid(table)
  47. for y=1,#table do
  48. for x=1,#table do
  49. write(table[y][x])
  50. end
  51. print()
  52. end
  53. end
  54.  
  55. print(turtle.refuel())
  56. os.loadAPI("lib.lua")
  57.  
  58. local maxy = 1
  59. local radius = 3
  60. local intRadius = math.floor(radius)
  61. local pixels = {}
  62. init(pixels, radius)
  63.  
  64. local posx, posy = intRadius+2, n
  65. local vx, vy = -1, 0
  66.  
  67. function pixelLeft(posx, posy, vx, vy)
  68. vvx, vvy = left(vx, vy)
  69. xx, yy = posx+vvx, posy+vvy
  70. print('checking left: ', xx, yy)
  71. if (xx < 1) or (xx >= n) then
  72. return false
  73. end
  74. if (yy < 1) or (yy >= n) then
  75. return false
  76. end
  77. return pixels[yy][xx] == 'x'
  78. end
  79.  
  80. function pixelForward(posx, posy, vx, vy)
  81. xx, yy = posx+vx, posy+vy
  82. if (xx < 1) or (xx >= n) then
  83. return false
  84. end
  85. if (yy < 1) or (yy >= n) then
  86. return false
  87. end
  88. return pixels[yy][xx] == 'x'
  89. end
  90.  
  91. function moveAndPlace(posx, posy, vx, vy)
  92. posx, posy = posx+vx, posy+vy
  93. turtle.forward()
  94. if lib.currentSlotEmpty() then
  95. lib.reSelect()
  96. end
  97. turtle.placeDown()
  98. return posx, posy
  99. end
  100.  
  101. function mainLoop(posx, posy, vx, vy)
  102. print(posx, posy)
  103. if pixelLeft(posx, posy, vx, vy) then
  104. print('pixel left!')
  105. if pixelForward(posx, posy, vx, vy) then
  106. print('pixel forward!')
  107. vx, vy = lib.turnRight(vx, vy)
  108. end
  109. else
  110. vx, vy = lib.turnLeft()
  111. end
  112. posx, posy = moveAndPlace(posx, posy, vx, vy)
  113. end
  114.  
  115. local currenty = 0
  116. repeat
  117. -- one circle in xz plane
  118. repeat
  119. mainLoop(posx, posy, vx, vy)
  120. until (posx==intRadius+2) and (posy==n)
  121. currenty = currenty+1
  122. turtle.up()
  123. print('one more layer finished!')
  124. until currenty==maxy
  125. print('done! :)')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement