canon代码5b00

// 代码开始
// canvas代码
// 请定义canvas相关的全局变量
var canvas, ctx, centerX, centerY, radius = 0;
【canon代码5b00】// 初始化canvas
function initCanvas() {
// 获取Canvas的DOM结点
canvas = document.getElementById(“canvas”);
// 判断当前的浏览器是否支持Canvas
if (!canvas.getContext) {
alert(“当前浏览器不支持canvas”);
return;
}
// 获取绘图上下文
ctx = canvas.getContext(“2d”);
// 中心点位置
centerX = canvas.width / 2;
centerY = canvas.height / 2;
}
// 绘制圆
function drawCircle() {
// 绘制圆
ctx.beginPath();
ctx.arc(centerX, centerY, radius, 0, 2 * Math.PI, false);
ctx.closePath();
// 填充颜色
ctx.fillStyle = ‘#08c’;
ctx.fill();
}
// 更新和清理
function animate() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
drawCircle();
if (radius < 150) {radius += 0.7;}else {radius = 0;}// 循环动画requestAnimationFrame(animate);}// 初始化initCanvas();// 执行动画animate();// 代码结束

    推荐阅读