Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added random point buttons, updated help menu, and added colored sele…
…ction points
  • Loading branch information
rwb11001 committed Dec 9, 2015
1 parent 5c8ac0b commit 9b1c484
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 32 deletions.
13 changes: 5 additions & 8 deletions RangeApp/Properties.pde
Expand Up @@ -4,7 +4,7 @@ color c_BLACK = color (0, 0, 0);
color c_PROCBLUE = color (5,13,22);
color c_LIGHTBLUE = color (0, 215, 255);
color c_YELLOW = color (215, 255, 0);
color c_HILITE = color (251, 255, 20, 100);//selector filling
color c_HILITE = color (70, 255, 50, 180);//selector filling

// Screen Color
color c_background = color (26, 26, 26);
Expand All @@ -31,7 +31,7 @@ int i_helpStrokeWidth = 2;
// Point
color c_pointStroke = c_BLACK;
color c_pointDefault = c_WHITE;
color c_pointSelect = color (100, 255, 100);
color c_pointSelect = color (255, 50, 50);
int i_pointRad = 20;

// Tree stuff
Expand All @@ -45,12 +45,9 @@ String[] s_helpStrings = {
"e: Toggle Gnoman",
"k: Toggle Relations",
"j: Toggle Boundaries",
"f: Scale",
"d: Pan",
"s: Rotate",
"a: Place Point",
"g: Select Point",
"c: Clear Points"
"c: Clear Points",
"r: Add 1 Random",
"t: Add 20 Random"
};

// Math Stuff
Expand Down
36 changes: 31 additions & 5 deletions RangeApp/RangeApp.pde
Expand Up @@ -3,7 +3,7 @@ TreeContainer pot;//or tree
Menu menu;
Selector selector;
Point nearestNeighbor;
ArrayList<Point> pointList;
ArrayList<Point> pointList, selectedList;
boolean drawCon, drawHelp, drawTreeRelations, drawTreeBoundaries, drawGnoman, useSelector;

void setup() {
Expand All @@ -16,11 +16,12 @@ void setup() {
nearestNeighbor = null;
menu = new Menu();
pointList = new ArrayList<Point>();
selectedList = new ArrayList<Point>();

drawCon = false;
drawHelp = false;
drawGnoman = true;
drawTreeRelations = true;
drawTreeRelations = false;
drawTreeBoundaries = true;

}
Expand Down Expand Up @@ -62,6 +63,7 @@ void keyPressed() {
case 'c':
case 'C':
pointList.clear();
selectedList.clear();
pot.clearTree();
break;
case 'h':
Expand All @@ -80,14 +82,38 @@ void keyPressed() {
case 'E':
drawGnoman = !drawGnoman;
break;
case '1':

case 'r':
case 'R':
addRandom(1);
break;
case 't':
case 'T':
addRandom(20);
break;
}
}

void checkSelect() {}

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);
Expand Down Expand Up @@ -133,4 +159,4 @@ void mouseReleased() {
if(mouseButton == RIGHT) {
cam.mouseReleased();
}
}
}
27 changes: 8 additions & 19 deletions RangeApp/Selector.pde
Expand Up @@ -43,32 +43,21 @@ class Selector{

void resetSelection(){//triggered on mouseReleased()
if(_selecting){ //selecting with rect or circle
ArrayList<Point> solution;
switch(_select_mode){
case 0:
Point p1 = cam.transform(new Point(_startX, _startY));
Point p2 = cam.transform(new Point(_endX+_startX, _endY+_startY));

if(pot.getTree() != null){//prevents query of null/empty tree
ArrayList<Point> solution = pot.getTree().queryBox(new BoundingBox(min(p1._x, p2._x), max(p1._x, p2._x), min(p1._y, p2._y), max(p1._y, p2._y)));
for(Point pp : solution)
{
ellipse(pp._x + width/2, pp._y + height/2, 30, 30);
}
println("size of list: " + solution.size());
}
solution = pot.queryBox(new BoundingBox(min(p1._x, p2._x), max(p1._x, p2._x), min(p1._y, p2._y), max(p1._y, p2._y)));
setSelected(solution);
println("size of list: " + solution.size());
break;
case 1:
Point pp1 = cam.transform(new Point(_startX, _startY));
Point pp2 = cam.transform(new Point(_endX+_startX, _endY+_startY));

if(pot.getTree() != null){//prevents query of null/empty tree
ArrayList<Point> solution = pot.getTree().queryCircle(pp1, dist(pp1._x, pp1._y, pp2._x, pp2._y));
for(Point pp : solution)
{
ellipse(pp._x + width/2, pp._y + height/2, 30, 30);
}
println("size of list: " + solution.size());
}
solution = pot.queryCircle(pp1, dist(pp1._x, pp1._y, pp2._x, pp2._y));
setSelected(solution);
println("size of list: " + solution.size());
break;
}
_selecting = false;
Expand Down Expand Up @@ -128,4 +117,4 @@ class Selector{
_searching = false;
}
}
}
}
15 changes: 15 additions & 0 deletions RangeApp/TreeContainer.pde
Expand Up @@ -19,6 +19,21 @@ class TreeContainer {

void clearTree(){ _tree = null; }

ArrayList<Point> queryBox(BoundingBox bb) {
if(_tree != null) {
return _tree.queryBox(bb);
}
return new ArrayList<Point>();
}

ArrayList<Point> queryCircle(Point p, float r) {
if(_tree != null) {
return _tree.queryCircle(p, r);
}
return new ArrayList<Point>();
}


void setTree (KdTree tree) { _tree = tree; }

void drawRelations() {
Expand Down

0 comments on commit 9b1c484

Please sign in to comment.