Canvas copies the characters of the matrix and canvas copies the matrix.

Source: Internet
Author: User
Tags drawtext

Canvas copies the characters of the matrix and canvas copies the matrix.
?

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 <!DOCTYPE html>"en">    <meta charset="UTF-8">    <Title> binary rain </title><body><div style="color:red;text-align: center;font-size: 20px;"> Binary rain </div><canvas id="myCanvas" width="1000px" height="600px" style="background-color: black;"></canvas><script>      var draw=function(ctx,x,y,size){        this.ctx=ctx;        this.x=x;        this.y=y;        this.size=size;        var y1=this.y;        this.drawText=function(){            var str=Math.ceil(Math.random()*10000).toString(2);            var grd=this.ctx.createLinearGradient(this.x,this.y,this.x,this.y-this.ctx.measureText(str).width);            grd.addColorStop(0,"#00FF00");            grd.addColorStop(1,"#004400");            this.ctx.fillStyle=grd;            this.ctx.font=this.size+"px Arial";            for(var i=str.length-1;i>=0;i--) {                this.ctx.fillText(str.charAt(i), this.x, y1-=15);            }            y1=this.y+=10;            if(y1-720+this.ctx.measureText(str).width>0){                this.x=Math.ceil(Math.random()*1000);                y1=this.y=Math.ceil(Math.random()*100);            }        }    };      var rain=function(ctx,length){        this.length=length;        this.ctx=ctx;        var x=[];        var y=[];        var size=[];        var texts=[];        var i=0;        for(;i<length;i++){            x[i]=Math.ceil(Math.random()*1000);            y[i]=Math.ceil(Math.random()*500);            size[i]=Math.ceil(Math.random()*15);            texts[i]=new draw(this.ctx,x[i],y[i],size[i]);        }        this.run=function(){            ctx.clearRect(0,0,1000,600);            for(var j=0;j<length;j++){                texts[j].drawText();            }        };      };      var canvas=document.getElementById("myCanvas");    var ctx=canvas.getContext("2d");    var rain0=new rain(ctx,100);    setInterval(rain0.run,50);  </script></body>    

 

This is the result of the previous blog. The phone cannot be viewed .... Http://blog.chinaunix.net/uid-30494608-id-5201548.html

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.