Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- radius =tonumber(read())
- x = 0
- y = 0
- function round(x)
- n = x % 1
- if n >= 0.5 then
- return math.ceil(x)
- else
- return math.floor(x)
- end
- end
- function getQuaterSector(r,y)
- sectorEdges = {}
- while x <= r^2 do
- z = math.sqrt(r^2-x-y^2)
- if math.sqrt(x) % 1 == 0 then
- table.insert(sectorEdges,{math.sqrt(x),round(z)})
- end
- x = x + 1
- end
- return sectorEdges
- end
- function moveToOnYPlane(x1,z1,x2,z2)
- XDiff=x2-x1
- if XDiff>0 then
- turtle.turnRight()
- elseif XDiff<0 then
- turtle.turnLeft()
- end
- tempDiff = 0
- if XDiff<0 then tempDiff = -XDiff else tempDiff=XDiff end
- i=0
- while i<tempDiff do
- turtle.forward()
- i=i+1
- end
- if XDiff>0 then
- turtle.turnLeft()
- elseif XDiff<0 then
- turtle.turnRight()
- end
- ZDiff =z2-z1
- if ZDiff<0 then
- turtle.turnLeft()
- turtle.turnLeft()
- end
- tempDiff2=0
- if ZDiff <0 then tempDiff2 = -ZDiff else tempDiff2 = ZDiff end
- b=0
- while b<tempDiff2 do
- turtle.forward()
- b = b+1
- end
- if ZDiff<0 then
- turtle.turnLeft()
- turtle.turnLeft()
- end
- end
- function placeSector(arr)
- a=0
- while a < table.getn(arr) do
- moveToOnYPlane(0,0,arr[a][1],arr[a][2])
- turtle.placeDown()
- moveToOnYPlane(arr[a][1],arr[a][2],0,0)
- a = a + 1
- end
- end
- function placeCircle(radius, y)
- arr = getQuaterSector(radius, y)
- placeSector(arr)
- turtle.turnRight()
- placeSector(arr)
- turtle.turnRight()
- placeSector(arr)
- turtle.turnRight()
- placeSector(arr)
- turtle.turnRight()
- end
- function placeSphere(radius)
- a=radius
- while a>0 do
- placeCircle(radius,radius-a)
- turtle.up()
- a = a-1
- end
- turtle.placeUp()
- while a <= radius do
- turtle.down()
- a=a+1
- end
- while a>0 do
- placeCircle(radius, radius-a)
- turtle.down()
- a = a-1
- end
- while a <= radius do
- turtle.up()
- a = a+1
- end
- turtle.down()
- turtle.placeUp()
- end
- placeSphere(radius)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement