diff --git a/RangeApp/web-export/RangeApp.pde b/RangeApp/web-export/RangeApp.pde deleted file mode 100644 index 54785b3..0000000 --- a/RangeApp/web-export/RangeApp.pde +++ /dev/null @@ -1,1074 +0,0 @@ -Camera cam; -TreeContainer pot;//or tree -Menu menu; -Selector selector; -Point nearestNeighbor; -ArrayList pointList, selectedList; -boolean drawCon, drawHelp, drawTreeRelations, drawTreeBoundaries, drawGnoman, useSelector; - -void setup() { - size(800,800); - background(120); - ellipseMode(CENTER); - cam = new Camera(); - pot = new TreeContainer(); - selector = new Selector(); - nearestNeighbor = null; - menu = new Menu(); - pointList = new ArrayList(); - selectedList = new ArrayList(); - - drawCon = false; - drawHelp = false; - drawGnoman = true; - drawTreeRelations = false; - drawTreeBoundaries = true; - -} - -void draw() { - background(c_background); - - pushMatrix(); - cam.update(); - if(drawGnoman) GnomanDraw(200); - - 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(); - } - -} - -void keyPressed() { - switch(key) { - case 'c': - case 'C': - pointList.clear(); - selectedList.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 'e': - case 'E': - drawGnoman = !drawGnoman; - break; - case 'r': - case 'R': - addRandom(1); - break; - case 't': - case 'T': - addRandom(20); - break; - } -} - -void checkSelect() {} - -void setSelected(ArrayList 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(); - } -} - -void balanceTree (ArrayList points, boolean dir) { - -} -class BoundingBox { - float x1, x2, y1, y2; - public BoundingBox(float _x1, float _x2, float _y1, float _y2) - { - x1 = _x1; - x2 = _x2; - y1 = _y1; - y2 = _y2; - } - void draw() - { - pushStyle(); - stroke(0); - line(x1, y1, x2, y1); - line(x1, y2, x2, y2); - line(x1, y1, x1, y2); - line(x2, y1, x2, y2); - popStyle(); - } -} - -class CirSHandler implements ButtonHandler{ - void Selected() { - selector.setSelectMode(1); - useSelector = true; - } -} - -class RectSHandler implements ButtonHandler{ - void Selected() { - selector.setSelectMode(0); - useSelector = true; - } -} -class PanHandler implements ButtonHandler{ - void Selected() { - cam.setMode(0); - useSelector = false; - } -} - -class RotHandler implements ButtonHandler{ - void Selected() { - cam.setMode(1); - useSelector = false; - } -} - -class PlaceHandler implements ButtonHandler{ - void Selected() { - selector.setSelectMode(3); - useSelector = true; - } -} - -interface ButtonHandler { - void Selected (); -} - -class Button { - int _x; - int _y; - int _w; - int _h; - int _r; - boolean _isSel; - String _label; - ArrayList _handlerList; - - Button (int x, int y, String label) { - _x = x; - _y = y; - _w = i_buttonWidth; - _h = i_buttonHeight; - _r = i_buttonRad; - _handlerList = new ArrayList (); - _label = label; - _isSel = false; - } - - boolean isMouseOver() { - return mouseX >= _x && mouseX <= _x + _w && mouseY >= _y && mouseY <= _y + _h; - } - - void Select() { - _isSel = true; - for(ButtonHandler h: _handlerList) { - h.Selected(); - } - } - - void unSelect() { - _isSel = false; - } - - void draw () { - pushStyle(); - stroke(c_buttonStr); - if(_isSel) { - fill(c_buttonSel); - } else { - fill(c_buttonDef); - } - rect(_x, _y, _w, _h, 0, _r, _r, 0); - if(_isSel) { - fill(c_WHITE); - } else { - fill(c_BLACK); - } - textSize(20); - text(_label, _x + 3, _y + _h - 10); - popStyle(); - } - - void addHandler (ButtonHandler h) { - _handlerList.add(h); - } -} -class Camera { - float _x; - float _y; - float _scale; - float _angle; - float _oldX; - float _oldY; - float _oldAngle; - float _oldScale; - - int _initMX; - int _initMY; - - int _mode; - - Camera() { - _x = 0.0; - _y = 0.0; - _scale = 1.0; - _angle = 4 * PI; - } - - void setMode(int mode) { - _mode = mode; - } - - void update() { - translate(_x + width/2,_y + height/2); - rotate(_angle); - scale(_scale); - } - - void mousePressed() { - _initMX = mouseX; - _initMY = mouseY; - _oldScale = _scale; - _oldX = _x; - _oldY = _y; - _oldAngle = _angle; - } - - void mouseDragged() { - float difX = (float)(mouseX - _initMX); - float difY = (float)(mouseY - _initMY); - - if(mouseButton == RIGHT) { - difX /= (float)(width); - difY /= (float)(height); - _scale = f_EPSILON + abs((1 - 4*(difX + difY)) * _oldScale); - _x = _oldX * _scale; - _y = _oldY * _scale; - } else { - switch(_mode) { - case 0: - difX *= 1.0/_scale; - difY *= 1.0/_scale; - _x = _oldX + difX; - _y = _oldY + difY; - break; - case 1: - float initAngle = atan((_initMY - height/2)/(f_EPSILON + _initMX - width/2)); - float newAngle = atan((mouseY - height/2)/(f_EPSILON + mouseX - width/2)); - float delta = newAngle - initAngle; - _angle = _oldAngle + delta; - break; - } - } - } - - void mouseReleased() { - - } - - Point transform(Point p) { - float px = (1.0/_scale)*((p._x - width/2) - _x); - float py = (1.0/_scale)*((p._y - height/2) - _y); - float x = (cos(_angle)*px + sin(_angle)*py); - float y = (-sin(_angle)*px + cos(_angle)*py); - return new Point(x,y); - } -} -class Menu{ - ArrayList