svg intersections working paper.js
this works for 3 must work for all
by Nick Hulea
HTML
<script src="http://cdn.eyahuska.com/paper.js"></script>
<canvas resize="true" id="canvas-1"></canvas>
<script type="text/paperscript" canvas="canvas-1">
var words = project.importSVG(document.getElementById('svg'));
words.fillColor = 'red';
words.strokeColor = 'black';
var noGroup = words.children.no;
var noGroup2 = noGroup.clone();
var noGroup3 = noGroup.clone();
console.log(noGroup);
console.log(noGroup2);
console.log(noGroup3);
noGroup.transformContent = true;
noGroup2.transformContent = true;
noGroup3.transformContent = true;
// Resize the words to fit snugly inside the view:
project.activeLayer.fitBounds(view.bounds);
project.activeLayer.scale(0.8);
noGroup.position = view.center;
noGroup2.position = [300, 300];
noGroup3.position = [300, 300];
noGroup.rotate(30);
noGroup2.rotate(-30);
noGroup3.rotate(-300);
function onMouseMove(event) {
noGroup.position = event.point;
}
function onMouseDown(event) {
noGroup.position = event.point;
for (var i = 0; i < noGroup3.children.length; i++) {
for (var j = 0; j < noGroup.children.length; j++) {
for (var k = 0; k < noGroup2.children.length; k++) {
showIntersections(noGroup.children[j], noGroup3.children[i])
showIntersections(noGroup.children[j], noGroup2.children[k])
}
}
}
}
function showIntersections(path1, path2) {
var intersections = path1.getIntersections(path2);
for (var i = 0; i < intersections.length; i++) {
console.log(intersections[i].point);
new Path.Circle({
center: intersections[i].point,
radius: 5,
fillColor: '#009dec'
}).removeOnMove();
console.log(intersections[i].point.length)
if (intersections[i].point.length > 0) {
...