1 | var pathArray = new Array();
|
---|
2 | var pathCollectionNames = new Array();
|
---|
3 | var dragCircle = false;
|
---|
4 | var pallete = [30,60,90,120,150,180,210,240,270,300,330,360];
|
---|
5 |
|
---|
6 | this.updateCircle = function(side){
|
---|
7 | var quer = new ComparisonQuery();
|
---|
8 | var newColor;
|
---|
9 | var oldColor = -1;
|
---|
10 | var index = 0;
|
---|
11 | if(side == "right")
|
---|
12 | index = 1;
|
---|
13 |
|
---|
14 | if(typeof(pathArray[index])!="undefined"){
|
---|
15 | oldColor = pathArray[index].fillColor.hue;
|
---|
16 | pathArray[index].remove();
|
---|
17 | }
|
---|
18 |
|
---|
19 | pathArray[index] = new Path.Circle(new Point(123 + (index) * 70,85),50);
|
---|
20 | pathArray[index].strokeColor = 'black';
|
---|
21 | newColor = pallete[Math.floor(Math.random()*pallete.length)];
|
---|
22 | pallete.splice(pallete.indexOf(newColor),1);
|
---|
23 | if(oldColor!=-1)
|
---|
24 | pallete.push(oldColor);
|
---|
25 |
|
---|
26 | pathArray[index].fillColor = {
|
---|
27 | hue: newColor,
|
---|
28 | saturation: 5,
|
---|
29 | brightness: 1
|
---|
30 | };
|
---|
31 | pathArray[index].blendMode = 'darken';
|
---|
32 | pathArray[index].opacity = .7;
|
---|
33 | if(side == "left")
|
---|
34 | pathCollectionNames[index] = (leftCollection);
|
---|
35 | else if(side == "right")
|
---|
36 | pathCollectionNames[index] = (rightCollection);
|
---|
37 |
|
---|
38 | return pathArray[index].fillColor.toCSS();
|
---|
39 | }
|
---|
40 | function onMouseDrag(event) {
|
---|
41 | if(dragCircle==true && event.item!=null)
|
---|
42 | event.item.position=event.point;
|
---|
43 | };
|
---|
44 |
|
---|
45 | function onMouseDown(event){
|
---|
46 | if(!dragCircle){
|
---|
47 | //Add circle where clicked
|
---|
48 | var s = new Path.Circle(event.point, 4,'#43ae0c');
|
---|
49 | s.fillColor = '#000000';
|
---|
50 | s.removeOnDown();
|
---|
51 |
|
---|
52 | var mousePos = event.point;
|
---|
53 | var IndicesUnder = new Array();
|
---|
54 |
|
---|
55 | //Loop through circles to see which are under mouse
|
---|
56 | for(var i=0; i < pathArray.length; i++){
|
---|
57 | if(typeof(pathArray[i])!="undefined"){
|
---|
58 | var circlePos = pathArray[i].position;
|
---|
59 | var circleRadius = pathArray[i].bounds.width/2;
|
---|
60 | var diff = distance(mousePos, circlePos);
|
---|
61 |
|
---|
62 | //If circle was clicked on
|
---|
63 | if(diff < circleRadius)
|
---|
64 | IndicesUnder.push(i);
|
---|
65 | }
|
---|
66 | }
|
---|
67 | if(IndicesUnder.length==2){
|
---|
68 | comparisonQuery.type = "intersection";
|
---|
69 | comparisonQuery.datasetSelection = "";
|
---|
70 | }
|
---|
71 | else if(IndicesUnder.length==1){
|
---|
72 | comparisonQuery.type = "minus";
|
---|
73 | comparisonQuery.datasetSelection = pathCollectionNames[IndicesUnder[0]];
|
---|
74 | }
|
---|
75 | if(IndicesUnder.length>0)
|
---|
76 | drawComparisonTable();
|
---|
77 | }
|
---|
78 | //If dragging a circle
|
---|
79 | //Move circle to top of active layer
|
---|
80 | else
|
---|
81 | project.activeLayer.appendTop(event.item);
|
---|
82 | }
|
---|
83 | function distance(p1, p2){
|
---|
84 | return Math.sqrt(Math.pow((p1.x - p2.x),2)+Math.pow((p1.y - p2.y),2));
|
---|
85 | }
|
---|
86 | function onKeyDown(event) {
|
---|
87 | if(event.key == 'control')
|
---|
88 | dragCircle=true;
|
---|
89 | }
|
---|
90 |
|
---|
91 | function onKeyUp(event) {
|
---|
92 | if(event.key == 'control')
|
---|
93 | dragCircle=false;
|
---|
94 | }
|
---|