-
Notifications
You must be signed in to change notification settings - Fork 2
/
snaptut-subpath.html
65 lines (49 loc) · 1.9 KB
/
snaptut-subpath.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
<!DOCTYPE html>
<html>
<head>
<title>Snap.svg Tutorial</title>
<script src="analytics.js" async></script>
</head>
<body>
<link href="/snapstyle.css" rel="stylesheet">
<div id="container"></div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
<script src="snap.svg.js"></script>
<a href="http://snapsvg.io/docs/">Snap Docs</a> <a href="/">More SVG Dabbles</a> <a href="/">Contact Me</a>
<article>
<h1 class="heading">Basic Test</h1>
<div class="intro">Lets just testing getting a basic shape up and filling it</div>
<pre class="codestuff"><code contenteditable="true">
<xmp>
var s = Snap("#svgout");
var path1 = s.path("M 60 0 L 120 0 L 180 60 L 180 120 L 120 180 L 60 180 L 0 120 L 0 60 Z").attr({ fill: "none", stroke: "red", opacity: "1" });
var path2 = s.path("M 100 100 L 300 100 L 200 300 z").attr({ fill: "none", stroke: "red", opacity: "1" });
var l1 = path1.getTotalLength();
var l2 = path2.getTotalLength();
var path1arrays = Snap.parsePathString( path1.attr('d') );
var path2arrays = Snap.parsePathString( path2.attr('d') );
console.log( l1, l2, path1arrays, path2arrays, path2arrays.length );
var numsegs = path1arrays.length;
var segsize = l2 / numsegs;
console.log( segsize, a*segsize );
var newpath = '';
for( var a = 0; a<numsegs; a++ ) {
newpath += Snap.path.getSubpath(path2, a*segsize, (a+1)*segsize);
}
//var np = s.path( newpath ).attr({ fill: 'none', stroke: 'blue' });
console.log( newpath );
path1.animate({ d: newpath }, 1000);
</xmp>
</code>
<button class="run">Edit/Run</button>
</pre>
</article>
<div class="intro">SVGout area...</div>
<div class="output">
<svg id="svgout" width="400" height="400"></svg>
</div>
<div class="intro">The actual svg markup looks like this (when you've clicked on run)....</div>
<div id="htmlraw"></div>
<script src="snaptut.js"></script></script>
<script src="hijs.js"></script>
</body>