SVG – Learning by Coding
1: <?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
2: <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN"
3: "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd" [
4: <!ATTLIST svg xmlns:xlink CDATA #FIXED "http://www.w3.org/1999/xlink">
5: ]>
6:
7: <!-- SVG - Learning by Coding - http://www.datenverdrahten.de/svglbc/ -->
8: <!-- Author: Dr. Thomas Meinike 11/03 - thomas@handmadecode.de -->
9:
10:
11: <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
12: zoomAndPan="disable">
13:
14: <title>SVG - Learning by Coding</title>
15: <desc>SVG-Spezifikation in Beispielen</desc>
16:
17: <defs>
18:
19: <style type="text/css">
20: <![CDATA[
21:
22: line
23: {
24: stroke-width: 1.5px;
25: }
26:
27: ]]>
28: </style>
29:
30:
31: <script type="text/javascript">
32: <![CDATA[
33:
34: function getLineLength(click_evt)
35: {
36: var line,l_x1,l_y1,l_x2,l_y2,l=0;
37:
38: line=click_evt.target;
39: l_x1=parseFloat(line.getAttribute("x1"));
40: l_y1=parseFloat(line.getAttribute("y1"));
41: l_x2=parseFloat(line.getAttribute("x2"));
42: l_y2=parseFloat(line.getAttribute("y2"));
43:
44: // Abstand der Punkte auf 6 Nachkommastellen gerundet
45: l=PointDistance(l_x1,l_y1,l_x2,l_y2).toFixed(6);
46:
47: alert("Abstand der Punkte\nP1("+l_x1+","+l_y1+") und P2("
48: +l_x2+","+l_y2+")\n\n"+l+" px");
49: }
50:
51:
52: function PointDistance(x1,y1,x2,y2)
53: {
54: // Abstand zweier Punkte bzw. Laenge einer Linie - Satz des Pythagoras
55: return Math.sqrt(Math.pow(x2-x1,2)+Math.pow(y2-y1,2));
56: }
57:
58: ]]>
59: </script>
60:
61: </defs>
62:
63: <text x="30" y="30" style="fill: #000; font-size: 24px">
64: Abstand zweier Punkte (Länge von Linien)
65: </text>
66:
67: <line x1="40" y1="60" x2="160" y2="90" style="stroke: #F00"
68: onclick="getLineLength(evt)"/>
69: <line x1="180" y1="100" x2="280" y2="50" style="stroke: #090"
70: onclick="getLineLength(evt)"/>
71: <line x1="290" y1="80" x2="430" y2="80" style="stroke: #00C"
72: onclick="getLineLength(evt)"/>
73: <line x1="460" y1="50" x2="460" y2="120" style="stroke: #000"
74: onclick="getLineLength(evt)"/>
75:
76: <text x="210" y="140">Linien anklicken!</text>
77:
78: </svg>
[zum Anfang]