require('canvas-testbed')(function(context, width, height, dt) { context.clearRect(0, 0, width, height) background(context, width, height) time += dt if (time > 1000) { time = 0 index ++ // index = 6 next() } camera.setViewport(width, height) orbit() drawFloor(context) context.fillStyle = '#428fc5' context.fill() var shadow3d = to3D(shadowed) drawPath(context, shadow3d) context.globalAlpha = 0.4 context.fillStyle = '#26282a' context.fill() var transformed = to3D(decomposed) drawPath(context, transformed) context.globalAlpha = 1 context.fillStyle = '#fff' context.fill() }, next, {
function orbit() { var cameraRadius = 6 //orbit our camera a little around center var hr = Math.sin(rotation) + Math.PI/2 var x = (Math.cos(hr)) * cameraRadius, z = (Math.sin(hr)) * cameraRadius camera.position.z = 4 camera.position.x = x camera.position.y = -z*0.5 rotation += 0.002 //keep the camera looking at centre of world camera.lookAt(0, 0, 0) camera.up.set(0, 1, 0) camera.update() }
points.forEach(function(p) { var vec = {x:p[0], y:p[1], z:p[2]||0} camera.project(vec, out) result.push([out.x, out.y]) })