小鱼55555
2017-10-30 19:30
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<canvas id="canvas"></canvas>
<script type="text/javascript">
var ball={x:512,y:100,r:20,g:2,vx:-4,vy:0,color:"black"}
window.onload = function() {
var canvas = document.getElementById("canvas");
canvas.width = 1024;
canvas.height = 768;
var context = canvas.getContext("2d");
setInterval(
function() {
render(context);
update();
},
50
)
}
function update() {
ball.x += ball.vx;
ball.y += ball.vy;
ball.vy += ball.g;
if(ball.y>=768-ball.r){
ball.y = 768-ball.r;
ball.vy-=ball.vy*0.5;
}
}
function render(cxt) {
cxt.clearRect(0,0,cxt.canvas.width,cxt.canvas.height)
cxt.fillStyle = ball.color
cxt.beginPath
cxt.arc(ball.x,ball.y,ball.r,0,2*Math.PI)
cxt.closePath
cxt.fill()
}
</script>
</body>
</html>
cxt.beginPath();
cxt.closePath();
——注意必须要括号!!
炫丽的倒计时效果Canvas绘图与动画基础
96746 学习 · 1000 问题
相似问题