var pathArray = new Array(); var pathCollectionNames = new Array(); var dragCircle = false; var pallete = [30,60,90,120,150,180,210,240,270,300,330,360]; this.updateCircle = function(side){ var quer = new ComparisonQuery(); var newColor; var oldColor = -1; var index = 0; if(side == "right") index = 1; if(typeof(pathArray[index])!="undefined"){ oldColor = pathArray[index].fillColor.hue; pathArray[index].remove(); } pathArray[index] = new Path.Circle(new Point(123 + (index) * 70,85),50); pathArray[index].strokeColor = 'black'; newColor = pallete[Math.floor(Math.random()*pallete.length)]; pallete.splice(pallete.indexOf(newColor),1); if(oldColor!=-1) pallete.push(oldColor); pathArray[index].fillColor = { hue: newColor, saturation: 5, brightness: 1 }; pathArray[index].blendMode = 'darken'; pathArray[index].opacity = .7; if(side == "left") pathCollectionNames[index] = (leftCollection); else if(side == "right") pathCollectionNames[index] = (rightCollection); return pathArray[index].fillColor.toCSS(); } function onMouseDrag(event) { if(dragCircle==true && event.item!=null) event.item.position=event.point; }; function onMouseDown(event){ if(!dragCircle){ //Add circle where clicked var s = new Path.Circle(event.point, 4,'#43ae0c'); s.fillColor = '#000000'; s.removeOnDown(); var mousePos = event.point; var IndicesUnder = new Array(); //Loop through circles to see which are under mouse for(var i=0; i < pathArray.length; i++){ if(typeof(pathArray[i])!="undefined"){ var circlePos = pathArray[i].position; var circleRadius = pathArray[i].bounds.width/2; var diff = distance(mousePos, circlePos); //If circle was clicked on if(diff < circleRadius) IndicesUnder.push(i); } } if(IndicesUnder.length==2){ comparisonQuery.type = "intersection"; comparisonQuery.datasetSelection = ""; } else if(IndicesUnder.length==1){ comparisonQuery.type = "minus"; comparisonQuery.datasetSelection = pathCollectionNames[IndicesUnder[0]]; } if(IndicesUnder.length>0) drawComparisonTable(); } //If dragging a circle //Move circle to top of active layer else project.activeLayer.appendTop(event.item); } function distance(p1, p2){ return Math.sqrt(Math.pow((p1.x - p2.x),2)+Math.pow((p1.y - p2.y),2)); } function onKeyDown(event) { if(event.key == 'control') dragCircle=true; } function onKeyUp(event) { if(event.key == 'control') dragCircle=false; }