diff --git a/B12NumbersV3/B12Char.pde b/B12NumbersV3/B12Char.pde index cb3b50f..165e73a 100644 --- a/B12NumbersV3/B12Char.pde +++ b/B12NumbersV3/B12Char.pde @@ -1,12 +1,14 @@ class B12Char extends B12Digit{ + String valid; char c; B12Char(char _c){ super(0); - if(_c == '-' || _c == '.' || _c == ':'){ + valid = "+-*/.:"; // Defines valid input characters + if(inStr(_c)){ c = _c; }else{ - throw new IllegalArgumentException("B12Char only accepts \'-\', \'.\', and ':'"); + throw new IllegalArgumentException("B12Char only accepts \'+ - * / . :'"); } } @@ -17,8 +19,14 @@ class B12Char extends B12Digit{ strokeWeight(1); switch(c) { + case '+': + lineMinus(); linePlus(); break; case '-': lineMinus(); break; + case '*': + lineTimes(); break; + case '/': + lineMinus(); dotsDiv(); break; case '.': strokeWeight(2); period(); break; case ':': @@ -28,7 +36,20 @@ class B12Char extends B12Digit{ popMatrix(); } + void lineTimes(){ line(4,-7,8,-3); line(4,-3,8,-7); } + void dotsDiv(){ point(6,-8); point(6,-2); } void lineMinus(){ line(3,-5,9,-5); } + void linePlus(){ line(6,-8,6,-2); } void period(){ point(5,0); } void colon(){ point(5,-2); point(5,-8); } + + boolean inStr(char _c){ + try{ + int x = valid.indexOf(_c); + return true; + } + catch (Exception e){ + return false; + } + } } diff --git a/B12NumbersV3/B12Math.pde b/B12NumbersV3/B12Math.pde new file mode 100644 index 0000000..7a96bbd --- /dev/null +++ b/B12NumbersV3/B12Math.pde @@ -0,0 +1,15 @@ +class B12Math { + ArrayList expression; + + B12Math(){ + expression = new ArrayList();; + } + + void delete(int pos){ + expression.remove(pos); + } + + void evaluate(){ + //TODO set expression to evaluation of expression + } +} diff --git a/B12NumbersV3/B12NumbersV3.pde b/B12NumbersV3/B12NumbersV3.pde index 12f56a3..1348496 100644 --- a/B12NumbersV3/B12NumbersV3.pde +++ b/B12NumbersV3/B12NumbersV3.pde @@ -13,19 +13,25 @@ public static int DECIMAL = 65; Clock clock; +B12Char p; +B12Char t; void setup(){ size(400,400); clock = new Clock(new STime48()); println("waiting"); + p = new B12Char('+'); + t = new B12Char('/'); } void draw(){ background(196); translate(width/2,height/2); - scale(1); + scale(2); point(0,0); clock.display(); + //p.display(); + t.display(); } void mouseClicked(){ diff --git a/B12NumbersV3/MathDisplay.pde b/B12NumbersV3/MathDisplay.pde new file mode 100644 index 0000000..3ff4682 --- /dev/null +++ b/B12NumbersV3/MathDisplay.pde @@ -0,0 +1,16 @@ +class MathDisplay{ + B12Math math; + + + MathDisplay(B12Math _math){ + math = _math; + digits = new ArrayList(); + } + + // TODO take expression from math and display it in whatever state it is in + void display(){ + for(int i = 0; i < math.expression.size(); i++){ + + } + } +} diff --git a/B12NumbersV3/MathPad.pde b/B12NumbersV3/MathPad.pde new file mode 100644 index 0000000..f308113 --- /dev/null +++ b/B12NumbersV3/MathPad.pde @@ -0,0 +1,16 @@ +class MathPad{ + B12Math math; + + MathPad(B12Math _math){ + math = _math; + } + + // TODO draw a grid for buttons + // TODO draw characters in grid + // TODO detect mousepresses on the buttons (maybe a global mouse handler?) + // TODO send characters to math + + void addchar(){ + math.expression.add(new B12Char('/')); + } +} diff --git a/B12NumbersV3/Time.pde b/B12NumbersV3/Time.pde deleted file mode 100644 index 1caeac9..0000000 --- a/B12NumbersV3/Time.pde +++ /dev/null @@ -1,96 +0,0 @@ -/*class Time extends Thread{ - PVector pos; - B12Int hours; - B12Int minutes; - B12Int seconds; - B12Char sep; - B12Int fill; - int tmillis; - boolean initialized; - - Time(Time48 t48){ // TODO refactor time class - pos = new PVector(0,0); - hours = new B12Int(0); - minutes = new B12Int(0); - seconds = new B12Int(0); - sep = new B12Char(':'); - fill = new B12Int(0); - - hours.setMinLen(2); - minutes.setMinLen(2); - seconds.setMinLen(2); - - initialized = false; - this.start(); - //thread("this.runTime"); - } - - PVector getPos(){ return pos; } - void setPos(PVector _pos){ pos = _pos.copy(); } - void setPos(float _x, float _y){ pos = new PVector(_x,_y); } - - void setTime(int _h, int _m, int _s, boolean twelve){ - if(twelve){ - tmillis = int(((_h*48*48 + _m*48 + _s)*1562.5) - millis()); - }else{ - tmillis = (_h*60*60*1000 + _m*60*1000 + _s*1000) - millis(); - } - initialized = true; - } - - public void run(){ - while(true){ - if(!initialized){ sync(); } - if(tmillis + millis() > 86400000){ tmillis -= 86400000; } // Fall over at 00:00 - int sec48 = int((tmillis + millis()) / 1562.5); - int min48 = sec48 / 48; - int hour48 = min48 / 48; - sec48 -= min48 * 48; - min48 -= hour48 * 48; - //println(hour48 + ":" + min48 + ":" + sec48); - hours.setValue(hour48); - minutes.setValue(min48); - seconds.setValue(sec48); - } - } - - public void syncTime(){ initialized = false; } // Allows syncing after time starts running - private void sync(){ - int sec = second(); - tmillis = 0; - while(true){ - if(sec != second()){ - tmillis = second()*1000 + minute()*60*1000 + hour()*60*60*1000; - initialized = true; - break; - } - } - } - - void display(){ - if(initialized){ - // Position - - hours.setPos(-64, 0); - minutes.setPos(-32, 0); - seconds.setPos(0,0); - B12Char c1 = new B12Char(':'); - B12Char c2 = new B12Char(':'); - c1.setRefPos(-34,0); - c2.setRefPos(-66,0); - - // Display - pushMatrix(); - translate(pos.x,pos.y); - hours.display(); - c2.display(); - minutes.display(); - c1.display(); - seconds.display(); - popMatrix(); - //print(seconds.getValue()); - }else{ - text("initializing " + second(),pos.x,pos.y); - } - } -}*/