Advertisement
TechManDylan

ChatGPT BuildCylinder v0.1

Jan 6th, 2023
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. -- This script will make a turtle build a hollow cylinder with the given radius and height
  2.  
  3. -- Define the function to build the cylinder
  4. function buildCylinder(radius, height)
  5. -- Set the radius of the cylinder
  6. local radius = radius
  7.  
  8. -- Set the height of the cylinder
  9. local height = height
  10.  
  11. -- Move the turtle to the starting position
  12. turtle.up()
  13. turtle.turnLeft()
  14. turtle.turnLeft()
  15. for i=1,radius do
  16. turtle.forward()
  17. end
  18. turtle.turnRight()
  19.  
  20. -- Build the top layer of the cylinder
  21. for i=1,radius*2 do
  22. turtle.placeDown()
  23. turtle.forward()
  24. end
  25. turtle.turnRight()
  26. turtle.forward()
  27. turtle.turnRight()
  28.  
  29. -- Build the sides of the cylinder
  30. for j=2,height do
  31. for i=1,radius*2+1 do
  32. turtle.placeDown()
  33. turtle.forward()
  34. end
  35. turtle.turnRight()
  36. turtle.forward()
  37. turtle.turnRight()
  38. end
  39.  
  40. -- Return the turtle to the starting position
  41. turtle.turnRight()
  42. for i=1,radius+1 do
  43. turtle.forward()
  44. end
  45. turtle.turnLeft()
  46. end
  47.  
  48. -- Test the function by building a cylinder with radius 5 and height 10
  49. buildCylinder(5, 10)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement