diff --git a/B12NumbersV3/ActionCodeAll.pde b/B12NumbersV3/ActionCodeAll.pde index 6e9db39..722648d 100644 --- a/B12NumbersV3/ActionCodeAll.pde +++ b/B12NumbersV3/ActionCodeAll.pde @@ -110,7 +110,7 @@ import java.lang.ref.*; public static class MethodRelay { /** The object to handle the draw event */ - private WeakReference reference = null; + private WeakReference reference = null; // Replaced the original strong reference with a weak reference so that relays will get garbage collected if the object they call get collected //private Object handlerObject = null; /** The method in drawHandlerObject to execute */ private Method handlerMethod = null; diff --git a/B12NumbersV3/B12Base.pde b/B12NumbersV3/B12Base.pde index f2b4147..c72ce68 100644 --- a/B12NumbersV3/B12Base.pde +++ b/B12NumbersV3/B12Base.pde @@ -210,7 +210,8 @@ class B12Int implements Number { class B12Float implements Number{ - private ArrayList digits; + //private ArrayList digits; + private B12Digit[] digits; private float value; private PVector pos; private boolean arrayLoaded; @@ -232,7 +233,20 @@ class B12Float implements Number{ PVector getPos(){ return pos; } int getPlaces(){ return places; } B12Int toInt(){return new B12Int(int(value));} - + B12Digit[] getDigits(){ //<>// + loadArray(); + B12Digit[] out = (B12Digit[])reverse(digits); + for(int i = out.length-1; i > 0; i--){ + if(out[i].getValue() == '.'){ + out = (B12Digit[])shorten(out); + break; + } + if(out[i].getValue() == 0){ + out = (B12Digit[])shorten(out); + } + } + return out; + } B12Float setValue(float _value){ value = _value; arrayLoaded = false; return this;} B12Float setPos(PVector _pos){ pos = _pos.copy(); inPosition = false;return this; } @@ -256,8 +270,8 @@ class B12Float implements Number{ if(!inPosition){ positionDigits(); } pushMatrix(); translate(pos.x,pos.y); - for(int i = 0; i < digits.size(); i++){ - digits.get(i).display(); + for(int i = 0; i < digits.length; i++){ + digits[i].display(); } popMatrix(); } @@ -268,38 +282,38 @@ class B12Float implements Number{ if(mode == LEFT){ for(int i = 0; i < pointPlace; i++){ curPos += -12; - digits.get(i).setRefPos(curPos, 0); + digits[i].setRefPos(curPos, 0); count++; } curPos += -8; - digits.get(count).setRefPos(curPos, 0); + digits[count].setRefPos(curPos, 0); count++; curPos += -6; - digits.get(count).setRefPos(curPos, 0); + digits[count].setRefPos(curPos, 0); count++; - for(int i = count; i < digits.size(); i++){ + for(int i = count; i < digits.length; i++){ curPos += -12; - digits.get(i).setRefPos(curPos, 0); + digits[i].setRefPos(curPos, 0); } }else if(mode == DECIMAL){ curPos = -5; - digits.get(pointPlace).setRefPos(curPos,0); + digits[pointPlace].setRefPos(curPos,0); curPos += -2; for(int i = pointPlace - 1; i >= 0; i--){ curPos += 12; - digits.get(i).setRefPos(curPos,0); + digits[i].setRefPos(curPos,0); } curPos = -2; - for(int i = pointPlace + 1; i < digits.size(); i++){ + for(int i = pointPlace + 1; i < digits.length; i++){ curPos += -12; - digits.get(i).setRefPos(curPos,0); + digits[i].setRefPos(curPos,0); } }else if(mode == RIGHT){ - for(int i = digits.size() - 1; i >= 0; i--){ - digits.get(count).setRefPos((12 * i) + 3, 0); + for(int i = digits.length - 1; i >= 0; i--){ + digits[count].setRefPos((12 * i) + 3, 0); count++; } } @@ -307,7 +321,8 @@ class B12Float implements Number{ } private void loadArray(){ - digits = new ArrayList(); + //digits = new ArrayList(); + digits = new B12Digit[0]; B12Digit[] temp = new B12Digit[places]; float mval = abs(value); int whole = int(mval); @@ -320,24 +335,24 @@ class B12Float implements Number{ } for(int i = places - 1; i >= 0; i--){ - digits.add(temp[i]); + digits = (B12Digit[])append(digits,temp[i]); } - pointPlace = digits.size(); - digits.add(new B12Digit('.')); + pointPlace = digits.length; + digits = (B12Digit[])append(digits,new B12Digit('.')); while(whole > 0){ if(whole < 12){ - digits.add(new B12Digit(whole)); + digits = (B12Digit[])append(digits,new B12Digit(whole)); whole = 0; }else{ - digits.add(new B12Digit(whole % 12)); + digits = (B12Digit[])append(digits,new B12Digit(whole % 12)); whole /= 12; } } if(value < 0){ - digits.add(new B12Digit('-')); + digits = (B12Digit[])append(digits,new B12Digit('-')); } arrayLoaded = true; diff --git a/B12NumbersV3/B12NumbersV3.pde b/B12NumbersV3/B12NumbersV3.pde index a96feb3..131aa36 100644 --- a/B12NumbersV3/B12NumbersV3.pde +++ b/B12NumbersV3/B12NumbersV3.pde @@ -1,6 +1,8 @@ +import net.objecthunter.exp4j.*; + // B12NumbersV3 // String dbout = new String(""); -float scale = 2; +float scale = 4; PVector offset; public static final int DECIMAL = 65; MouseHandler mh; // Mouse event handler @@ -15,7 +17,7 @@ STime48 time; void setup(){ - size(400,400); + size(800,800); offset = new PVector(width/2, height/2); time = new STime48(); mh = new MouseHandler(new MouseData(offset, scale)); @@ -23,13 +25,13 @@ void setup(){ calc = new Calculator(mh, ex); - mode = new Button(mh).setPos(new PVector(-20,-width/4), new PVector(40,20)).setRadius(2).setColor(#8B687F).autoHighlight().setText("Mode").setFunction(new MethodRelay(this, "changeMode")); + mode = new Button(mh).setPos(new PVector(-20,-100), new PVector(40,20)).setRadius(2).setColor(#8B687F).autoHighlight().setText("Mode").setFunction(new MethodRelay(this, "changeMode")); } void draw(){ - textAlign(LEFT,TOP); - background(196); + textAlign(LEFT,TOP); + textSize(30); text(dbout,0,0); mh.frameUpdate(offset, scale); stroke(0); @@ -68,7 +70,7 @@ void changeMode(){ } calc = null; clock = new Clock(time).setPos(new PVector(30,0)); - changeTime = new Button(mh).setPos(new PVector(-40,-width/4 + 30), new PVector(80,20)).setRadius(2).setColor(#B096A7).autoHighlight().setText("Change Time").setFunction(new MethodRelay(clock, "setTime", Time48.class)); + changeTime = new Button(mh).setPos(new PVector(-40,-60), new PVector(80,20)).setRadius(2).setColor(#B096A7).autoHighlight().setText("Change Time").setFunction(new MethodRelay(clock, "setTime", Time48.class)); changeTime.setData(new Time48(12,0,0)); Runtime.getRuntime().gc(); } diff --git a/B12NumbersV3/guiB12Expression.pde b/B12NumbersV3/guiB12Expression.pde index d7e7aa8..522f84e 100644 --- a/B12NumbersV3/guiB12Expression.pde +++ b/B12NumbersV3/guiB12Expression.pde @@ -7,7 +7,7 @@ class B12Expression { // GETTERS // B12Digit getDigit(int index){ return expression[index]; } - int length(){return expression.length;} + int length(){if(expression == null){return 0;} return expression.length;} // SETTERS // B12Expression insertChar(int ind, B12Digit _digit){ @@ -35,10 +35,11 @@ class B12Expression { } void evaluate(){ - String evalString = parseDigits(); - println(evalString); - dbout = evalString; - //<>// //<>// + String evalString = parseDigits(); //<>// + Expression exp = new ExpressionBuilder(evalString).build(); + expression = new B12Float((float)exp.evaluate()).setPlaces(12).getDigits(); + println(exp.evaluate()); + dbout = str((float)exp.evaluate()); } private String parseDigits(){ diff --git a/B12NumbersV3/guiMathPad.pde b/B12NumbersV3/guiMathPad.pde index 147c4b1..99b98f4 100644 --- a/B12NumbersV3/guiMathPad.pde +++ b/B12NumbersV3/guiMathPad.pde @@ -1,3 +1,4 @@ + class MathPad{ private B12Expression ex; private MouseHandler mh; @@ -41,7 +42,7 @@ class MathPad{ buttons = (Button[])append(buttons, new B12Button(mh, new B12Digit('*')).setPos(new PVector(pos.x + 22*4,pos.y)).setFunction(new MethodRelay(this, "addChar", B12Digit.class)).setColor(220,150)); buttons = (Button[])append(buttons, new B12Button(mh, new B12Digit('/')).setPos(new PVector(pos.x + 22*4,pos.y + 22)).setFunction(new MethodRelay(this, "addChar", B12Digit.class)).setColor(220,150)); buttons = (Button[])append(buttons, new B12Button(mh, new B12Digit('.')).setPos(new PVector(pos.x + 22*4,pos.y + 22*2)).setFunction(new MethodRelay(this, "addChar", B12Digit.class)).setColor(220,150)); - buttons = (Button[])append(buttons, new Button(mh).setText("Enter").setPos(new PVector(pos.x + 22*4,pos.y + 22*3)).setDim(new PVector(42,20)).setFunction(new MethodRelay(this.ex, "evaluate")).setColor(220,150)); //<>// + buttons = (Button[])append(buttons, new Button(mh).setText("Enter").setPos(new PVector(pos.x + 22*4,pos.y + 22*3)).setDim(new PVector(42,20)).setFunction(new MethodRelay(this.ex, "evaluate")).setColor(220,150)); buttons = (Button[])append(buttons, new Button(mh).setText("Cl").setPos(new PVector(pos.x + 22*5,pos.y + 22)).setDim(new PVector(20,42)).setFunction(new MethodRelay(this.ex, "clear")).setColor(220,150)); buttons = (Button[])append(buttons, new Button(mh).setText("Del").setPos(new PVector(pos.x + 22*5,pos.y)).setDim(new PVector(20,20)).setFunction(new MethodRelay(this.ex, "delete")).setColor(220,150)); } diff --git a/B12NumbersV3/zchangelog.pde b/B12NumbersV3/zchangelog.pde index 57ec696..e2153de 100644 --- a/B12NumbersV3/zchangelog.pde +++ b/B12NumbersV3/zchangelog.pde @@ -3,19 +3,25 @@ Beta version of a clock in base 12. by Nayan Sawyer started Mar 2022 - version 0.1.5.8 April 30 2022 + version 0.2.0.0 April 30 2022 Characters are a variation of Kaktovik Inupiaq numerals reversed and in base 12 instead of 20. I take no credit for the design. - Includes method relay code be Quark - see https://forum.processing.org/two/discussion/13093/how-to-call-function-by-string-content.html + Includes method relay code by Quark - see https://forum.processing.org/two/discussion/13093/how-to-call-function-by-string-content.html for more details. - // TODO add actual math evaluation to B12Expression // Once thiss is done we hit version 0.2.0.0 // + // TODO switch B12Int from ArrayList to Array + // DONE add actual math evaluation to B12Expression // Once thiss is done we hit version 0.2.0.0 // // TODO add throwing exceptions to all contructors // MAYBE start clock widget structure // MAYBE add additional operations like power, log, and trig functions + changelog 0.2.0.0 + - Evaluating expressions has been fully implemented using + exp4j. Various things have been added to the base classes + to support this. + changelog 0.1.5.8 - Tweaks for first beta release for class presentation