HTML and CSS Reference
In-Depth Information
z1 = ball.zpos * cos + ball.xpos * sin;
ball.xpos = x1;
ball.zpos = z1;
}
function setPerspective (ball) {
if (ball.zpos > -fl) {
var scale = fl / (fl + ball.zpos);
ball.scaleX = ball.scaleY = scale;
ball.x = vpX + ball.xpos * scale;
ball.y = vpY + ball.ypos * scale;
ball.visible = true;
} else {
ball.visible = false;
}
}
function move (ball, i) {
rotateX(ball, angleX);
rotateY(ball, angleY);
setPerspective(ball);
//don't draw line to first ball
if (i !== 0) {
context.lineTo(balls[i].x, balls[i].y);
}
}
function draw (ball) {
if (ball.visible) {
ball.draw(context);
}
}
(function drawFrame () {
window.requestAnimationFrame(drawFrame, canvas);
context.clearRect(0, 0, canvas.width, canvas.height);
angleX = (mouse.y - vpY) * 0.001;
angleY = (mouse.x - vpX) * 0.001;
context.beginPath();
//line starts at first ball
context.moveTo(balls[0].x, balls[0].y);
balls.forEach(move);
context.stroke();
balls.forEach(draw);
}());
};
</script>
</body>
</html>
Search WWH ::




Custom Search