-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.html
372 lines (312 loc) · 13.3 KB
/
test.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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
<!DOCTYPE html>
<html>
<head>
</head>
<body id="body">
<p>Test</p>
<svg width="1000" height="500" viewBox="-250 -250 1000 500">
<circle id="g0" cx="0" cy="0" r="100" stroke="black" fill="none"/>
<circle id="c1" cx="0" cy="-100" r="100" stroke="gray" fill="none" visibility="hidden"/>
<circle id="c2" cx="86.602540378443864676372317075294" cy="-50" r="173.20508075688772935274463415059" stroke="gray" fill="none" visibility="hidden"/>
<line id="l1b" x1="-1000" y1="577.35026918962576450914878050195746" x2="1000" y2="-577.35026918962576450914878050195746" stroke="lightgray" visibility="hidden"/>
<line id="l1" x1="0" y1="0" x2="86.602540378443864676372317075294" y2="-50" stroke="gray" visibility="hidden"/>
<line id="l2b" x1="-1000" y1="-900" x2="1000" y2="1100" stroke="lightgray" visibility="hidden"/>
<line id="l2" x1="-63.397459621556135323627682924706382" y1="36.602540378443864676372317075293618" x2="0" y2="100" stroke="gray" visibility="hidden"/>
<line id="l3b" x1="-1000" y1="900" x2="1000" y2="-1100" stroke="lightgray" visibility="hidden"/>
<line id="l3" x1="-100" y1="0" x2="0" y2="-100" stroke="gray" visibility="hidden"/>
<line id="l4b" x1="-1000" y1="1100" x2="1000" y2="-900" stroke="lightgray" visibility="hidden"/>
<line id="l4" x1="0" y1="100" x2="236.60254037844386467637231707529362" y2="-136.60254037844386467637231707529362" stroke="gray" visibility="hidden"/>
<line id="l5b" x1="-1000" y1="-1100" x2="1000" y2="900" stroke="lightgray" visibility="hidden"/>
<line id="l5" x1="0" y1="-100" x2="100" y2="0" stroke="gray" visibility="hidden"/>
<line id="fl1" x1="0" y1="-100" x2="100" y2="0" stroke="darkorange" stroke-width="2" visibility="hidden"/>
<line id="fl2" x1="100" y1="0" x2="0" y2="100" stroke="darkorange" stroke-width="2" visibility="hidden"/>
<line id="fl3" x1="0" y1="100" x2="-100" y2="0" stroke="darkorange" stroke-width="2" visibility="hidden"/>
<line id="fl4" x1="-100" y1="0" x2="0" y2="-100" stroke="darkorange" stroke-width="2" visibility="hidden"/>
<circle id="g1" cx="0" cy="0" r="2.5" stroke="black" fill="white"/>
<circle id="g2" cx="0" cy="-100" r="2.5" stroke="black" fill="white"/>
<circle id="p1" cx="86.602540378443864676372317075294" cy="-50" r="2.5" stroke="black" fill="white" visibility="hidden"/>
<circle id="p2" cx="-86.602540378443864676372317075294" cy="-50" r="2.5" stroke="black" fill="white" visibility="hidden"/>
<circle id="p3" cx="-63.397459621556135323627682924706382" cy="36.602540378443864676372317075293618" r="2.5" stroke="black" fill="white" visibility="hidden"/>
<circle id="p4" cx="0" cy="100" r="2.5" stroke="black" fill="white" visibility="hidden"/>
<circle id="p5" cx="-100" cy="0" r="2.5" stroke="black" fill="white" visibility="hidden"/>
<circle id="p6" cx="236.60254037844386467637231707529362" cy="-136.60254037844386467637231707529362" r="2.5" stroke="black" fill="white" visibility="hidden"/>
<circle id="p7" cx="100" cy="0" r="2.5" stroke="black" fill="white" visibility="hidden"/>
<circle id="fp1" cx="0" cy="-100" r="3" stroke="darkorange" stroke-width="2" fill="white" visibility="hidden"/>
<circle id="fp2" cx="100" cy="0" r="3" stroke="darkorange" stroke-width="2" fill="white" visibility="hidden"/>
<circle id="fp3" cx="0" cy="100" r="3" stroke="darkorange" stroke-width="2" fill="white" visibility="hidden"/>
<circle id="fp4" cx="-100" cy="0" r="3" stroke="darkorange" stroke-width="2" fill="white" visibility="hidden"/>
<circle id="m1" cx="0" cy="0" r="3" stroke="red" stroke-width="2" fill="yellow" visibility="hidden"/>
<circle id="m2" cx="0" cy="0" r="3" stroke="red" stroke-width="2" fill="yellow" visibility="hidden"/>
</svg>
</body>
<script>
var AnimationEngine = (function () {
//protect this pointer
var _this = this;
//private variable
var doc;
var sceneLinkedList = { head: null };
var frameId;
var stopped;
var resumeScene = {};
var init = function () {
doc = document; //for later use
frameId = -1;
stopped = true;
document.getElementById("body").onclick = togglePause;
addScene(new showHideScene(["g0", "g1", "g2"], ["c1", "c2", "l1b", "l1", "l2b", "l2", "l3b", "l3", "l4b", "l4", "l5b", "l5", "fl1", "fl2", "fl3", "fl4", "p1", "p2", "p3", "p4", "p5", "p6", "p7", "fp1", "fp2", "fp3", "fp4", "m1", "m2"], 50));
addScene(new hilightMarkerScene([{id: "m1", x: 0, y: -100}, {id: "m2", x: 0, y:0}], 50));
addScene(new circleScene("m1", 0, -100, "m2", 0, 0, "c1", 100));
addScene(new showHideScene([], [], 50));
addScene(new showHideScene(["p1", "p2"], [], 50));
addScene(new showHideScene([], ["m1", "m2"], 50));
addScene(new hilightMarkerScene([{id: "m1", x: 86.602540378443864676372317075294, y: -50}, {id: "m2", x: -86.602540378443864676372317075294, y: -50}], 50));
addScene(new circleScene("m1", 86.602540378443864676372317075294, -50, "m2", -86.602540378443864676372317075294, -50, "c2", 100));
addScene(new showHideScene([], [], 100));
addScene(new hilightMarkerScene([{id: "m1", x: 0, y: 0}, {id: "m2", x: 86.602540378443864676372317075294, y: -50}], 50));
addScene(new lineScene("m1", 0, 0, "m2", 86.602540378443864676372317075294, -50, "l1", "l1b", 100));
addScene(new showHideScene([], [], 50));
addScene(new showHideScene(["p3", "p4"], [], 50));
addScene(new hilightMarkerScene([{id: "m1", x: -63.397459621556135323627682924706382, y: 36.602540378443864676372317075293618}, {id: "m2", x: 0, y: 100}], 50));
addScene(new lineScene("m1", -63.397459621556135323627682924706382, 36.602540378443864676372317075293618, "m2", 0, 100, "l2", "l2b", 100));
addScene(new showHideScene([], [], 50));
addScene(new showHideScene(["p5"], [], 50));
addScene(new hilightMarkerScene([{id: "m1", x: -100, y: 0}, {id: "m2", x: 0, y: -100}], 50));
addScene(new lineScene("m1", -100, 0, "m2", 0, -100, "l3", "l3b", 100));
addScene(new showHideScene([], [], 50));
addScene(new showHideScene(["p6"], [], 50));
addScene(new hilightMarkerScene([{id: "m1", x: 0, y: 100}, {id: "m2", x: 236.60254037844386467637231707529362, y: -136.60254037844386467637231707529362}], 50));
addScene(new lineScene("m1", 0, 100, "m2", 236.60254037844386467637231707529362, -136.60254037844386467637231707529362, "l4", "l4b", 100));
addScene(new showHideScene([], [], 50));
addScene(new showHideScene(["p7"], [], 50));
addScene(new hilightMarkerScene([{id: "m1", x: 0, y: -100}, {id: "m2", x: 100, y: 0}], 50));
addScene(new lineScene("m1", 0, -100, "m2", 100, 0, "l5", "l5b", 100));
addScene(new showHideScene([], ["m1", "m2"], 50));
addScene(new showHideScene(["fl1", "fl2", "fl3", "fl4", "fp1", "fp2", "fp3", "fp4"], [], 150));
resumeScene = sceneLinkedList.head;
togglePause();
}
function addScene(scene) {
if(sceneLinkedList.head == null) {
sceneLinkedList.head = scene;
sceneLinkedList.head.next = scene;
sceneLinkedList.head.prev = scene;
} else {
var prv = sceneLinkedList.head.prev;
scene.next = prv.next;
scene.prev = prv;
prv.next = scene;
scene.next.prev = scene;
}
}
function togglePause()
{
if(stopped) {
stopped = false;
requestAnimationFrame(resumeScene.animate);
resumeScene = null;
} else {
stopped = true;
}
}
var showHideScene = function (showIdList, hideIdList, frame) {
var _this = this;
var showElemList = [], hideElemList = [];
_this.next = null;
_this.prev = null;
var init = function() {
if(Array.isArray(showIdList) && Array.isArray(hideIdList)) {
var elem;
for(var s in showIdList) {
elem = doc.getElementById(showIdList[s]);
if(elem != null) showElemList.push(elem);
}
for(var h in hideIdList) {
elem = doc.getElementById(hideIdList[h]);
if(elem != null) hideElemList.push(elem);
}
}
}
_this.animate = function() {
if(stopped) {
resumeScene = _this;
} else {
if(++frameId >= frame) {
frameId = -1;
requestAnimationFrame(_this.next.animate);
} else {
if(frameId == 0) {
for(var s in showElemList) showElemList[s].setAttribute("visibility", "visible");
for(var h in hideElemList) hideElemList[h].setAttribute("visibility", "hidden");
}
requestAnimationFrame(_this.animate);
}
}
}
init();
}
var hilightMarkerScene = function (markerParams, frame) {
var _this = this;
var markers = [];
_this.next = null;
_this.prev = null;
var init = function() {
if(Array.isArray(markerParams)) {
var elem;
for(var m in markerParams) {
elem = doc.getElementById(markerParams[m].id);
if(elem != null) markers.push({e: elem, x: markerParams[m].x, y: markerParams[m].y});
}
}
}
_this.animate = function() {
if(stopped) {
resumeScene = _this;
} else {
if(++frameId >= frame) {
frameId = -1;
requestAnimationFrame(_this.next.animate);
} else {
if(frameId == 0) {
for(var m in markers) {
var cur = markers[m];
cur.e.setAttribute("visibility", "visible");
cur.e.setAttribute("cx", cur.x);
cur.e.setAttribute("cy", cur.y);
}
}
requestAnimationFrame(_this.animate);
}
}
}
init();
}
var lineScene = function (markerId1, x1, y1, markerId2, x2, y2, lineId, lineBackId, frame) {
var _this = this;
var m1, m2, l, lb;
var xt = [], yt = [];
_this.next = null;
_this.prev = null;
var init = function() {
m1 = doc.getElementById(markerId1);
m2 = doc.getElementById(markerId2);
l = doc.getElementById(lineId);
lb = doc.getElementById(lineBackId);
if(m1 != null && m2 != null && l != null) {
for(var i=0; i<frame; i++) {
xt.push(x1+i/(frame-1)*(x2-x1));
yt.push(y1+i/(frame-1)*(y2-y1));
}
}
}
_this.animate = function() {
if(stopped) {
resumeScene = _this;
} else {
if(++frameId >= frame) {
frameId = -1;
if(lb != null) lb.setAttribute("visibility", "visible");
requestAnimationFrame(_this.next.animate);
} else {
m2.setAttribute("cx", xt[frameId]);
m2.setAttribute("cy", yt[frameId]);
l.setAttribute("x2", xt[frameId]);
l.setAttribute("y2", yt[frameId]);
if(frameId == 0) {
m1.setAttribute("cx", x1);
m1.setAttribute("cy", y1);
l.setAttribute("x1", x1);
l.setAttribute("y1", y1);
//backline calculation is a problem, wait for later solve
m1.setAttribute("visibility", "visible");
m2.setAttribute("visibility", "visible");
l.setAttribute("visibility", "visible");
if(lb != null) lb.setAttribute("visibility", "hidden");
}
requestAnimationFrame(_this.animate);
}
}
}
init();
}
var circleScene = function (markerId1, x1, y1, markerId2, x2, y2, circleId, frame) {
var _this = this;
var m1, m2, c;
var xt = [], yt = [], rt = [];
_this.next = null;
_this.prev = null;
var init = function() {
m1 = doc.getElementById(markerId1);
m2 = doc.getElementById(markerId2);
c = doc.getElementById(circleId);
if(m1 != null && m2 != null) {
var finalr = Math.sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
for(var i=0; i<frame; i++) {
xt.push(x1+i/(frame-1)*(x2-x1));
yt.push(y1+i/(frame-1)*(y2-y1));
rt.push(i/(frame-1)*finalr);
}
}
}
_this.animate = function() {
if(stopped) {
resumeScene = _this;
} else {
if(++frameId >= frame) {
frameId = -1;
requestAnimationFrame(_this.next.animate);
} else {
m2.setAttribute("cx", xt[frameId]);
m2.setAttribute("cy", yt[frameId]);
c.setAttribute("r", rt[frameId]);
if(frameId == 0) {
m1.setAttribute("cx", x1);
m1.setAttribute("cy", y1);
c.setAttribute("cx", x1);
c.setAttribute("cy", y1);
m1.setAttribute("visibility", "visible");
m2.setAttribute("visibility", "visible");
c.setAttribute("visibility", "visible");
}
requestAnimationFrame(_this.animate);
}
}
}
init();
}
var pointMoveScene = function (elemId, x0, y0, x1, y1, frame) {
var _this = this;
var elem;
var xt = [], yt = [];
_this.next = null;
_this.prev = null;
var init = function() {
elem = doc.getElementById(elemId);
if(elem.nodeName != "circle") elem = null;
if(elem != null) {
for(var i=0; i<frame; i++) {
xt.push(x0+i/(frame-1)*(x1-x0));
yt.push(y0+i/(frame-1)*(y1-y0));
}
}
}
_this.animate = function() {
if(stopped) {
resumeScene = _this;
} else {
if(++frameId >= frame) {
frameId = -1;
requestAnimationFrame(_this.next.animate);
} else {
elem.setAttribute("cx", xt[frameId]);
elem.setAttribute("cy", yt[frameId]);
requestAnimationFrame(_this.animate);
}
}
}
init();
}
init();
}());
</script>
</html>