Skip to content

Instantly share code, notes, and snippets.

@irineujunior
Created December 1, 2021 17:08
Show Gist options
  • Save irineujunior/3e8ad89753ea069a387f1d362c3b7aa2 to your computer and use it in GitHub Desktop.
Save irineujunior/3e8ad89753ea069a387f1d362c3b7aa2 to your computer and use it in GitHub Desktop.
Matrix animation using html5 canvas
<canvas id="c"></canvas>
<!-- definitely not my work!!!!!
just tested this out from http://thecodeplayer.com/walkthrough/matrix-rain-animation-html5-canvas-javascript -->
var c = document.getElementById('c');
var cxt = c.getContext("2d");
c.width = window.innerWidth;
c.height = window.innerHeight;
var chinese = "田由甲申甴电甶男甸甹町画甼甽甾甿畀畁畂畃畄畅畆畇畈畉畊畋界畍畎畏畐畑";
chinese = chinese.split("");
var font_size =10;
var columns = c.width/font_size;
var drops = [];
for(var x=0;x<columns;x++){
drops[x]=1;
}
function draw(){
cxt.fillStyle="rgba(0,0,0,0.05)";
cxt.fillRect(0,0,c.width,c.height);
cxt.fillStyle = "#0F0";
cxt.font = font_size+'px arial';
for(var i=0;i<drops.length;i++){
var text = chinese[Math.floor(Math.random()*chinese.length)];
cxt.fillText(text,i*font_size,drops[i]*font_size);
if(drops[i]*font_size>c.height && Math.random() >0.975)
drops[i]=0;
//increment y coordinate
drops[i]++;
}
}
setInterval(draw,33);
*{margin:0;padding:0;}
canvas{display:block;}
body{background:black;}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment