HTML5-黑客帝国2D

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
canvas{
display: block;
}
</style>
</head>

<body>
<canvas id="canvas"></canvas>
<script>
function $(id){
return document.getElementById(id);
}
//画布 的大小设置
var mywindow=window.screen;
var canvas=$("canvas");
canvas.width=mywindow.width;
canvas.height=mywindow.height;

//要输出的信息
var str="0123456789";
str=str.split("");
var fontSize=16;//输出字体的大小
//每列显示多少个信息
var cols=canvas.width/fontSize;
//数组,统计下落的位置
var drops=[];
for(var i=0;i<cols;i++){
drops[i]=1;
}
//
var ctx=canvas.getContext("2d");
function draw(){
/**
*这的黑客帝国:
* 获取页面的 大小 包括宽度和高度
* 用cols获取能够宽度加载列数
* drops加载每一列的位置
* drops[2]=10 2为第二排的 top为10
*/
ctx.fillStyle="rgba(0,0,0,0.05)";
ctx.fillRect(0,0,canvas.width,canvas.height);

ctx.fillStyle="green";
ctx.font=fontSize+"px arial";
for(var i=0;i<cols;i++){

var text=str[ Math.floor( Math.random() * (str.length) ) ];
// console.info("x-"+i*fontSize);
// console.info("y-"+drops[i]*fontSize);
ctx.fillText(text,i*fontSize,drops[i]*fontSize);
if(drops[i]*fontSize > canvas.height || Math.random() > 0.95)
drops[i] = 0;//把位置恢复到最上面
//控制下落的位置
drops[i]++;
}
}
setInterval(draw,33);
</script>
</body>

</html>

转载于:https://www.cnblogs.com/loce/p/5045580.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值