HTML and CSS Reference
In-Depth Information
ball = new Ball3d(15);
ball.vx = Math.random() * 10 - 5;
ball.vy = Math.random() * 10 - 5;
ball.vz = Math.random() * 10 - 5;
balls.push(ball);
}
function move (ball) {
ball.xpos += ball.vx;
ball.ypos += ball.vy;
ball.zpos += ball.vz;
//check boundaries
if (ball.xpos + ball.radius > right) {
ball.xpos = right - ball.radius;
ball.vx *= -1;
} else if (ball.xpos - ball.radius < left) {
ball.xpos = left + ball.radius;
ball.vx *= -1;
}
if (ball.ypos + ball.radius > bottom) {
ball.ypos = bottom - ball.radius;
ball.vy *= -1;
} else if (ball.ypos - ball.radius < top) {
ball.ypos = top + ball.radius;
ball.vy *= -1;
}
if (ball.zpos + ball.radius > back) {
ball.zpos = back - ball.radius;
ball.vz *= -1;
} else if (ball.zpos - ball.radius < front) {
ball.zpos = front + ball.radius;
ball.vz *= -1;
}
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 draw (ball) {
if (ball.visible) {
ball.draw(context);
}
}
(function drawFrame () {
Search WWH ::




Custom Search