-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestSin.html
154 lines (130 loc) · 3.08 KB
/
testSin.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<!DOCTYPE html>
<html>
<head>
<title></title>
<style type="text/css">
body,html {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f3f3f3;
}
</style>
</head>
<body>
<canvas id="canvas"></canvas>
</body>
<script type="text/javascript">
var W = window.innerWidth,
H =window.innerHeight;
var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d');
window.onresize = function(){
// console.log(11)
W = window.innerWidth,
H =window.innerHeight;
resize();
};
resize();
var ss = 40,
T = 200,
ww = Math.PI*2/T,
Ao,
dd = 0; //x方向间隔
// //bezier波动
// // Ao = (W/2 - Math.abs(W/2 - W/2))/(5+ss/10);
// // var p1 = {
// // x: W/2+dd,
// // y: ~~Ao*Math.sin((W/2- W/2-T/4 - ss*5)*ww)
// // },
// // p2 = {
// // x: W/2-dd,
// // y: ~~Ao*Math.sin((W/2- W/2-T/4 + ss*5)*ww)
// // },
// // p3 = getP3(p1, p2);
// // ctx.beginPath();
// // ctx.strokeStyle = '#bdd4cc';
// // ctx.moveTo(p1.x,p1.y+H/2+0.5);
// // ctx.quadraticCurveTo(p3.x,p3.y+H/2+0.5, p2.x,p2.y+H/2+0.5);
// // ctx.stroke();
// // ctx.closePath();
var len1 = len2 = 0;
go()
function go(){
len1 = (len1> H )? H :(len1 += 2);
len2 = (len2> H )? H :(len2 += 2.5);
ctx.clearRect(0,0,W,H);
drawLine(len1, 200);
drawLine(len2, 300);
ss += 1;
window.requestAnimationFrame(go);
};
function drawLine(len,posX){
//右侧波动
ctx.beginPath();
// ctx.moveTo(0, H/2+0.5);
ctx.strokeStyle = '#bdd4cc';
for (var i = 0; i <= len ; i++) {
var A = 80;
var A = 80*((H/2 - Math.abs(i - H/2)) /H/2);
// console.log( (H/2 - Math.abs(i - H/2))/(H/2) )
// var A = (H/2 - Math.abs(i - H/2)/H/2)/(5+ss/10);
var y = ~~A*Math.sin((i- H/2-T/4 - ss*5)*ww );
ctx.lineTo( posX+0.5+y,i);
};
ctx.stroke();
ctx.closePath();
}
function getP3(p1, p2){
var k1 = Ao*ww*Math.cos((p1.x- W/2-T/4 - ss*5)*ww),
k2 = Ao*ww*Math.cos((p2.x- W/2-T/4 + ss*5)*ww),
b1 = p1.y - k1*p1.x,
b2 = p2.y - k2*p2.x;
console.log(k1)
return {
x: (b2-b1)/(k1-k2),
y: (b2*k1-b1*k2)/(k1-k2)
}
}
// begin(600,0 );
window.onmousedown = function(e){
var s_x = e.clientX,
s_y = e.clientY;
(Math.abs(s_x-W/2)<20) && (window.onmousemove = function(e){
var d_x = e.clientX,
d_y = e.clientY;
var delt = Math.abs(d_x-W/2)>120 ? 120*(d_x-W/2)/Math.abs(d_x-W/2):d_x-W/2;
begin(d_y, delt);
e.preventDefault();
})
window.onmouseup = function(e){
window.onmousemove = window.onmouseup = null;
};
// console.log(x)
}
function begin(x, delt){
ctx.clearRect(0,0,W,H);
ctx.beginPath();
// ctx.moveTo(0, H/2+0.5);
ctx.strokeStyle = '#bdd4cc';
for (var i = 0; i < H; i++) {
var A = -delt/2,
midX = x,
T = Math.abs(10*A),
ww = (A==0) ? 0 :Math.PI*2/T;
A = (~~Math.abs(i-midX) >= ~~T/2) ? 0 :A;
// console.log(A)
y = A*Math.sin((i-(midX-T)-T/4)*ww) - A;
ctx.lineTo( W/2+0.5+y,i);
};
ctx.stroke();
ctx.closePath();
}
function resize(){
canvas.width = W;
canvas.height = H;
canvas.style.width = W;
canvas.style.height = H;
};
</script>
</html>