/** * recursive circulator * jeremyawon.info * jeremy awon, (c) all rights reserved. **/ import javax.vecmath.*; import processing.opengl.*; color g_bgColor = color(248,248,248), g_fgColor = color(0,0,0); void setup() { //size(900,507, OPENGL); size(800,590, OPENGL); smooth(); //noCursor(); frameRate(60); initialize(); } int g_count; double g_decline; double g_radius; double g_diameter; double g_zoom; Vector2d g_center; Vector2d g_direction[]; int g_index[]; EquationMenu g_fm; boolean g_mouseClicked; void initialize() { g_count = 512; g_zoom = 0; g_diameter = height; g_radius = g_diameter/2; g_center = new Vector2d((width/2)+100, (height/2)); g_direction = new Vector2d[g_count]; g_index = new int[g_count]; for(int i=0;i=0) temp0.sub(g_direction[neighbor]); else temp0.add(g_direction[abs(neighbor)]); temp0.normalize(); temp0.scale(0.05); g_direction[i].add(temp0); g_direction[i].normalize(); temp1.set(temp3); temp2.set(g_direction[i]); temp2.scale((r0/2)-r1); temp1.sub(temp2); ellipse((float)temp1.x,(float)temp1.y,(float)r1*2,(float)r1*2); temp1.set(g_direction[i]); temp1.scale(r1); temp3.add(temp1); r0 -= r1*2; r1 *= g_decline; } g_fm.draw(); /**** added this because i couldn't get my cursor to show up in videos (for vimeo) ****/ /*color ic = mousePressed?color(255,100,100):color(255,200,200); fill(ic); stroke(ic); ellipse(mouseX,mouseY,10,10);*/ /*******/ } /* this is a hack.. i needed a gui and had issues with the processing gui libs. it went through numerious functionality iterations, but i hardly rethought the code. sorry :\ */ public class EquationMenu { PApplet _parent; Vector2f _position; Vector _equations; int _font_size; int _spacing; float _font_height; PFont _font; int _current; int _selected; EquationMenu(PApplet parent, int font_size, int spacing) { _parent = parent; _parent.registerKeyEvent(this); _equations = new Vector(); _current = -1; _selected = -1; _font_size = font_size; _spacing = spacing; _font = loadFont("Monaco-NotSmooth-18.vlw"); textFont(_font, _font_size); _font_height = textAscent(); } void keyEvent(KeyEvent e) { if(_current==-1) return; if(e.getID() == KeyEvent.KEY_PRESSED) { char input = e.getKeyChar(); if(input=='\n') { if((_current>=0)&&(_current<_equations.size())) { Equation eq = (Equation)_equations.get(_current); if(!eq.isEmpty()) { add(eq.toString(), _current+1, false); } } } else { if((_equations.size()>0)) { Equation eq = (Equation)_equations.get(_current); if((_equations.size()>1)&&(eq.isEmpty())&&((input==BACKSPACE)||(input==DELETE))) { remove(_current); } else { if(eq.change(input, e.getKeyCode())&&(_current==_selected)) _selected = -1; } } } } } void add(String equation, int i, boolean select) { if(i<=_selected) _selected += 1; Equation eq = new Equation(equation); _equations.add(i, eq); if(select) select(i); } void remove(int i) { if(i<_selected) _selected -= 1; else if(i==_selected) _selected = -1; _equations.remove(i); } void select(int i) { Equation eq = (Equation)_equations.get(i); int[] index = eq.evaluate(); if((index==null)&&(eq.isReset())) { for(int j=0;j=mouseY)&&(mouseY>=(y-_font_height)); if(current) { _current = i; if(g_mouseClicked) { select(i); g_mouseClicked = false; } } eq.draw(x,y, current, i==_selected); } } } class Equation { boolean _error; StringBuffer _content; int _offset; Equation(String equation) { _content = new StringBuffer(equation); _offset = max(1,_content.length()); _error = false; } boolean change(char input, int coded) { if(input == CODED) { if(coded == LEFT) _offset = max(0,_offset-1); else if(coded == RIGHT) _offset = min(_offset+1,max(0,_content.length())); } else { if((input==BACKSPACE)||(input==DELETE)) { if(_offset>0) { _content = _content.deleteCharAt(_offset-1); _offset = _offset-1; return true; } } else { if((input==' ')||(ArithmeticEvaluator.VALID_KEY.indexOf(input)!=-1)) { if(_offset > _content.length()) _content.append(input); else _content.insert(_offset, input); _offset = _offset+1; return true; } } } return false; } void draw(int x, int y, boolean current, boolean selected) { if(selected) x += 10; color c = color(180); if(_error) c = color(255,0,0); else if(selected) c = color(0); else if(current) c = color(90); fill(c); text(_content.toString(), x, y); if(current&&(((millis()/333)%2)==0)) { String indicator = new String(""); for(int i=0;i<_offset;i++) indicator += " "; indicator += "_"; text(indicator.toString(), x, y); } } float getWidth() { return max(textWidth(" ")*15, textWidth(_content.toString())); } boolean getError() { return _error; } boolean isEmpty() { return _content.length()==0; } boolean isReset() { return _content.toString().equals("reset"); } int[] evaluate() { int index[] = new int[g_index.length]; try { ArithmeticEvaluator ae = new ArithmeticEvaluator(_content.toString()); ae.assign("n", g_count); ae.assign("i", 1); for(int i=0;i0)&&((_offset+offset)<(_tokens.length-1)); } String token(int offset) { return token(offset, 0); } String token(int offset, int progress) { String result = _tokens[_offset+offset]; _offset += progress; return result; } } abstract class Node { abstract int evaluate(Environment e); String represent(String node, String content) { return node+"("+content+")"; } } class NodeNumeric extends Node { int _numeric; NodeNumeric(int numeric) { _numeric = numeric; } int evaluate(Environment e) { return _numeric; } String toString() { return represent("N",""+_numeric); } } class NodeSymbol extends Node { String _symbol; NodeSymbol (String symbol) { _symbol = symbol; } int evaluate(Environment e) { return e.retrieve(_symbol); } String toString() { return represent("S",_symbol); } } class NodeNegation extends Node { Node _ast; NodeNegation(Node ast) { _ast = ast; } int evaluate(Environment e) { return -1*_ast.evaluate(e); } String toString() { return represent("PN",""+_ast); } } class NodeOperation extends Node { Node _cL, _cR; String _op; NodeOperation(String op, Node cL, Node cR) { _op = op; _cL = cL; _cR = cR; } int evaluate(Environment e) { int result = 0; if(_op.equals("+")) result = _cL.evaluate(e) + _cR.evaluate(e); else if(_op.equals("-")) result = _cL.evaluate(e) - _cR.evaluate(e); else if(_op.equals("*")) result = _cL.evaluate(e) * _cR.evaluate(e); else if(_op.equals("/")) result = _cL.evaluate(e) / _cR.evaluate(e); else if(_op.equals("^")) result = (int)Math.pow(_cL.evaluate(e), _cR.evaluate(e)); else if(_op.equals("%")) result = _cL.evaluate(e) % _cR.evaluate(e); return result; } String toString() { return represent("O", _op+","+_cL+","+_cR); } } class NodeExpression extends Node { Node _c; NodeExpression (Node c) { _c = c; } int evaluate(Environment e) { return _c.evaluate(e); } String toString() { return represent("E", ""+_c); } } }