Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function setpixel(table, n, x, y)
- local tx = math.floor(n/2)+x
- local ty = math.floor(n/2)+y
- table[ty+1][tx+1] = 'x'
- end
- function init(pixels, radius)
- intRadius = math.floor(radius)
- n = 2*(intRadius+1) + 1
- -- go up and move past the circle
- turtle.up()
- for i=1,intRadius+1 do
- turtle.forward()
- end
- turtle.turnLeft()
- -- set empty spaces to dot
- for y=1,n do
- pixels[y] = {}
- for x=1,n do
- pixels[y][x] = '.'
- end
- end
- -- fill in circle pixels
- 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
- end
- function printGrid(table)
- for y=1,#table do
- for x=1,#table do
- write(table[y][x])
- end
- print()
- end
- end
- print(turtle.refuel())
- os.loadAPI("lib.lua")
- local maxy = 1
- local radius = 3
- local intRadius = math.floor(radius)
- local pixels = {}
- init(pixels, radius)
- local posx, posy = intRadius+2, n
- local vx, vy = -1, 0
- function pixelLeft(posx, posy, vx, vy)
- vvx, vvy = left(vx, vy)
- 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(posx, posy, vx, vy)
- 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 moveAndPlace(posx, posy, vx, vy)
- posx, posy = posx+vx, posy+vy
- turtle.forward()
- if lib.currentSlotEmpty() then
- lib.reSelect()
- end
- turtle.placeDown()
- return posx, posy
- end
- function mainLoop(posx, posy, vx, vy)
- print(posx, posy)
- if pixelLeft(posx, posy, vx, vy) then
- print('pixel left!')
- if pixelForward(posx, posy, vx, vy) then
- print('pixel forward!')
- vx, vy = lib.turnRight(vx, vy)
- end
- else
- vx, vy = lib.turnLeft()
- end
- posx, posy = moveAndPlace(posx, posy, vx, vy)
- end
- local currenty = 0
- repeat
- -- one circle in xz plane
- repeat
- mainLoop(posx, posy, vx, vy)
- 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