-
Notifications
You must be signed in to change notification settings - Fork 1
/
h5_screenSave.html
104 lines (94 loc) · 3.3 KB
/
h5_screenSave.html
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<style>
*{margin: 0;padding: 0;}
body{overflow: hidden;}
#can{background: #000000;}
</style>
<script>
function rnd(n,m){
return parseInt(Math.random()*(m-n))+n;
}
window.onload=function(){
var oCan=document.querySelector('#can');
var gd=oCan.getContext('2d');
oCan.width=document.documentElement.clientWidth;
oCan.height=document.documentElement.clientHeight;
var N=5;
var oW=1;
var oH=1;
var aPoint=[];
for(var i=0;i<N;i++){
var x=rnd(0,oCan.width-oW);
var y=rnd(0,oCan.height-oH);
aPoint[i]={x:x,y:y,iSpeedX:rnd(-5,5),iSpeedY:rnd(-5,5)};
gd.strokeRect(aPoint[i].x,aPoint[i].y,oW,oH);
}
gd.strokeStyle='white';
gd.moveTo(aPoint[0].x,aPoint[0].y);
for(var i=1;i<aPoint.length;i++){
gd.lineTo(aPoint[i].x,aPoint[i].y);
}
gd.closePath();
gd.stroke();
var oldPoint=[];
setInterval(function(){
gd.clearRect(0,0,oCan.width,oCan.height);
for(var i=0;i<aPoint.length;i++){
aPoint[i].x+=aPoint[i].iSpeedX;
aPoint[i].y+=aPoint[i].iSpeedY;
if(aPoint[i].x<0){
aPoint[i].x=0;
aPoint[i].iSpeedX*=-1;
}
if(aPoint[i].y<0){
aPoint[i].y=0;
aPoint[i].iSpeedY*=-1;
}
if(aPoint[i].x>oCan.width-oW){
aPoint[i].x=oCan.width-oW;
aPoint[i].iSpeedX*=-1;
}
if(aPoint[i].y>oCan.height-oH){
aPoint[i].y=oCan.height-oH;
aPoint[i].iSpeedY*=-1;
}
gd.strokeRect(aPoint[i].x,aPoint[i].y,oW,oH);
}
var arr=[];
gd.beginPath();
//gd.strokeStyle='white';
arr[0]={x:aPoint[0].x,y:aPoint[0].y};
gd.moveTo(aPoint[0].x+oW/2,aPoint[0].y+oH/2);
for(var i=1;i<aPoint.length;i++){
gd.lineTo(aPoint[i].x+oW/2,aPoint[i].y+oH/2);
arr[i]={x:aPoint[i].x,y:aPoint[i].y};
}
oldPoint.push(arr);
if(oldPoint.length>50){
oldPoint.shift();
}
gd.closePath();
gd.stroke();
for(var i=0;i<oldPoint.length;i++){
var scale=i/oldPoint.length;
gd.beginPath();
gd.strokeStyle='rgba(255,255,255,'+scale+')';
gd.moveTo(oldPoint[i][0].x,oldPoint[i][0].y);
for(var j=1;j<N;j++){
gd.lineTo(oldPoint[i][j].x,oldPoint[i][j].y);
}
gd.closePath();
gd.stroke();
}
},16);
};
</script>
</head>
<body>
<canvas id="can"></canvas>
</body>
</html>