Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Assume that the turtle starts at the bottom left of the pyramid.
- turtle_location = vector.new(0,0,0)
- turtle_slot = 1
- function place_block()
- if not turtle.detectDown() then
- while not turtle.placeDown() do
- turtle_slot = turtle_slot + 1
- turtle.select(turtle_slot)
- end
- end
- end
- function lay_side(n_size)
- -- Lays a single side of the pyramid.
- row_count = 0
- while row_count < n_size do
- row_count = row_count + 1
- place_block()
- while not turtle.forward() do
- turtle.dig()
- os.sleep(5)
- end
- end
- end
- function square(n_size)
- n_sides = 0
- while n_sides < 4 do
- lay_side(n_size-1)
- turtle.turnRight()
- n_sides = n_sides + 1
- end
- end
- function pyramid(n_size)
- layer_size = n_size
- while layer_size > 1 do
- square(layer_size)
- turtle.forward()
- turtle.turnRight()
- turtle.forward()
- turtle.turnLeft()
- turtle.up()
- layer_size = layer_size - 2
- end
- end
- function main()
- pyramid_size = 0
- print("Enter size of pyramid.")
- pyramid_size = tonumber(read())
- turtle.up()
- pyramid(pyramid_size)
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement