黑客帝国雨效果JS。

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
*{margin: 0;padding: 0;}
body{overflow: hidden;}
canvas{background: #111;}
</style>
</head>
<body>
<canvas id="canvas"></canvas>
<script>
var canvas = document.getElementById("canvas");
var context = canvas.getContext("2d"); var W = window.innerWidth;
var H = window.innerHeight; canvas.width = W;
canvas.height = H; var fontSize = 16;
//计算列
var colunm = Math.floor(W/fontSize);
//console.log(colunm);
//存储Y值
var drops = []; for(var i = 0;i<colunm;i++){
drops[i] = 1;
}
//console.log(...drops)
var str = "Welcome JavaScript"; //let tempRandom = Math.random()*str.length;
//console.log(tempRandom,Math.floor(tempRandom))
//把文字画到屏幕上
function draw(){
context.fillStyle = "rgba(0,0,0,0.05)";//文字随机出现的背景
context.fillRect( 0, 0, W, H);
context.font = "700 " + fontSize + "px ARIAL";
context.fillStyle = "#00cc33";
//context.fillStyle = randColor();
//console.log("你好");
for(var i = 0; i<colunm; i++){
//让字符串中的内容随机出现
var index = Math.floor(Math.random()*str.length);
var x = i*fontSize;
var y = drops[i]*fontSize;
context.fillText(str[index],x,y);
console.log(str[index],x,y);
if(y>=canvas.height && Math.random()>0.99){
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,20);
</script>
</body>
</html>

效果截图:

最新文章

  1. spring springMVC
  2. Fedora下依赖库的解决
  3. php中redis的安装
  4. 教你一招:解决安装或卸载office时 提示错误2503 2502 发生了内部错误
  5. {POJ}{3897}{Maze Stretching}{二分答案+BFS}
  6. HTML5夜空烟花绽放动画效果
  7. MongoDb学习1
  8. MyBatis复习
  9. Estimating Project Costs
  10. 关于HTML的Element
  11. iOS xcode8提交 iOS10 “此构建版本无效” (已解决)
  12. Linux学习笔记----(2)
  13. jquery_ajax
  14. Linq表连接大全(INNER JOIN、LEFT OUTER JOIN、RIGHT OUTER JOIN、FULL OUTER JOIN、CROSS JOIN)
  15. UGUI 过渡动画插件,模仿NGUI的Tween (转载)
  16. RMAN备份各种物理文件
  17. Java EE (2) -- Java EE 6 Enterprise JavaBeans Developer Certified Expert(1z0-895)
  18. 导出Mysql数据库中的数据
  19. Python中的枚举
  20. SpringBoot整合系列-整合JPA

热门文章

  1. odoo学习之:【转】控制menuitem的显示权限
  2. python 布尔值 bool( ) 与逻辑运算符
  3. [Vani有约会]雨天的尾巴 线段树合并
  4. 记Thinkpad的一次扩容升级经历
  5. Linux TCP/IP调优参数 /proc/sys/net/目录
  6. nmap保存结果
  7. Pairs Forming LCM LightOJ - 1236 素因子分解
  8. Python爬虫入门(3-4):Urllib库的高级用法
  9. struts通配符*的使用
  10. tensorflow训练线性回归模型