Canvas绘制平抛小球效果
2016-09-11 16:41
357 查看
4000
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <style type="text/css"> canvas { border-bottom: 10px solid orange; } </style> </head> <body> <canvas id="space" width="1200" height="500"></canvas> <script type="text/javascript"> var myCanvas = document.getElementById("space"); var ctx = myCanvas.getContext("2d"); var x = 10,y = 10; var g = 9.8 / 100, t = -0.85, v = 0; function freeFall() { ctx.clearRect(0, 0, 1200, 500); ctx.beginPath(); ctx.arc(x, y, 10, 0, Math.PI * 2, false); ctx.closePath(); ctx.fillStyle = "red"; ctx.fill(); v += g; y += v; x += 1; if(y >= myCanvas.height - 10) { y = myCanvas.height - 10; v *= t; } if(x >= 1190) { x = 1190; window.location.reload() } window.requestAnimationFrame(freeFall); } freeFall() </script> </body> </html>
相关文章推荐
- HTML5利用Canvas绘制图形(使用图像、裁剪区域、使用文本。阴影效果和操作像素)
- JavaScript+html5 canvas绘制的圆弧荡秋千效果完整实例
- 绘制canvas彩色泡泡小球碰撞
- Canvas绘制小球运动,检测碰撞变色
- canvas绘制圆环百分比进度的动态效果
- JS+canvas绘制的动态机械表动画效果
- [js高手之路]html5 canvas动画教程 - 边界判断与小球粒子模拟喷泉,散弹效果
- JavaScript+html5 canvas绘制的小人效果
- rainday.js实现canvas绘制下雨的效果
- canvas绘制的小效果
- js实现canvas绘制的图形的拖动效果
- canvas绘制万花筒效果(代码分享)
- Canvas绘制页面小球跳动
- canvas绘制简易百分比圆饼效果
- Canvas 绘制矩形,圆形,不规则图形(线条),渐变等图像效果
- JavaScript+html5 canvas绘制缤纷多彩的三角形效果完整实例
- Canvas实战---模仿GOOGLE浮动小球效果
- Android Canvas绘制炫酷效果
- JavaScript Canvas绘制圆形时钟效果
- SurfaceView与Canvas的结合实现简单的图形绘制与动画效果