zoukankan      html  css  js  c++  java
  • canvas点阵函数波动,类似飘带或水波

    canvas动画利用函数波动特点制作水波动画

    <canvas id="myCanvas" width="500" height="400" style="border:0px double #996633;"></canvas>


    var canvas = document.getElementById('myCanvas');
    var ctx = canvas.getContext('2d');
    var i=0;
    setInterval(move,30);
    function move(){

      ctx.clearRect(0,0,canvas.width,canvas.height);

      var dig=Math.PI/24;
      var colorArr = ['red','yellow','green','blue','purple']
      var colorIndex = 0
      for (k=0;k<=14;k++){

        for (n=0;n<=17;n++){
          colorIndex++
          if (colorIndex >= 5) {
            colorIndex = 0
          }
          ctx.fillStyle = colorArr[colorIndex]
          x0=30*n;
          y0=30*k;
          var x=24*Math.sin((i+k*2+n*3)*dig)+x0;
          var y=24*Math.cos((i+k*2+n*3)*dig)+y0;
          ctx.beginPath();
          ctx.arc(x,y,8,0,Math.PI*2,true);
          ctx.closePath();
          ctx.fill();
        }
       }

       i=i+1;
       if (i>=48) i=0;
     }

    直接可复制代码查看效果

  • 相关阅读:
    几个概率题
    几个智力题。。
    [算法]各种二分查找
    深入 JavaScript 时间对象 Date
    Leaflet 调用百度瓦片地图服务
    JavaScript中进制和字符编码问题
    DOM事件流
    flex 弹性布局
    javascript 闭包内部机制
    HTML DOM setAttribute()、与createAttribute()
  • 原文地址:https://www.cnblogs.com/zyz-s/p/13322537.html
Copyright © 2011-2022 走看看