-
Notifications
You must be signed in to change notification settings - Fork 2
/
snaptut-matrix-groups.html
76 lines (56 loc) · 2.69 KB
/
snaptut-matrix-groups.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
<!DOCTYPE html>
<html>
<head>
<title>Snap.svg Tutorial</title>
<script src="analytics.js"></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>
<article>
<h1 class="heading">Snap Matrix</h1>
<div class="intro">Lets fiddle with Snap matrices. Change the group transforms in code and check the matrices from rect.transform()</div>
<div class="intro">Note how g1 globalMatrix and rect globalMatrix are added up from each outer localMatrix combined</div>
<div class="intro">Useful Matrix links <a href="http://www.w3.org/TR/SVG/coords.html#TransformMatrixDefined">w3.org svg coords and matrix</a></div>
<pre class="codestuff"><code contenteditable="true">
var s = Snap("#svgout");
var r0 = s.rect(150,150,100,100,20,20).attr({ fill: "orange", opacity: "0.8", stroke: "black", strokeWidth: "2" });
var c0 = s.circle(225,225,10).attr({ fill: "silver", stroke: "black" });
var g0 = s.group( r0,c0 );
g0.animate({ 'transform' : 'r360,225,225' },4000);
var r1 = s.rect(100,100,100,100,20,20).attr({ fill: "red", opacity: "0.8", stroke: "black", strokeWidth: "2" });
var c1 = s.circle(175,175,10).attr({ fill: "silver", stroke: "black" });
var g1 = s.group( r1,c1 );
g1.appendTo( g0 );
g1.animate({ 'transform' : 'r360,175,175' },4000);
var r2 = s.rect(50,50,100,100,20,20).attr({ fill: "blue", opacity: "0.8", stroke: "black", strokeWidth: "2" });
var c2 = s.circle(125,125,10).attr({ fill: "silver", stroke: "black" });
var g2 = s.group(r2,c2);
g2.appendTo( g1 );
g2.animate( { 'transform' : 'r360,125,125' },4000);
var r3 = s.rect(0,0,100,100,20,20).attr({ fill: "yellow", opacity: "0.8", stroke: "black", strokeWidth: "2" });
var c3 = s.circle(75,75,10).attr({ fill: "silver", stroke: "black" });
var g3 = s.group(r3,c3);
g3.appendTo( g2 );
g3.animate( { 'transform' : 'r360,75,75' },4000);
var r4 = s.rect(-50,-50,100,100,20,20).attr({ fill: "green", opacity: "0.8", stroke: "black", strokeWidth: "2" });
var c4 = s.circle(25,25,10).attr({ fill: "silver", stroke: "black" });
var g4 = s.group(r4,c4);
g4.appendTo( g3 );
g4.animate( { 'transform' : 'r360,25,25' },4000);
</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>