Created
January 8, 2013 05:06
-
-
Save netpoetica/4481375 to your computer and use it in GitHub Desktop.
In Paper.js, use importSVG to import an svg node to a useable symbol and remove it from the DOM.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> | |
<title>Paperjs - ImportSVG to Symbol</title> | |
<script type="text/javascript" src="js/lib/paper.js"></script> | |
<script type="text/paperscript" canvas="canvas"> | |
function SVGSymbol(elem){ | |
var a = new Symbol(paper.project.importSvg(elem)); | |
elem.parentNode.removeChild(elem); | |
return a; | |
} | |
var a = SVGSymbol(document.getElementById('svg')); | |
var n = 20; | |
while(n--){ | |
var p = a.place(); | |
p.position = new Point(n * 40, 100); | |
p.scale(0.25 + Math.random() * 0.75); | |
} | |
</script> | |
</head> | |
<body> | |
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" style="width:500px; height:1000px;" id="svg"> | |
<circle cx="40" cy="300" r="20" style="fill:orange;stroke:yellow;stroke-width:2px;stroke-dasharray:3px" id="circle1" /> | |
</svg> | |
<canvas id="canvas" width="595px" height="841px"></canvas> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for your reply @netpoetica, sorry if I sounded rude. I appreciate your very useful original post. All the best Derek.