首页 > 其他 > 详细

canvas基础动画示例

时间:2019-02-10 21:42:44      阅读:174      评论:0      收藏:0      [点我收藏+]

canvas基础动画示例

技术分享图片

本文主要用最简单的例子,展示canvas动画效果是如何实现的

动画效果,是一个球绕着一点旋转

const canvas = document.getElementById(‘canvas‘);
const ctx = canvas.getContext(‘2d‘);
ctx.translate(250, 250);

var count = 2;
function animate() {
    ctx.clearRect(0, 0, 900, 700);  // 清除画布

    ctx.beginPath();
    ctx.rotate((Math.PI / 180) * count);
    ctx.arc(50, 50, 10, 0, Math.PI * 2, true);
    ctx.stroke();
    window.requestAnimationFrame(animate);
}

window.requestAnimationFrame(animate);

canvas基础动画示例

原文:https://www.cnblogs.com/ye-hcj/p/10360305.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!