-
Notifications
You must be signed in to change notification settings - Fork 2
/
demo.html
112 lines (99 loc) · 3.54 KB
/
demo.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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Path Demo</title>
<style>
*{margin:0;padding:0}
body{font:14px/24px "Microsoft YaHei"}
form div{padding:10px 0;overflow:hidden;_zoom:1}
form p, form label, form input{float:left}
form p, form label{padding:0 10px;height:24px}
form input{margin:0;padding:2px 10px;outline:none;border:1px solid #333;width:60px;height:18px;line-height:18px}
form input:focus{border-color:#09f}
form button{margin-left:10px}
#box{position:relative;width:20px;height:20px;background-color:#069;border-radius:2px}
</style>
</head>
<body>
<form>
<div><p>开始点 :</p></div>
<div><label>x :</label><input id="begin-pos-x" type="text" /> <label>y :</label><input id="begin-pos-y" /> <label>z :</label><input id="begin-pos-z" /></div>
<div><p>结束点 :</p></div>
<div><label>x :</label><input id="end-pos-x" type="text" /> <label>y :</label><input id="end-pos-y" /> <label>z :</label><input id="end-pos-z" /></div>
<div><p>控制点1 :</p></div>
<div><label>x :</label><input id="cp1-pos-x" type="text" /> <label>y :</label><input id="cp1-pos-y" /> <label>z :</label><input id="cp1-pos-z" /></div>
<div><p>控制点2 :</p></div>
<div><label>x :</label><input id="cp2-pos-x" type="text" /> <label>y :</label><input id="cp2-pos-y" /> <label>z :</label><input id="cp2-pos-z" /></div>
<div><button id="draw-line" type="submit">画直线</button><button id="draw-curve" type="submit">画曲线</button></div>
</form>
<div id="box"></div>
<script type="text/javascript" src="Path.js"></script>
<script type="text/javascript">
document.getElementById('draw-line').onclick = function(event){
event.preventDefault();
draw('line');
return false;
}
document.getElementById('draw-curve').onclick = function(){
event.preventDefault();
draw('curve');
return false
}
var timer, path;
function draw(type){
var beginX, beginY, beginZ,
endX, endY, endZ,
cp1X, cp1Y, cp1Z,
cp2X, cp2Y, cp2Z,
box, step;
if(timer){
clearInterval(timer);
timer = null;
path = null;
}
beginX = document.getElementById('begin-pos-x').value || 0;
beginY = document.getElementById('begin-pos-y').value || 0;
beginZ = document.getElementById('begin-pos-z').value || 0;
endX = document.getElementById('end-pos-x').value || 100;
endY = document.getElementById('end-pos-y').value || 0;
endZ = document.getElementById('end-pos-z').value || 0;
cp1X = document.getElementById('cp1-pos-x').value || 0;
cp1Y = document.getElementById('cp1-pos-y').value || 100;
cp1Z = document.getElementById('cp1-pos-z').value || 0;
cp2X = document.getElementById('cp1-pos-x').value || 100;
cp2Y = document.getElementById('cp1-pos-y').value || 100;
cp2Z = document.getElementById('cp1-pos-z').value || 0;
type = type || 'line';
path = new Path('box', null, 'position');
path.beginPath([beginX, beginY, beginZ], 0);
if(type == 'line'){
path.lineTo([endX, endY, endZ], 200);
path.stay(200);
path.lineTo([beginX, beginY, beginZ], 200);
}else{
path.curveTo(
[endX, endY, endZ],
[cp1X, cp1Y, cp1Z],
[cp2X, cp2Y, cp2Z],
200);
path.stay(200);
path.curveTo(
[beginX, beginY, beginZ],
[cp2X, cp2Y, cp2Z],
[cp1X, cp1Y, cp1Z],
200);
}
step = 0;
timer = setInterval(function(){
path.update(step);
if(step++ > 600){
clearInterval(timer);
timer = null;
path = null;
}
}, 2);
}
</script>
</body>
</html>