def setup
createCanvas(100, 100, WEBGL)
normalMaterial
@cam1 = createCamera
@cam2 = createCamera
@cam2.setPosition(30, 0, 50)
@cam2.lookAt(0, 0, 0)
@cam2.ortho
# set variable for previously active camera:
@currentCamera = 1
end
def draw
background(200)
# camera 1:
@cam1.lookAt(0, 0, 0)
@cam1.setPosition(sin(frameCount / 60) * 200, 0, 100)
# every 100 frames, switch between the two cameras
if frameCount % 100 == 0
if @currentCamera == 1
setCamera(@cam1)
@currentCamera = 0
else
setCamera(@cam2)
@currentCamera = 1
end
end
drawBoxes
end
def drawBoxes
rotateX(frameCount * 0.01)
translate(-100, 0, 0)
box(20)
translate(35, 0, 0)
box(20)
translate(35, 0, 0)
box(20)
translate(35, 0, 0)
box(20)
translate(35, 0, 0)
box(20)
translate(35, 0, 0)
box(20)
translate(35, 0, 0)
box(20)
end