Skip to content
Permalink
911cc8d56f
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
182 lines (160 sloc) 3.17 KB
Camera cam;
TreeContainer pot;//or tree
Menu menu;
Selector selector;
Point nearestNeighbor;
ArrayList<Point> pointList, selectedList;
ArrayList<BoundingBox> boxList;
boolean drawCon, drawHelp, drawTreeRelations, drawTreeBoundaries, drawGnoman, useSelector, drawBoxes;
void setup() {
size(1000,1000);
background(120);
ellipseMode(CENTER);
cam = new Camera();
pot = new TreeContainer();
selector = new Selector();
nearestNeighbor = null;
menu = new Menu();
pointList = new ArrayList<Point>();
selectedList = new ArrayList<Point>();
boxList = new ArrayList <BoundingBox>();
drawCon = false;
drawHelp = false;
drawGnoman = true;
drawTreeRelations = false;
drawTreeBoundaries = false;
drawBoxes = false;
}
void draw() {
background(c_background);
pushMatrix();
cam.update();
if(drawGnoman) GnomanDraw(200);
if(drawBoxes) {
for(BoundingBox bb: boxList) {
bb.draw();
}
}
if(drawTreeBoundaries) {
pot.drawBoundaries();
}
if(drawTreeRelations) {
pot.drawRelations();
}
for(Point p: pointList) {
p.draw();
}
popMatrix();
if(useSelector) {
selector.draw();
}
/*if (drawHelp) {
drawHelpMenu();
} else {
menu.draw();
}*/
menu.draw();
}
void keyPressed() {
switch(key) {
case 'c':
case 'C':
pointList.clear();
selectedList.clear();
boxList.clear();
pot.clearTree();
break;
case 'h':
case 'H':
drawHelp = !drawHelp;
break;
case 'k':
case 'K':
drawTreeRelations = !drawTreeRelations;
break;
case 'j':
case 'J':
drawTreeBoundaries = !drawTreeBoundaries;
break;
case 'l':
case 'L':
drawBoxes = !drawBoxes;
break;
case 'e':
case 'E':
drawGnoman = !drawGnoman;
break;
case 'r':
case 'R':
addRandom(1);
break;
case 't':
case 'T':
addRandom(20);
break;
}
}
void checkSelect() {}
void addBox(BoundingBox bb) {
boxList.add(bb);
}
void setSelected(ArrayList<Point> pointList) {
for(Point p: selectedList) {
p.setUnSelected();
}
selectedList = pointList;
for(Point p: selectedList) {
p.setSelected();
}
}
void addRandom(int n) {
for(int i = 0; i < n; i++) {
Point p = new Point((int)random(width),(int)random(height));
Point r = cam.transform(p);
pointList.add(r);
pot.insert(r);
}
}
void GnomanDraw(int r) {
pushStyle();
stroke(c_gnoman);
line(-r,0,r,0);
line(0,-r,0,r);
popStyle();
}
void mousePressed() {
if(mouseButton == LEFT && !menu.mousePressed()) {
if(useSelector) {
selector.mousePressed();
} else {
cam.mousePressed();
}
}
if(mouseButton == RIGHT) {
cam.mousePressed();
}
}
void mouseDragged() {
if(mouseButton == LEFT) {
if(useSelector) {
selector.mouseDragged();
} else {
cam.mouseDragged();
}
}
if(mouseButton == RIGHT) {
cam.mouseDragged();
}
}
void mouseReleased() {
if(mouseButton == LEFT) {
if(useSelector) {
menu.mouseReleased();
} else {
cam.mouseReleased();
}
}
if(mouseButton == RIGHT) {
cam.mouseReleased();
}
}