diff --git a/demos/tutorial/1.html b/demos/tutorial/1.html new file mode 100644 index 0000000..31a534c --- /dev/null +++ b/demos/tutorial/1.html @@ -0,0 +1,180 @@ + + + + + Tutorial + + + + + + + + +
    +
  1. // Simple dashed pattern on circle +var s = Snap("#svg");
  2. +
  3. // This will be our shape. It could be anything. +var bigCircle = s.circle(150, 150, 100);
  4. +
  5. bigCircle.attr({ + stroke: "#000", + strokeWidth: 5 +});
  6. +
  7. // Now let's create pattern +var p = s.path("M110,95,95,110M115,100,100,115").attr({ + fill: "none", + stroke: "#bada55", + strokeWidth: 4 + }); +
  8. +
  9. //This is where our pattern cut will happen: +var cut = s.rect(100, 100, 10, 10).attr({fill: "#fff", opacity: .5})
  10. +
  11. cut.remove();
  12. +
  13. //make it a pattern +var ptrn = p.pattern(100, 100, 10, 10); +//ptrn is an invisible <pattern> element.
  14. +
  15. // Then use it as a fill on the big circle +bigCircle.attr({ + fill: ptrn +});
  16. +
  17. //We still have access to original path for the pattern, lets animate it a bit:
  18. +
  19. p.animate({strokeWidth: 1, stroke: "#FF4136"}, 1e3); +//Note that pattern could have as many elements as you want
  20. +
+ +
+ + + + + + + \ No newline at end of file diff --git a/demos/tutorial/2.html b/demos/tutorial/2.html new file mode 100644 index 0000000..a0c1ed4 --- /dev/null +++ b/demos/tutorial/2.html @@ -0,0 +1,194 @@ + + + + + Tutorial + + + + + + + + +
    +
  1. // Simple dashed pattern on circle with mask +var s = Snap("#svg"); +var bigCircle = s.circle(150, 150, 100).attr({ + fill: "#bada55", + stroke: "#000", + strokeWidth: 6 +}); +var p = s.path("M110,95,95,110M115,100,100,115").attr({ + fill: "none", + stroke: "#bada55", + strokeWidth: 4 + }); +var ptrn = p.pattern(100, 100, 10, 10); +bigCircle.attr({ + fill: ptrn +}); +//Here is our circle from the first Snap-bit. +
  2. +
  3. //Lets create a masking circle
  4. +
  5. var ring = s.circle(150, 150, 92).attr({ + fill: "none", + stroke: "#fff", + strokeWidth: 10 +});
  6. +
  7. //This looks correct, but only because our background is white
  8. +
  9. s.rect(0, 150, 300, 30).attr({fill: "#85144B"}).insertBefore(bigCircle); +//Uh-oh, lets try to apply this ring as a mask:
  10. +
  11. bigCircle.attr({ + mask: ring +});
  12. +
  13. //Not exactly what we want. We need to invert the mask
  14. +
  15. var mask = s.mask();
  16. +
  17. // Background rect: +mask.add(s.rect(0, 0, "100%", "100%").attr({fill: "#fff"}));
  18. +
  19. // and our ring, but black +mask.add(ring.attr({stroke: "#000"}));
  20. +
  21. bigCircle.attr({ + mask: mask +});
  22. +
  23. //Now, let’s animate the ring:
  24. +
  25. ring.animate({r: 10}, 1e3);
  26. + +
+ +
+ + + + + + + \ No newline at end of file