Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- itemSlot = 16
- x = 0
- y = 0
- z = 0
- -- The following 'face' directions are relative to the starting position of the turtle in this program
- north = 0
- west = 1
- south = 2
- east = 3
- face = north
- length = 9
- width = 9
- interval = 4
- args = {...}
- nArgs = #args
- if nArgs == 0 or (nArgs == 1 and args[1]== "help") then
- print("Lays down a pattern of items of length and width.")
- print("Usage: sprinkle <length> <width>")
- return
- end
- if nArgs ~= 2 then
- print("Usage: sprinkle <distance>")
- return
- end
- length = tonumber(args[1])
- if length == nil then
- print("\"", args[1], "\" is not a valid length")
- return
- end
- if length < 1 then
- print("length must be a positive number greater than zero")
- return
- end
- width = tonumber(args[2])
- if width == nil then
- print("\"", args[1], "\" is not a valid width")
- return
- end
- if width < 1 then
- print("width must be a positive number greater than zero")
- return
- end
- function left()
- if face == 0 then face = 1 turtle.turnLeft() return end
- if face == 1 then face = 2 turtle.turnLeft() return end
- if face == 2 then face = 3 turtle.turnLeft() return end
- if face == 3 then face = 0 turtle.turnLeft() return end
- print("function left\(\): Bad face value: ", face)
- end
- function right()
- if face == 0 then face = 3 turtle.turnRight() return end
- if face == 1 then face = 0 turtle.turnRight() return end
- if face == 2 then face = 1 turtle.turnRight() return end
- if face == 3 then face = 2 turtle.turnRight() return end
- print("function right\(\): Bad face value: ", face)
- end
- function setFace(f)
- if f == 0 then
- if face == 0 then return end
- if face == 1 then right() return end
- if face == 2 then right() right() return end
- if face == 3 then left() return end
- end
- if f == 1 then
- if face == 0 then left() return end
- if face == 1 then return end
- if face == 2 then right() return end
- if face == 3 then right() right() return end
- end
- if f == 2 then
- if face == 0 then left() left() return end
- if face == 1 then left() return end
- if face == 2 then return end
- if face == 3 then right() return end
- end
- if f == 3 then
- if face == 0 then right() return end
- if face == 1 then left() left() return end
- if face == 2 then left() return end
- if face == 3 then return end
- end
- end
- function forward(nBlocks)
- for i=1,nBlocks do
- turtle.forward()
- end
- if face == north then z = z+nBlocks return end
- if face == west then x = x-nBlocks return end
- if face == south then z = z-nBlocks return end
- if face == east then x = x+nBlocks return end
- end
- function layRow(nBlocks)
- turtle.select(itemSlot)
- for i=0,nBlocks do
- if (i % interval) == 0 then
- turtle.placeDown()
- end
- if i < nBlocks then
- forward(1)
- end
- end
- end
- function layPattern(l, w)
- -- setFace(north)
- layRow(w - 1)
- setFace(west)
- layRow(l - 1)
- setFace(south)
- layRow(w - 1)
- setFace(east)
- layRow(l - 1)
- setFace(north)
- end
- radius = interval
- -- Let's let the parent program get to start position
- --[[
- turtle.up()
- turtle.select(itemSlot)
- turtle.placeDown()
- -- Move to starting position
- setFace(north)
- forward(radius)
- setFace(west)
- forward(radius)
- --]]
- layPattern(length, width)
- setFace(north)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement