Debian Codegraph @

tests/svg/corpus/1.svg

raw symbols SCIP
1
2 <?xml version="1.0" standalone="no"?>
3 <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
4 <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="600" height="600" onload="NewGame()">
5 <title>Steps</title>
6 <script type="text/ecmascript">
7 <![CDATA[
8 var svgNS = "http://www.w3.org/2000/svg";
9 var xlinkNS = "http://www.w3.org/1999/xlink";
10
11 var Objects=new Array();
12 var Pos=new Array();
13 var Directions=new Array();
14 var Moves=new Array();
15
16 var gLevel=1;
17 var gIsMoving='False';
18 var gMoveInterval=100;
19
20 function NewGame()
21 {
22 var Object;
23 var b=Objects.length;
24 for(var a=2;a<b;a++)
25 {
26 Object=document.getElementById(a);
27 if(Object)
28 Object.parentNode.removeChild(Object);
29 }
30
31 Object=document.getElementById('Player');
32 if(Object)
33 Object.parentNode.removeChild(Object);
34
35 Object=document.getElementById('Target');
36 if(Object)
37 Object.parentNode.removeChild(Object);
38
39 Object=document.getElementById('Skull');
40 if(Object)
41 Object.parentNode.removeChild(Object);
42
43 Objects=new Array();
44 Pos=new Array();
45 Directions=new Array();
46 gLevel=1;
47 document.getElementById('Level').firstChild.nodeValue='Level: 1';
48
49 NewObject('Player');
50 NewObject('Target');
51 NewObject('Arrow');
52 NewObject('Arrow');
53 }
54
55 function NewObject(Object)
56 {
57 var ArrayPos=Objects.length;
58 var a=NewPosition();
59 Pos[ArrayPos]=a;
60 var NewObject=document.createElementNS(svgNS,"use");
61 NewObject.setAttribute("x",0);
62 NewObject.setAttribute("y",0);
63
64 if(Object=='Arrow')
65 {
66 Objects[ArrayPos]='Arrow';
67 var b=Math.round(Math.random()*7);
68 Directions[ArrayPos]=b;
69 NewObject.setAttribute("id",ArrayPos);
70 NewObject.setAttributeNS(xlinkNS,"href","#arrow");
71 NewObject.setAttribute("transform", "translate("+(a%8)*50+","+Math.floor(a/8)*50+") rotate("+b*45+",25,25)");
72 Moves[ArrayPos]=CalculateMoves(a,b);
73 }
74 else if(Object=='Player')
75 {
76 Objects[ArrayPos]='Player';
77 NewObject.setAttribute("id",'Player');
78 NewObject.setAttributeNS(xlinkNS,"href","#player");
79 NewObject.setAttribute("transform", "translate("+(a%8)*50+","+Math.floor(a/8)*50+")");
80 }
81 else if (Object=='Target')
82 {
83 Objects[ArrayPos]='Target';
84 NewObject.setAttribute("id",'Target');
85 NewObject.setAttributeNS(xlinkNS,"href","#target");
86 NewObject.setAttribute("transform", "translate("+(a%8)*50+","+Math.floor(a/8)*50+")");
87 NewObject.setAttribute("onclick", "ClickTarget()");
88 }
89 else if (Object=='Skull')
90 {
91 Objects[ArrayPos]='Skull';
92 NewObject.setAttribute("id",'Skull');
93 NewObject.setAttributeNS(xlinkNS,"href","#skull");
94 NewObject.setAttribute("transform", "translate("+(Pos[0]%8)*50+","+Math.floor(Pos[0]/8)*50+")");
95 }
96
97 document.getElementById("board").appendChild(NewObject);
98 }
99
100 function NewPosition()
101 {
102 var a=Math.round(Math.random()*63);
103 while(!EmptySquare(a) || a==Pos[0] || a==Pos[1])
104 {
105 a++;
106 if(a==64)
107 a=0;
108 }
109 return (a);
110 }
111
112 function EmptySquare(ThisPos)
113 {
114 var EmptySquare=new Boolean(true);
115
116 // Pos[0]=player, Pos[1]=target so start from Pos[2]
117 var b=Pos.length;
118 for(var a=2;a<b;a++)
119 {
120 if(Pos[a]==ThisPos)
121 EmptySquare=false;
122 }
123 return(EmptySquare);
124 }
125
126 // Returns a list of available squares that this arrow will
127 // move through as a comma delimmeted string
128 function CalculateMoves(a,Dir)
129 {
130 var MyMoves='';
131 MyMoves+=a;
132
133 for(var b=0;b<7;b++)
134 {
135 switch(Dir)
136 {
137 case 0: // East
138 if(a%8==7)
139 a=a-7
140 else
141 a++;
142 break;
143 case 1: // South East
144 if(a==63)
145 a=0
146 else if(a>55)
147 a=a-55
148 else if(a%8==7)
149 a++
150 else
151 a=a+9;
152 break;
153 case 2: // South
154 if(a>55)
155 a=a-56
156 else
157 a=a+8;
158 break;
159 case 3: // South West
160 if(a==56)
161 a=7
162 else if(a>55)
163 a=a-57
164 else if(a%8==0)
165 a=a+15
166 else
167 a=a+7;
168 break;
169 case 4: // West
170 if(a%8==0)
171 a=a+7
172 else
173 a--;
174 break;
175 case 5: // North West
176 if(a==0)
177 a=63
178 else if(a<8)
179 a=a+55
180 else if(a%8==0)
181 a--
182 else
183 a=a-9;
184 break;
185 case 6: // North
186 if(a<8)
187 a=a+56
188 else
189 a=a-8;
190 break;
191 case 7: // North East
192 if(a==7)
193 a=56
194 else if(a<8)
195 a=a+57
196 else if(a%8==7)
197 a=a-15
198 else
199 a=a-7;
200 break;
201 }
202
203 MyMoves+=','+a;
204 }
205
206 return (MyMoves);
207 }
208
209 function ClickTarget()
210 {
211 var CurPos=Pos[0];
212 var NewPos=Pos[1];
213 if((CurPos%8!=7 && NewPos==CurPos+1) || (CurPos%8!=0 && NewPos==CurPos-1) || (CurPos>7 && NewPos==CurPos-8) || (CurPos<56 && NewPos==CurPos+8) )
214 MovePlayer(NewPos);
215 }
216
217 function CheckSquare(evt)
218 {
219 var XPos=evt.clientX;
220 var YPos=evt.clientY;
221 var NewPos=(Math.floor((YPos-50)/50)*8)+(Math.floor((XPos-50)/50));
222 var CurPos=Pos[0];
223
224 if(EmptySquare(NewPos) && ((CurPos%8!=7 && NewPos==CurPos+1) || (CurPos%8!=0 && NewPos==CurPos-1) || (CurPos>7 && NewPos==CurPos-8) || (CurPos<56 && NewPos==CurPos+8)) )
225 MovePlayer(NewPos);
226 }
227
228 function KeyPress(evt)
229 {
230 var CurPos=Pos[0];
231 var NewPos=-1;
232
233 if(evt.keyCode==37 && CurPos%8!=0) // West
234 {
235 evt.preventDefault();
236 NewPos=CurPos-1;
237 }
238 if(evt.keyCode==38 && CurPos>7) // North
239 {
240 evt.preventDefault();
241 NewPos=CurPos-8;
242 }
243 if(evt.keyCode==39 && CurPos%8!=7) // East
244 {
245 evt.preventDefault();
246 NewPos=CurPos+1;
247 }
248 if(evt.keyCode==40 && CurPos<56) // South
249 {
250 evt.preventDefault();
251 NewPos=CurPos+8;
252 }
253
254 if(NewPos!=-1 && EmptySquare(NewPos))
255 MovePlayer(NewPos);
256 }
257
258 function MovePlayer(NewPos)
259 {
260 if(gIsMoving=='False')
261 {
262 gIsMoving='True';
263 var Object=document.getElementById('Player');
264 Pos[0]=NewPos;
265 Object.setAttribute("transform", "translate("+(NewPos%8)*50+","+Math.floor(NewPos/8)*50+")");
266 var ColResult=CheckCollision('Player',NewPos);
267 if(ColResult=='NextLevel')
268 {
269 Pos[1]=NewPosition();
270 window.setTimeout("document.getElementById('Target').setAttribute(\"transform\", \"translate(\"+(Pos[1]%8)*50+\",\"+Math.floor(Pos[1]/8)*50+\")\")",2*gMoveInterval);
271 window.setTimeout("NewObject('Arrow')",5*gMoveInterval);
272 window.setTimeout("NewObject('Arrow')",7*gMoveInterval);
273 gLevel++;
274 document.getElementById('Level').firstChild.nodeValue='Level: '+gLevel;
275 window.setTimeout("gIsMoving='False'",7*gMoveInterval);
276 }
277 else
278 Move();
279 }
280 }
281
282 function Move()
283 {
284 var a=2;
285 var b=Objects.length;
286 while(a<b)
287 {
288 window.setTimeout("Animate("+a+")",a*gMoveInterval);
289 a++;
290 }
291 window.setTimeout("gIsMoving='False'",a*gMoveInterval);
292 }
293
294 function Animate(a)
295 {
296 var Object=document.getElementById(a);
297 var b=Pos[a];
298 var MyMoves=Moves[a];
299 MyArray=MyMoves.split(',');
300
301 var c=0;
302 while(MyArray[c]!=b)
303 c++;
304
305 var d=1;
306 b=MyArray[(c+d)%8];
307 while(CheckCollision(Objects[a],b)=='SkipTile' && d<8)
308 {
309 d++;
310 b=MyArray[(c+d)%8];
311 }
312 Pos[a]=b;
313 Object.setAttribute("transform", "translate("+(b%8)*50+","+Math.floor(b/8)*50+") rotate("+Directions[a]*45+",25,25)");
314
315
316 if(CheckCollision(Objects[a],b)=='GameOver')
317 {
318 Object.parentNode.removeChild(Object);
319 Object=document.getElementById('Player');
320 Object.parentNode.removeChild(Object);
321 NewObject('Skull');
322 window.setTimeout("NewGame()",2000);
323 }
324 }
325
326 function CheckCollision(Object,NewPos)
327 {
328 var Result='none';
329 var a=0;
330 var b=Pos.length;
331 while(a<b && Result=='none')
332 {
333 if(Pos[a]==NewPos)
334 {
335 if(Object=='Player' && Objects[a]=='Target')
336 Result='NextLevel';
337 else if(Object=='Arrow' && Objects[a]=='Player')
338 Result='GameOver'
339 else if(Object=='Arrow' && (Objects[a]=='Arrow' || Objects[a]=='Target'))
340 Result='SkipTile';
341 }
342 a++;
343 }
344 return (Result);
345 }
346
347 function SetInst()
348 {
349 var Object=document.getElementById('Instructions');
350 if(Object.getAttribute('visibility')=='hidden')
351 Object.setAttribute('visibility','visible');
352 else
353 Object.setAttribute('visibility','hidden');
354 }
355
356 function SetAnimate()
357 {
358 var Object=document.getElementById('AnimateCheck');
359 if(Object.getAttribute('visibility')=='hidden')
360 {
361 Object.setAttribute('visibility','visible');
362 gMoveInterval=100;
363 }
364 else
365 {
366 Object.setAttribute('visibility','hidden');
367 gMoveInterval=0;
368 }
369 }
370
371 document.documentElement.addEventListener("keydown",KeyPress,false)
372
373 ]]>
374 </script>
375
376 <defs>
377 <symbol id="arrow">
378 <path d="M5,15 H25 V5 L45,25 L25,45 V35 H5 z" fill="none" stroke="#ff6666" stroke-width="5" stroke-linejoin="round" />
379 </symbol>
380
381 <symbol id="player">
382 <circle cx="25" cy="25" r="20" stroke="black" stroke-width="2" fill="red"/>
383 </symbol>
384
385 <symbol id="target">
386 <rect x="5" y="5" r="20" width="40" height="40" stroke="black" stroke-width="2" fill="red"/>
387 </symbol>
388
389 <symbol id="skull">
390 <g stroke="#000000">
391 <g fill="#ffffff" stroke-width="1">
392 <path id="bone1" d="M 13.6,41.4 C 13.2,41.9 12.8,42.5 12.5,43.1 C 12.3,43.5 11.9,43.8 11.6,44.1 C 10.9,44.7 10.1,44.7 9.8,43.7 C 9.7,42.8 9.7,42.2 9.5,41.4 C 9,40.9 8.5,40.6 7.9,40 C 7.4,39.5 7.4,38.8 8,38.3 C 10.3,37.6 10.2,38.7 12,38.2 C 14.3,37.4 39.2,27.8 41.2,26.8 C 42.4,25.8 42.1,24.8 43.1,24.1 C 44.1,23.2 44.7,23.4 45.1,23.9 C 45.4,24.8 45.6,25.7 45.5,26.5 C 46.5,27.4 47,27.8 47.5,28.6 C 47.6,29.6 46.7,30 45.7,30 C 44.3,30.2 44.1,29.4 42.5,30 L 13.6,41.4 z " />
393 <path id="bone2" d="M 9,26.7 C 7.8,25.8 8.2,24.7 6.7,23.9 C 6.1,23.6 5.6,23.4 5.1,24.3 C 4.8,25 4.8,25.8 4.7,26.6 C 4.2,27.2 3.5,27.6 3,28.3 C 2.4,29.4 3.4,29.7 4,29.9 C 5.6,30.3 6.1,29.6 7.6,29.9 L 36.8,41.1 C 38.1,42.2 37.6,43.2 38.5,43.8 C 39.4,44.6 39.9,44.7 40.4,44 C 40.9,43.2 40.8,42.3 40.9,41.4 C 41.5,40.8 42,40.5 42.5,39.9 C 43.1,39.3 43.1,38.8 42.2,38.3 C 41.5,38.1 40.8,37.9 40,38.2 C 39.4,38.3 38.9,38.4 38.1,38.1 C 38.1,38.1 11.3,27.9 9,26.7 z " />
394 <path id="main outline" d="M 24.2,41.3 C 22.5,41.3 21.5,41.1 20,40.6 C 18.5,40 17,38.2 16.6,36.7 C 16.3,35.6 16.2,34.2 16.5,33.1 C 16.4,31.6 15.8,30.3 14.2,25.7 C 11.5,20.9 10.4,18.2 10.2,15.3 C 10,12.1 11.8,8.9 14.4,7 C 17.4,5 22.3,4.5 25.3,4.6 C 27.4,4.6 32,5.7 33.6,6.8 C 36.5,8.9 38,11.7 38.1,15 C 38.3,18.3 36.9,20.8 34.1,25.6 C 32.5,30.3 31.9,31.6 31.8,33.1 C 32.1,34.2 32,35.6 31.7,36.7 C 31.4,38.2 29.8,40 28.3,40.6 C 26.8,41.1 25.9,41.3 24.1,41.3" />
395 <path id="left side" d="M 13.3,13.3 C 12.6,13.9 12.7,14.7 12.8,16 C 12.9,17 13.5,18 13.6,18.8 C 13.8,20.7 13.2,22.6 13,24.1 C 12.8,25.9 13.3,27.4 14,28 C 14.7,28.6 15.5,28.8 16.4,29.1 C 17.3,29.3 17.7,29.6 18.3,30.1 C 19.1,30.9 19.2,31.5 19.2,32.3" />
396 <path id="right side" d="M 35.1,13.3 C 35.8,13.8 35.7,14.7 35.6,16 C 35.5,16.9 34.9,17.9 34.8,18.8 C 34.6,20.7 35.2,22.5 35.4,24.1 C 35.6,25.8 35.1,27.3 34.4,27.9 C 33.8,28.5 32.5,28.8 32,29 C 31.4,29.2 30.7,29.6 30.1,30.1 C 29.4,30.7 29.2,31.5 29.2,32.2" />
397 </g>
398
399 <g fill="none" stroke-width="0.4">
400 <path id="left jaw outline" d="M 16.7,29.5 C 17.2,30.6 17.4,31 17.7,32.2 C 18,33.2 18.1,33.8 18.3,35.3" />
401 <path id="right jaw outline" d="M 31.6,29.4 C 31.1,30.5 31,31 30.6,32.1 C 30.3,33.1 30.2,33.8 30,35.2" />
402 <path id="upper teeth outline" d="M 18.8,32.1 C 20.1,32.9 22.3,33 24.3,32.9 C 26.5,32.9 28.4,32.8 29.6,32.1" />
403 <path id="middle teeth outline" d="M 19.3,34.1 C 20.7,34.9 22.3,35.2 24.2,35.2 C 26.2,35.1 27.7,35 29.1,34.1" />
404 <path id="lower teeth outline" d="M 18.2,35.1 C 19.7,36.9 21.8,37.2 24.2,37.3 C 26.8,37.3 29.4,36.4 30,35.1" />
405 <path id="teeth vert" d="M 19.2,32.5 L 19.2,36 M 20.4,32.9 L 20.4,36.6 M 21.7,33 L 21.7,36.9 M 22.9,33.1 L 22.9,37 M 24.2,33.1 L 24.2,37.1 M 25.5,33.1 L 25.5,37.1 M 26.6,33 L 26.6,36.9 M 27.9,32.8 L 27.9,36.5 M 29.1,32.3 L 29.1,35.8" />
406 </g>
407
408 <g fill="#000000" stroke="none">
409 <path id="left eye" d="M 16.7,19.8 C 17.9,19.6 19,19.5 20.2,19.4 C 21.7,19 22.5,20.7 22.1,22 C 21.5,23.1 20.8,24.1 19.9,25 C 19.3,25.8 18.5,25.9 17.7,25.6 C 17.1,25.5 16.6,25.1 16,24.3 C 15.7,23.5 15.5,23.2 15.1,22.3 C 14.9,21.4 15.3,20.2 16.7,19.8 z " />
410 <path id="right eye" d="M 31.6,19.8 C 30.5,19.6 29.3,19.5 28.2,19.4 C 26.6,19 25.9,20.7 26.3,22 C 26.8,23.1 27.6,24.1 28.4,25 C 29.1,25.8 29.9,25.9 30.6,25.6 C 31.2,25.5 31.8,25.1 32.4,24.3 C 32.7,23.5 32.9,23.2 33.2,22.3 C 33.5,21.4 33.1,20.2 31.6,19.8 z " />
411 <path id="left nostril" d="M 23.9,24.5 C 23,25.2 22.8,25.4 22.4,26.1 C 22.2,26.3 21.9,26.9 21.8,27.4 C 21.7,27.8 21.7,28.4 21.7,28.7 C 21.7,29.8 22,30.4 22.4,30.4 C 22.8,30.4 23.2,30 23.9,29.2" />
412 <path id="right nostril" d="M 24.5,24.6 C 25.3,25.2 25.5,25.4 26,26.1 C 26.1,26.3 26.4,27 26.5,27.4 C 26.6,27.8 26.7,28.4 26.7,28.7 C 26.7,29.8 26.3,30.5 25.9,30.4 C 25.6,30.4 25.2,30.1 24.5,29.3" />
413 </g>
414 </g>
415
416 </symbol>
417
418 </defs>
419
420 <g transform="translate(50,50)">
421
422 <g id="board" style="fill:#99ff99;stroke:#6666cc;stroke-width:3">
423 <rect id="Background" x="0" y="0" width="400" height="400" rx="10" ry="10" onclick="CheckSquare(evt)" />
424 <path id="Grid" fill="none" d="M50,0 V400 M100,0 V400 M150,0 V400 M200,0 V400 M250,0 V400 M300,0 V400 M350,0 V400 M0,50 H400 M0,100 H400 M0,150 H400 M0,200 H400 M0,250 H400 M0,300 H400 M0,350 H400" />
425 </g>
426
427
428 <g id="text" fill="#66f" font-family="sans-serif">
429
430 <g id="title" stroke="#000000" stroke-width="3" fill="#ff6666" font-weight="bold" font-size="150">
431 <text x="430" y="90">S</text>
432 <text x="440" y="190">T</text>
433 <text x="450" y="270">E</text>
434 <text x="430" y="370">P</text>
435 <text x="440" y="460">S</text>
436 </g>
437
438 <text id="Level" x="0" y="450" font-size="40" font-weight="bold" > </text>
439
440 <text x="230" y="425" onclick="SetInst()" font-size="16" font-weight="bold" cursor="pointer">Instructions</text>
441 <g id="checkbox">
442 <text x="230" y="450" onclick="SetAnimate()" font-size="16" font-weight="bold" >Animate Arrows</text>
443 <rect x="360" y="438" onclick="SetAnimate()" width="15" height="15" rx="1" ry="1" style="fill:#ffffff;stroke:#6666cc;stroke-width:2"/>
444 <path id="AnimateCheck" onclick="SetAnimate()" fill="none" stroke="#ff6666" stroke-width="5" stroke-linejoin="round" d="M358,441 L366,450 L378,435" />
445 </g>
446
447 </g>
448
449 <g id="Instructions" visibility="hidden" font-family="sans-serif" font-size="16" fill="#333333">
450 <rect x="0" y="0" width="400" height="400" rx="10" ry="10" fill="#ffffff"/>
451 <text x="15" y="50" font-weight="bold">Instructions:</text>
452 <text x="15" y="70">Steps is a turn based game where you must move</text>
453 <text x="15" y="90">the red circle to the red square while avoiding the</text>
454 <text x="15" y="110">arrows.</text>
455 <text x="15" y="150">You can move 1 square at a time either up, down,</text>
456 <text x="15" y="170">left or right using the mouse or the arrow keys. You</text>
457 <text x="15" y="190">move first, then each of the arrows will move in turn</text>
458 <text x="15" y="210">onto the next available square in the direction they</text>
459 <text x="15" y="230">are pointing. When an arrow reaches the edge of</text>
460 <text x="15" y="250">the board it will wrap around onto the opposite edge.</text>
461 <text x="15" y="270">With each new level the number of arrows increases.</text>
462 <text x="15" y="300">Good luck!</text>
463 <text x="100" y="300" onclick="SetInst()" fill="#66f" text-decoration="underline" cursor="pointer" font-weight="bold">Close</text>
464 </g>
465
466
467
468 </g>
469
470 </svg>