Skip to content

Instantly share code, notes, and snippets.

@Dms-Codee
Created December 8, 2022 02:43
Show Gist options
  • Select an option

  • Save Dms-Codee/74b322d13c094ae9e443cf9ebf643f29 to your computer and use it in GitHub Desktop.

Select an option

Save Dms-Codee/74b322d13c094ae9e443cf9ebf643f29 to your computer and use it in GitHub Desktop.
Efecto-Matrix-CSS-JS
<canvas id="canvas"></canvas>
const canvas = document.getElementById('canvas');
const ctx= canvas.getContext('2d');
canvas.width = document.body.offsetWidth;
const w=canvas.width;
const h=canvas.height;
ctx.fillStyle='#000';
ctx.fillRect(0,0,w,h);
const cols = Math.floor(w/20)+1;
const position_y = Array(cols).fill(0);
function matrix(){
// Capa de la letra
ctx.fillStyle ='#0001';
ctx.fillRect(0,0,w,h);
// Estilos de los caracteres
ctx.fillStyle = 'yellow';
ctx.font = '8pt Papyrus';
// Se obtiene la posicion de cada columna y un indice
position_y.forEach((y,index)=>{
const text= String.fromCharCode(Math.random()*128);
const x= index*20;
ctx.fillText(text,x,y);
if(y>100+Math.random()*10000){
position_y[index]= 0;
}else{
position_y[index]= y+20;
}
})
}
setInterval(matrix,80);
canvas{
width: 100%;
height: 100%;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment