效果如下:

Canvas实现放射线动画效果

代码如下:

<!DOCTYPE html>
<html>
 <head>
 <meta charset="UTF-8">
 <title></title>
 <style>
 body {background: #000;overflow: hidden;margin: 0;padding: 0;}
 #canv {width: 45%;margin: 5% 30%;animation: wheel-rotate 30s linear infinite;}
 @keyframes wheel-rotate {
 from {
 transform: rotate(0deg);
 }
 to {
 transform: rotate(360deg);
 }
 }
 </style>
 </head>
 <body>
 <canvas id="canv" width="600" height="600"></canvas>
 <script type="text/javascript">
 var c;
 var $;
 var w = 600;
 var h = 600;
 constant = 15;
 var rad = 300;
 var timeout = 0;
 c = document.getElementById("canv");
 $ = c.getContext("2d");
 drawLines();
 function drawLines() {
 $.fillRect(0,0,w,h);
 $.translate(w/2,h/2);
 for (var i = 0; i < 25; i++) {
 for (var n = -45; n <= 45; n+=constant) {
 setTimeout("draw("+n+");",100 * timeout);
 timeout++;
 }
 }
 }
 function draw(n){
 $.beginPath();
 $.moveTo(0,rad);
 var radians = Math.PI/180*n;
 var x = (rad * Math.sin(radians)) / Math.sin(Math.PI/2 - radians);
 $.lineTo(x,0);
 if (Math.abs(n) == 45) {
 $.strokeStyle=rndColor();
 $.lineWidth=2;
 } else if (n == 0) {
 $.strokeStyle="rgb(200,200,200)";
 $.lineWidth=.5;
 } else {
 $.strokeStyle="rgb(110,110,110)";
 $.lineWidth=.5;
 }
 $.stroke();
 $.rotate((Math.PI/180)*15);
 }
 function rndColor() {
 var r = 255*Math.random()|0,
  g = 255*Math.random()|0,
  b = 255*Math.random()|0;
 return 'rgb(' + r + ',' + g + ',' + b + ')';
 }
 function myrefresh(){
  //window.location.reload();
  //drawLines()
 }
 //setTimeout('myrefresh()',100*175);
 </script>
 </body>
</html>

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持!

标签:
canvas,动画

免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
狼山资源网 Copyright www.pvsay.com

评论“Canvas实现放射线动画效果”

暂无“Canvas实现放射线动画效果”评论...