旋转的辐射Logo

本文介绍了一种使用HTML canvas元素动态绘制圆环的方法,通过调整起点和终点的角度,实现圆环的平滑过渡和动画效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

var canvas = document.getElementById("myCanvas");
var context = canvas.getContext("2d");
var startP = [0 , 0.67 , 1.34 ];
var endP = [0.3 , 0.97 , 1.64];
var n = 0.01;
var animate;
window.onload = initPage;

function initPage() {
    var speed = document.getElementsByTagName("select")[0].value;
    window.clearInterval(animate);
    animate = setInterval("show()",speed);
}

function show() {
    context.clearRect(0,0,500,500);
    for(var i = 0 ; i<3 ; i++) {
	startP[i] += n;
	endP[i] += n;
	if(startP[i] == 2) {
	    startP[i] = 0;
	}
	if(endP[i] == 2) {
	    endP[i] = 0;
	}
    }
    context.beginPath();
    context.rect(0,0,500,500);
    context.lineWidth = 1;
    context.fillStyle = "#F2CA07";
    context.fill();
    context.stroke();

    context.beginPath();
    context.arc(250, 250, 10, 0, 2 * Math.PI, false);
    context.lineWidth = 1;
    context.fillStyle = "#333";
    context.fill();
    context.stroke();

    context.beginPath();
    context.arc(250, 250, 100, startP[0] * Math.PI, endP[0] * Math.PI, false);
    context.lineWidth = 160;
    context.strokeStyle = "#333";
    context.stroke();

    context.beginPath();
    context.arc(250, 250, 100, startP[1] * Math.PI, endP[1] * Math.PI, false);
    context.lineWidth = 160;
    context.strokeStyle = "#333";
    context.stroke();

    context.beginPath();
    context.arc(250, 250, 100, startP[2] * Math.PI, endP[2] * Math.PI, false);
    context.lineWidth = 160;
    context.strokeStyle = "#333";
    context.stroke();
}



Demo



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值