Advertisement
VaMinion

Pyramid Builder

Jun 19th, 2014
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.08 KB | None | 0 0
  1. -- Assume that the turtle starts at the bottom left of the pyramid.
  2.  
  3. turtle_location = vector.new(0,0,0)
  4. turtle_slot = 1
  5.  
  6. function place_block()
  7.   if not turtle.detectDown() then
  8.     while not turtle.placeDown() do
  9.       turtle_slot = turtle_slot + 1
  10.       turtle.select(turtle_slot)
  11.     end
  12.   end
  13. end
  14.  
  15. function lay_side(n_size)
  16.  -- Lays a single side of the pyramid.
  17.  row_count = 0
  18.  while row_count < n_size do
  19.   row_count = row_count + 1
  20.   place_block()
  21.   while not turtle.forward() do
  22.    turtle.dig()
  23.    os.sleep(5)
  24.   end
  25.  end
  26. end
  27.  
  28. function square(n_size)
  29.  n_sides = 0
  30.  while n_sides < 4 do
  31.   lay_side(n_size-1)
  32.   turtle.turnRight()
  33.   n_sides = n_sides + 1
  34.  end
  35. end
  36.  
  37. function pyramid(n_size)
  38.  layer_size = n_size
  39.  while layer_size > 1 do
  40.   square(layer_size)
  41.   turtle.forward()
  42.   turtle.turnRight()
  43.   turtle.forward()
  44.   turtle.turnLeft()
  45.   turtle.up()
  46.   layer_size = layer_size - 2
  47.  end
  48. end
  49.  
  50. function main()
  51.  pyramid_size = 0
  52.  print("Enter size of pyramid.")
  53.   pyramid_size = tonumber(read())
  54.   turtle.up()
  55.   pyramid(pyramid_size)
  56. end
  57.  
  58. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement