Not a member of Pastebin yet?
                        Sign Up,
                        it unlocks many cool features!                    
                - -- https://en.wikipedia.org/wiki/Hilbert_curve
 - -- The Hilbert Curve can be expressed by a rewrite system (L-system).
 - -- Alphabet : A, B
 - -- Constants : F + -
 - -- Axiom : A
 - -- Production rules:
 - -- A → - B F + A F A + F B -
 - -- B → + A F - B F B - F A +
 - -- Here, F means "draw forward", - means "turn left 90°", + means "turn right 90°" (see turtle graphics), and "A" and "B" are ignored during drawing.
 - currentSlot = 1
 - torchInterval = 13 -- Must correspond to lineLength
 - lineLength = 4
 - recursiveDepth = 4
 - repetition = 1
 - distance = 0
 - function A(depth)
 - if depth < 1 then return end
 - print("A" .. depth)
 - turtle.turnLeft()
 - B(depth - 1)
 - F()
 - turtle.turnRight()
 - A(depth - 1)
 - F()
 - A(depth - 1)
 - turtle.turnRight()
 - F()
 - B(depth - 1)
 - turtle.turnLeft()
 - end
 - function B(depth)
 - if depth < 1 then return end
 - print("B" .. depth)
 - turtle.turnRight()
 - A(depth - 1)
 - F()
 - turtle.turnLeft()
 - B(depth - 1)
 - F()
 - B(depth - 1)
 - turtle.turnLeft()
 - F()
 - A(depth - 1)
 - turtle.turnRight()
 - end
 - function F()
 - for i = 1, lineLength do
 - turtle.dig()
 - turtle.forward()
 - turtle.digDown()
 - distance = distance + 1
 - if distance % torchInterval == 0 then
 - if turtle.getItemCount(currentSlot) > 1 then
 - turtle.placeDown()
 - else
 - currentSlot = currentSlot + 1
 - turtle.select(currentSlot)
 - if currentSlot <= 16 and turtle.getItemCount(currentSlot) > 1 then
 - turtle.placeDown()
 - end
 - end
 - end
 - end
 - end
 - -- MAIN
 - -- Fuel completely before starting
 - -- Torches in all slots
 - -- Does not gather resources!
 - turtle.select(1)
 - for i=1, repetition do
 - print("Repetition " .. repetition)
 - A(recursiveDepth)
 - end
 
Advertisement
 
                    Add Comment                
                
                        Please, Sign In to add comment