Skip to content

Instantly share code, notes, and snippets.

@SquidLord
Last active February 6, 2016 18:18
Show Gist options
  • Save SquidLord/4744290 to your computer and use it in GitHub Desktop.
Save SquidLord/4744290 to your computer and use it in GitHub Desktop.
ComputerCraft turtle code for building a sphere of material.
-- v. 1.0 : Based off of v. 1.1 of Circle Platform. Again, a bit messy, dealing
-- with going over the entire area of r^3 cube (and plus the distance for it to
-- get back to the center), but this should do the trick.
-- The MIT License (MIT)
-- Copyright (c) 2012 Alexander Williams
-- Permission is hereby granted, free of charge, to any person obtaining a copy
-- of this software and associated documentation files (the "Software"), to deal
-- in the Software without restriction, including without limitation the rights
-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-- copies of the Software, and to permit persons to whom the Software is
-- furnished to do so, subject to the following conditions:
-- The above copyright notice and this permission notice shall be included in all
-- copies or substantial portions of the Software.
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-- SOFTWARE.
local tArgs = {...}
local radius = tonumber(tArgs[1])
local slot = 1
local turnflag = true
turtle.select(slot)
for k = -radius,radius do
turnflag = true
for i = 1,radius do
turtle.back()
end
turtle.turnRight()
for i = 1,radius do
turtle.back()
end
turtle.turnLeft()
for i = -radius, radius do
for j = -radius, radius do
if turtle.getItemCount(slot) == 0 then
slot = slot + 1
if slot == 17 then
slot = 1 -- Let's hope something will be there.
if turtle.getItemCount(slot) == 0 then
return
end
end
turtle.select(slot)
end
if math.sqrt(i*i + j*j + k*k) <= radius then
turtle.placeDown()
end
turtle.forward()
end
if turnflag == true then
turtle.turnRight()
turtle.forward()
turtle.turnRight()
turtle.forward()
turnflag = false
else
turtle.turnLeft()
turtle.forward()
turtle.turnLeft()
turtle.forward()
turnflag = true
end
end
-- now to return to the center of the platform
for i=1,radius do
turtle.forward()
end
turtle.turnLeft()
for i=0,radius do
turtle.back()
end
turtle.up()
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment