Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- This script will make a turtle build a hollow cylinder with the given radius and height
- -- Define the function to build the cylinder
- function buildCylinder(radius, height)
- -- Set the radius of the cylinder
- local radius = radius
- -- Set the height of the cylinder
- local height = height
- -- Move the turtle to the starting position
- turtle.up()
- turtle.turnLeft()
- turtle.turnLeft()
- for i=1,radius do
- turtle.forward()
- end
- turtle.turnRight()
- -- Build the top layer of the cylinder
- for i=1,radius*2 do
- turtle.placeDown()
- turtle.forward()
- end
- turtle.turnRight()
- turtle.forward()
- turtle.turnRight()
- -- Build the sides of the cylinder
- for j=2,height do
- for i=1,radius*2+1 do
- turtle.placeDown()
- turtle.forward()
- end
- turtle.turnRight()
- turtle.forward()
- turtle.turnRight()
- end
- -- Return the turtle to the starting position
- turtle.turnRight()
- for i=1,radius+1 do
- turtle.forward()
- end
- turtle.turnLeft()
- end
- -- Test the function by building a cylinder with radius 5 and height 10
- buildCylinder(5, 10)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement