javascript canvas 生成蕾丝花边

本文介绍了一种利用HTML5 Canvas元素结合数学函数和斐波那契数列递归算法来创建动态视觉效果的方法。通过实时更新画布上的圆形位置和颜色,实现了随时间变化的动态图案生成。代码中运用了三角函数、随机数生成和颜色随机化技术,为读者提供了深入理解Canvas绘图和动态视觉设计的机会。

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

var canvas=document.createElement("canvas");
                canvas.setAttribute("style","background:#000");
                canvas.width=document.body.clientWidth,canvas.height=document.body.clientHeight;
                document.body.appendChild(canvas);
                ctx=canvas.getContext("2d");
                w=document.body.offsetWidth,h=document.body.offsetHeight;
                function dwg(xs,ys,g){
                
                ctx.beginPath();
                ctx.strokeStyle=g;
              ctx.arc(w/2+ys,h/2+xs+50,20,0,Math.PI*2);
               
                ctx.stroke();
                ctx.closePath();}
                var f=0;
                function recursion(n){
                    this.x=1,this.y=1,this.arr=[1,1],this.sum=0;
                    for(var p=0;p<n;p+=1){
                        this.sum=this.x+this.y;
                        this.x=this.y;
                        this.y=this.sum;
                        this.arr.push(this.sum);
                    }
                    return this.arr;
                }
      
              function random(n,n1){
                  if(n<n1){
                      [n,n1]=[n1,n]
                  }
                  return Math.floor(Math.random()*(n-n1+1)+n);
              }

              function randoms(){
                  return "rgb("+Math.floor(Math.random()*255)+","+Math.floor(Math.random()*255)+","+Math.floor(Math.random()*255)+")";
              }    

              var xc=recursion(12);    
            var  x=0,r=0,z=0;
               setInterval(function(){
                   x=x+1;
                   r=r+.1;
               
             
                    dwg(Math.sin(x)*r,Math.cos(x)*r,"#fff");
                   
                },1000/100);
        </script>        

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值