Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- print(turtle.refuel())
- maxy = 1
- radius = 3
- intRadius = math.floor(radius)
- n = 2*(intRadius+1) + 1
- pixels = {}
- function init()
- turtle.up()
- for i=1,intRadius+1 do
- turtle.forward()
- end
- turtle.turnLeft()
- end
- init()
- function setpixel(x, y)
- local tx = math.floor(n/2)+x
- local ty = math.floor(n/2)+y
- pixels[ty+1][tx+1] = 'x'
- end
- for y=1,n do
- pixels[y] = {}
- for x=1,n do
- pixels[y][x] = '.'
- end
- end
- local l = math.floor(radius * math.cos(math.pi/4))
- for x=0,l do
- y = math.floor(math.sqrt(radius*radius - x*x))
- setpixel(x, y)
- setpixel(-x, y)
- setpixel(x, -y)
- setpixel(-x, -y)
- setpixel(y, x)
- setpixel(-y, x)
- setpixel(y, -x)
- setpixel(-y, -x)
- end
- for y=1,#pixels do
- for x=1,#pixels do
- write(pixels[y][x])
- end
- print()
- end
- posx, posy = intRadius+2, n
- vx, vy = -1, 0
- function left()
- return vy*-1, vx
- end
- function right()
- return vy, vx*-1
- end
- function turnLeft()
- vx, vy = left()
- turtle.turnLeft()
- end
- function turnRight()
- vx, vy = right()
- turtle.turnRight()
- end
- function pixelLeft()
- vvx, vvy = left()
- xx, yy = posx+vvx, posy+vvy
- print('checking left: ', xx, yy)
- if (xx < 1) or (xx >= n) then
- return false
- end
- if (yy < 1) or (yy >= n) then
- return false
- end
- return pixels[yy][xx] == 'x'
- end
- function pixelForward()
- xx, yy = posx+vx, posy+vy
- if (xx < 1) or (xx >= n) then
- return false
- end
- if (yy < 1) or (yy >= n) then
- return false
- end
- return pixels[yy][xx] == 'x'
- end
- function currentSlotEmpty()
- return turtle.getItemCount(turtle.getSelectedSlot())==0
- end
- function reSelect()
- for i=1,16 do
- if turtle.getItemCount(i) > 0 then
- turtle.select(i)
- return
- end
- end
- -- exit the program early
- error()
- end
- function moveAndPlace()
- posx, posy = posx+vx, posy+vy
- turtle.forward()
- if currentSlotEmpty() then
- reSelect()
- end
- turtle.placeDown()
- end
- function mainLoop()
- print(posx, posy)
- if pixelLeft() then
- print('pixel left!')
- if pixelForward() then
- print('pixel forward!')
- turnRight()
- end
- else
- turnLeft()
- end
- moveAndPlace()
- end
- currenty = 0
- repeat
- -- one circle in xz plane
- repeat
- mainLoop()
- until (posx==intRadius+2) and (posy==n)
- currenty = currenty+1
- turtle.up()
- print('one more layer finished!')
- until currenty==maxy
- print('done! :)')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement