抖音爆火的 黑客帝國,代碼雨
01、在桌面新建一個(gè)文件夾,命名為黑客帝國代碼雨。

02、在文件夾內(nèi)新建一個(gè)文本文檔。
03、將新建文本文檔命名為代碼雨。
04、將以下代碼復(fù)制到文本中:<canvas id="canvas" style="background:black" width="620" height="340"></canvas><audio style="display:none; height: 0" id="bg-music" preload="auto" src="music/黑客帝國.mp3"></audio><style type="text/css">body{margin: 0; padding: 0; overflow: hidden;}</style><script type="text/javascript">window.onload = function(){//獲取圖形對象var canvas = document.getElementById("canvas");//獲取圖形的上下文var context = canvas.getContext("2d");//獲取瀏覽器屏幕的寬度和高度var W = window.innerWidth;var H = window.innerHeight;//設(shè)置canvas的寬度和高度canvas.width = W;canvas.height = H;//每個(gè)文字的字體大小var fontSize = 15;//計(jì)算列var colunms = Math.floor(W /fontSize);//記錄每列文字的y軸坐標(biāo)var drops = [];//給每一個(gè)文字初始化一個(gè)起始點(diǎn)的位置for(var i=0;i<colunms;i++){drops.push(0);}//運(yùn)動(dòng)的文字var str ="01abcdefghijklmnopqurstuvwxyz";//4:fillText(str,x,y);原理就是去更改y的坐標(biāo)位置//繪畫的函數(shù)function draw(){//讓背景逐漸由透明到不透明context.fillStyle = "rgba(0,0,0,0.05)";context.fillRect(0,0,W,H);//給字體設(shè)置樣式//context.font = "700 "+fontSize+"px 微軟雅黑";context.font = fontSize + 'px arial';//給字體添加顏色context.fillStyle ="green";//隨意更改字體顏色//寫入圖形中for(var i=0;i<colunms;i++){var index = Math.floor(Math.random() * str.length);var x = i*fontSize;var y = drops[i] *fontSize;context.fillText(str[index],x,y);//如果要改變時(shí)間,肯定就是改變每次他的起點(diǎn)if(y >= canvas.height && Math.random() > 0.92){drops[i] = 0;}drops[i]++;}};function randColor(){var r = Math.floor(Math.random() * 256);var g = Math.floor(Math.random() * 256);var b = Math.floor(Math.random() * 256);return "rgb("+r+","+g+","+b+")";}draw();setInterval(draw,33);};</script>
05、直接復(fù)制代碼,后綴名改為:.html ,直接運(yùn)行就可以看到效果啦!