Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
working circle and rectangle, incomplete point
  • Loading branch information
laa11004 committed Nov 27, 2015
1 parent ce379bd commit a99f462
Show file tree
Hide file tree
Showing 4 changed files with 165 additions and 0 deletions.
Binary file modified .DS_Store
Binary file not shown.
50 changes: 50 additions & 0 deletions SelectTest/Menu.pde
@@ -0,0 +1,50 @@
class Menu{
Selector selector;
PShape rectButton, circleButton, neighborButton, rectIcon, circleIcon, neighborIcon;

Menu(){
rectButton = createShape(RECT,0,0,60,25,0,7,7,0);
rectIcon = createShape(RECT,20,15,40,20);
circleButton = createShape(RECT,0,26,60,25,0,7,7,0);
circleIcon = createShape(ELLIPSE,0,52,60,25,0,7,7,0);
neighborButton = createShape(RECT,0,52,60,25,0,7,7,0);
neighborIcon = createShape(RECT,0,52,60,25,0,7,7,0);
selector = new Selector();
}

void activate(int button){
selector.setSelectMode(button);
}

int onaButton(int x, int y){
if( 0<x && x<=60 && y>0 && y<=25){ return 1; }
else if( 0<x && x<=60 && y>25 && y<=51){ return 2; }
else if( 0<x && x<=60 && y>51 && y<=77){ return 3; }
else { return 0; }
}

void draw(){
shape(rectButton);
shape(rectIcon);
shape(circleButton);
shape(circleIcon);
shape(neighborButton);
shape(neighborIcon);
selector.draw();
}

void mousePressed(MouseEvent e){
int button = onaButton(mouseX,mouseY);
if( button != 0 ){ activate(button); }
//else{ selector.startSelection(); }
selector.startSelection();
}

void mouseReleased(MouseEvent e){
selector.resetSelection();
}

void mouseDragged(MouseEvent e){
selector.stretchSelection();
}
}
26 changes: 26 additions & 0 deletions SelectTest/SelectTest.pde
@@ -0,0 +1,26 @@

Menu menu;

void setup(){

menu = new Menu();
size(800,800);
background(240);
}

void draw(){
background(240);
menu.draw();
}

void mousePressed(MouseEvent e){
menu.mousePressed(e);
}

void mouseReleased(MouseEvent e){
menu.mouseReleased(e);
}

void mouseDragged(MouseEvent e){
menu.mouseDragged(e);
}
89 changes: 89 additions & 0 deletions SelectTest/Selector.pde
@@ -0,0 +1,89 @@
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;
}
}

0 comments on commit a99f462

Please sign in to comment.