首页 / CANVAS / canvas仿黑客帝国的字符下落
canvas仿黑客帝国的字符下落
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了canvas仿黑客帝国的字符下落,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1881字,纯文字阅读大概需要3分钟。
内容图文
![canvas仿黑客帝国的字符下落](/upload/InfoBanner/zyjiaocheng/1311/be87705e9799466e9f8aa53e5e1eaa2e.jpg)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
<!DOCTYPE html>
<html lang=
"en"
>
<head>
<meta charset=
"UTF-8"
>
<title>二进制雨</title>
</head>
<body>
<div style=
"color:red;text-align: center;font-size: 20px;"
>二进制雨</div>
<canvas id=
"myCanvas" width= "1000px" height= "600px" style= "background-color: black;" ></canvas> <script>
var draw= function (ctx,x,y,size){
this
.ctx=ctx;
this
.x=x;
this
.y=y;
this
.size=size;
var y1= this .y;
this
.drawText=
function
(){
var str=Math.ceil(Math.random()*10000).toString(2);
var grd= this .ctx.createLinearGradient( this .x, this .y, this .x, this .y- this .ctx.measureText(str).width);
grd.addColorStop(0,
"#00FF00"
);
grd.addColorStop(1,
"#004400"
);
this
.ctx.fillStyle=grd;
this
.ctx.font=
this
.size+
"px Arial"
;
for
(
var i=str.length-1;i>=0;i--) {
this
.ctx.fillText(str.charAt(i),
this
.x, y1-=15);
}
y1=
this
.y+=10;
if
(y1-720+
this
.ctx.measureText(str).width>0){
this
.x=Math.ceil(Math.random()*1000);
y1=
this
.y=Math.ceil(Math.random()*100);
}
}
};
var rain= function (ctx,length){
this
.length=length;
this
.ctx=ctx;
var x=[];
var y=[];
var size=[];
var texts=[];
var i=0;
for
(;i<length;i++){
x[i]=Math.ceil(Math.random()*1000);
y[i]=Math.ceil(Math.random()*500);
size[i]=Math.ceil(Math.random()*15);
texts[i]=
new draw( this .ctx,x[i],y[i],size[i]);
}
this
.run=
function
(){
ctx.clearRect(0,0,1000,600);
for
(
var j=0;j<length;j++){
texts[j].drawText();
}
};
};
var canvas=document.getElementById( "myCanvas" );
var ctx=canvas.getContext( "2d" );
var rain0= new rain(ctx,100);
setInterval(rain0.run,50);
</script>
</body>
</html>
|
原文:http://www.cnblogs.com/startnow/p/5013383.html
内容总结
以上是互联网集市为您收集整理的canvas仿黑客帝国的字符下落全部内容,希望文章能够帮你解决canvas仿黑客帝国的字符下落所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。