首页 > 作文

HTML5 Canvas旋转动画的2个代码例子(一个旋转的太极图效果)

更新时间:2023-04-06 16:02:53 阅读: 评论:0

效果图:

方法一:

复制代码 代码如下: <!doctype html>

<html>

<body>

<canvas id=”mycanvas” width=”500″ height=”500″>your browr does not support the canvas tag</canvas>

<script type=”text/javascript”>

var deg = 0;

var r = 30;

var rl = 100;

function drawtaiji() {

var canvas = document.getelementbyid(‘mycanvas’);

var context = canvas.getcontext(‘2d’);

var colora = “rgb(0, 0, 0)”;

var colorb = “red”;

var px =math.sin(deg)*r;

var py =math.cos(deg)*r;

context.clearrect(0, 0, 300, 300);

context.beginpath();

context.fillstyle = colora;

context.arc(rl, rl, 60, 0.5 * math.pi +deg, 1.5 * math.pi +deg, true);

context.clopath();

context.fill();

context.fillstyle = colorb;

context.beginpath();

context.arc(rl, rl, 60, 1.5* math.pi +deg, 0.5 * math.pi +deg, true);

context.clopath();

context.fill();

context.fillstyle = colorb;

context.beginpath();

context.arc(rl+px, rl-py, 30, 0.5 * math.pi + deg, 1.5 * math.pi + deg, true);

context.clopath();

context.fill();

context.fillstyle = colora;

context.beginpath();

context.arc(rl-px, rl+py, 30, 1.5 * math.pi + deg, 0.5 * math.pi + deg, true);

context.clopath();

context.fill();

context.fillstyle = colora;

context.beginpath();

context.arc(rl+px, rl-py, 8, 0, 2 * math.pi, true);

context.clopath();

context.fill();

context.fillstyle = colorb;

context.beginpath();

context.arc(rl-px, rl+py, 8, 0, 2 * math.pi, true);

context.clopath();

context.fill();

deg +=0.1;

}

tinterval(drawtaiji, 100);

</script> </p> <p></body>

</html>

方法二:

复制代码 代码如下:

<!doctype html>

<html>

<body>

<canvas id=”mycanvas” width=”500″ height=”500″ >your brows育才二中er does not support the canvas tag </canvas>

<script type=”text/javascript”>

var canvas = document.getelementbyid(‘mycanvas’德育计划;);

var ctx = canvas.getcontext(“2d”);

var angle = 0;

var count = 360;

var clra = ‘#000’;

var clrb = ‘red’;

function taiji(x, y, radius, angle, wi) {

angleangle = angle || 0;

wiwi = wi ? 1 : -1;

ctx.save();

ctx.translate(x, y);

ctx.rotate(angle);

ctx.fillstyle = clra;

ctx.beginpath();

ctx.arc(0, 0, radius, 0, math.pi, true);

ctx.fill();

ctx.beginpath();

ctx.fillstyle = clrb;

ctx.arc(0, 0, radius, 0, math.pi, fal);

ctx.fill();

ctx.fillstyle = clrb;

ctx.beginpath();

ctx.arc(wi * -0.5 * radius, 0, radius / 2, 0, math.pi * 2, true);

ctx.fill();

ctx.beginpath();

ctx.fillstyle = clra;

ctx.arc(wi * +0.5 * radius, 0, radius / 2, 0, math.pi * 2, fal);

ctx.arc(wi * -0.5 * radius, 0, radius / 10, 0, math.pi * 2, true);

ctx.fill();

ctx.beginpath();

ctx.fillstyle = clrb;

ctx.arc(wi * +0.5 * radius, 0, radius / 10, 0, math.pi * 2, true);

ctx.fill();

ctx.restore();

}

loop = tinterval(function () {

begintag = true;

有你陪伴的日子ctx.clearrect(0, 0, canvas.width, canvas.height);

taiji(200, 200, 50, math.pi * (angle / count) * 2, true);
什么叫自考
//taiji(350, 350, 50, math.pi * ((count – angle) / count) * 2, fal);

angle = (an刚度gle + 5) % count;

}, 50);

</script> </p> <p></body>

</html>

本文发布于:2023-04-06 16:02:51,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/zuowen/87b2abe21fbd7f41cf36b6de2ff68363.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

本文word下载地址:HTML5 Canvas旋转动画的2个代码例子(一个旋转的太极图效果).doc

本文 PDF 下载地址:HTML5 Canvas旋转动画的2个代码例子(一个旋转的太极图效果).pdf

标签:代码   方法   刚度   什么叫
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图