Skip to content
Permalink
a99f4625f2
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
89 lines (81 sloc) 1.93 KB
class Selector{
PShape selection;
float startX,startY, endX, endY;
boolean selecting, animating;
int select_mode;
float a,b,radius;
Selector(){
selecting = false;
animating = false;
a = 0;
b = 0;
select_mode = 1;
endX = -1;
endY = -1;
selection = createShape(RECT,-1,-1,-1,-1);
}
void setSelectMode(int mode){
select_mode = mode;
}
void startSelection(){
selecting = true;
startX = mouseX;
startY = mouseY;
if(select_mode == 3){
animating = true;
}
}
void resetSelection(){
selecting = false;
startX = -1;
startY = -1;
endX = -1;
endY = -1;
a = 0;
b = 0;
}
void stretchSelection(){
if(selecting){
endX = mouseX-startX;
endY = mouseY-startY;
}
}
void draw(){
if(selecting){
switch(select_mode){
case 1: selection = createShape(RECT,startX,startY,endX,endY);
break;
case 2: a = mouseX-startX;
b = mouseY-startY;
radius = sqrt(a*a+b*b);
ellipseMode(RADIUS);
selection = createShape(ELLIPSE,startX,startY,radius,radius);
line(startX,startY,mouseX,mouseY);
break;
case 3: if(animating){neighborAnimation();}
}
selection.setStroke(true);
selection.setFill(color(251, 255, 20, 100));
shape(selection);
}
}
void neighborAnimation(){
int i;
int t = millis();
int pointRadius = 5;
for(i=0;i<5;i++){
background(240);
//println("done\n");
ellipseMode(RADIUS);
selection = createShape(ELLIPSE,startX,startY,pointRadius,pointRadius);
selection.setStroke(true);
selection.setFill(color(251, 255, 20, 100));
shape(selection);
pointRadius += 10;
while(millis()-t < 1000){
}
t = millis();
}
animating = false;
}
}