Last active
February 6, 2016 18:19
-
-
Save SquidLord/4744268 to your computer and use it in GitHub Desktop.
ComputerCraft turtle code for building a circular platform. Rectangular laying path.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- v. 1.0 : Not the most efficient way of doing a circle--I just do a square | |
-- grid, and if the turtle is outside the radius, it just skips laying a block. | |
-- I hope in later versions, I'll manage to make a spiral pattern so we don't have to go over empty blocks. | |
-- v. 1.1 : It will start now know the correct center of the circle...it's moving too far back | |
-- 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 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) <= 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 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment