From f160a7fadd3878a1fa0ec07be78da35f352f29e4 Mon Sep 17 00:00:00 2001 From: 61616 Date: Thu, 19 May 2022 17:35:10 -0400 Subject: [PATCH] 0.2.1.1 - finished stopwatch --- B12NumbersV3/B12Base.pde | 7 ++- B12NumbersV3/B12NumbersV3.pde | 7 ++- B12NumbersV3/Stopwatch.pde | 51 +++++++++++++++++ B12NumbersV3/TimeDisplay.pde | 6 +- B12NumbersV3/Timer.pde | 100 ++++++++++++++++++++++++++++++++++ B12NumbersV3/zchangelog.pde | 8 +-- 6 files changed, 172 insertions(+), 7 deletions(-) create mode 100644 B12NumbersV3/Stopwatch.pde create mode 100644 B12NumbersV3/Timer.pde diff --git a/B12NumbersV3/B12Base.pde b/B12NumbersV3/B12Base.pde index 95ca540..125efc2 100644 --- a/B12NumbersV3/B12Base.pde +++ b/B12NumbersV3/B12Base.pde @@ -7,6 +7,7 @@ abstract interface Number{ class B12Digit implements Number{ private byte value; private PVector refPos; + private color col; B12Digit(int _value){ if(_value >= 12 || _value < 0){ @@ -14,6 +15,7 @@ class B12Digit implements Number{ } value = byte(_value); refPos = new PVector(0,0); + col = 0; } B12Digit(char _c){ @@ -21,17 +23,20 @@ class B12Digit implements Number{ if(!inStr(valid, _c)){ throw new IllegalArgumentException("B12Char only accepts \'+ - * / . :'"); } value = byte(_c); refPos = new PVector(0,0); + col = 0; } // SETTERS B12Digit setPos(PVector _refPos){ refPos = _refPos; return this;} B12Digit setPos(float _x, float _y){ refPos = new PVector(_x,_y); return this;} B12Digit setValue(int _value){ value = byte(_value); return this;} + B12Digit setCol(color _col){col = _col; return this;} // GETTERS PVector getPos(){ return refPos; } int getValue(){ return value; } boolean isNum(){return value >= 0 && value < 12; } + color getCol(){return col;} // RENDER CHARACTERS void display(){ @@ -39,7 +44,7 @@ class B12Digit implements Number{ translate(refPos.x,refPos.y); strokeWeight(1); noFill(); - stroke(1); + stroke(col); ellipseMode(CORNERS); switch(value) { // NUMBERS // diff --git a/B12NumbersV3/B12NumbersV3.pde b/B12NumbersV3/B12NumbersV3.pde index 664c83d..cc21c8f 100644 --- a/B12NumbersV3/B12NumbersV3.pde +++ b/B12NumbersV3/B12NumbersV3.pde @@ -12,6 +12,8 @@ Calculator calc; //ClockApp ca; Clock clock; +Timer timer; +Stopwatch st; Button mode; Button changeTime; @@ -28,6 +30,8 @@ void setup(){ //ca = new ClockApp(mh, time).setPos(-43,0); clock = new Clock(mh, time);//.setPos(40,20); + timer = new Timer(mh); + st = new Stopwatch(mh); calc = new Calculator(mh, ex); 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")); @@ -50,7 +54,8 @@ void draw(){ //if(changeTime != null) changeTime.display(); //mode.display(); - clock.display(); + //clock.display(); + st.display(); //point(-15,0); } diff --git a/B12NumbersV3/Stopwatch.pde b/B12NumbersV3/Stopwatch.pde new file mode 100644 index 0000000..811cb42 --- /dev/null +++ b/B12NumbersV3/Stopwatch.pde @@ -0,0 +1,51 @@ +class Stopwatch{ + PVector pos; + MouseHandler mh; + STime48 time; + TimeDisplay td; + Button[] buttons; + boolean running; + color stopCol; + + Stopwatch(MouseHandler _mh){ + pos = new PVector(0,0); + mh = _mh; + time = new STime48().setTime(new Time48(0)); + td = new TimeDisplay(new Time48(0)); + buttons = new Button[0]; + running = false; + initialize(); + } + + void initialize(){ + stopCol = 100; + td.setPos(pos.x + 13*4 + 2,pos.y-2).setCol(stopCol); + buttons = (Button[])append(buttons, new Button(mh).setText("Start").setPos(new PVector(pos.x - 14 - 30,pos.y + 2)).setDim(new PVector(28,16)).setFunction(new MethodRelay(this, "startt")).setColor(220,150)); + buttons = (Button[])append(buttons, new Button(mh).setText("Stop").setPos(new PVector(pos.x - 14,pos.y + 2)).setDim(new PVector(28,16)).setFunction(new MethodRelay(this, "stopp")).setColor(220,150)); + buttons = (Button[])append(buttons, new Button(mh).setText("Reset").setPos(new PVector(pos.x + 16,pos.y + 2)).setDim(new PVector(28,16)).setFunction(new MethodRelay(this, "reset")).setColor(220,150)); + } + + void display(){ + for(int i = 0; i < buttons.length; i++){ + buttons[i].display(); + } + td.display(); + } + + void startt(){ + if(running) return; + td.setTime(time.setTime(td.getTime())).setCol(0); + running = true; + } + + void stopp(){ + if(!running )return; + td.setTime(new Time48(time)).setCol(stopCol); + running = false; + } + + void reset(){ + td.setTime(new Time48(0)).setCol(stopCol); + running = false; + } +} diff --git a/B12NumbersV3/TimeDisplay.pde b/B12NumbersV3/TimeDisplay.pde index 5763c61..dc61397 100644 --- a/B12NumbersV3/TimeDisplay.pde +++ b/B12NumbersV3/TimeDisplay.pde @@ -6,6 +6,7 @@ class TimeDisplay { B12Int seconds; B12Digit[] digits; int tmillis; + color col; TimeDisplay(Time48 _t48) { pos = new PVector(0, 0); @@ -23,8 +24,10 @@ class TimeDisplay { // GETTERS and SETTERS // PVector getPos() { return pos; } Time48 getTime(){return t48;} + color getCol(){return col;} TimeDisplay setPos(PVector _pos) { pos = _pos.copy(); return this;} TimeDisplay setPos(float _x, float _y) { pos = new PVector(_x, _y);return this;} + TimeDisplay setCol(color _col){col = _col; return this;} TimeDisplay setTime(Time48 _time) { if(_time.getClass() == STime48.class){ @@ -57,9 +60,10 @@ class TimeDisplay { digits = (B12Digit[])append(digits,new B12Digit(':')); digits = (B12Digit[])concat(digits,hours.getDigits()); + // Position for(int i = 0; i < digits.length; i++){ - digits[i].setPos(i*-13 + pos.x - 13,pos.y).display(); + digits[i].setPos(i*-13 + pos.x - 13,pos.y).setCol(col).display(); } // Position diff --git a/B12NumbersV3/Timer.pde b/B12NumbersV3/Timer.pde new file mode 100644 index 0000000..833e642 --- /dev/null +++ b/B12NumbersV3/Timer.pde @@ -0,0 +1,100 @@ +class Timer{ + PVector pos; + MouseHandler mh; + Button[] buttons; + Button setTimeButton; + boolean setTime; + int cursorPos; + STime48 time; + TimeDisplay td; + + Timer(MouseHandler _mh){ + pos = new PVector(0,0); + mh = _mh; + time = new STime48().setTime(new Time48(0));; + td = new TimeDisplay(time); + setTime = false; + cursorPos = 0; + initialize(); + } + + PVector getPos(){return pos;} + + Timer setPos(PVector _pos){pos = _pos.copy(); return this;} + Timer setPos(float x, float y){pos = new PVector(x,y); initialize(); return this;} + + void initialize(){ + buttons = new Button[0]; + td.setPos(pos.x + 13*4 + 2,pos.y-2); + // Create numpad buttons + for(int i = 0; i < 12; i++){ + /* Button position must contain it's absolute position relative to sketch 0,0 for mouseOver to work. + This means we cannot translate and traw buttons, we mumst factor the parents position into the + absolute position of the button */ + // x = pos.x + (width + gap) * (i%cols) + // y = pos.y + (height + gap) * b2rows - (height + gap) * row + PVector bPos = new PVector(pos.x + 22 * int(i%4) - 43,pos.y + 22 * 2 - 22 * floor(i/4) + 2); + buttons = (Button[])append(buttons, new B12Button(mh ,new B12Digit(i)).setPos(bPos).setDim(new PVector(20,20)).setFunction(new MethodRelay(this, "addChar", B12Digit.class)).setColor(220,150)); + } + // Create other buttons + buttons = (Button[])append(buttons, new Button(mh).setText("Set").setPos(new PVector(pos.x - 43,pos.y + 22*3 + 2)).setDim(new PVector(27,20)).setFunction(new MethodRelay(this, "lockTime")).setColor(220,150)); + buttons = (Button[])append(buttons, new Button(mh).setText("Clear").setPos(new PVector(pos.x + 29 - 43,pos.y + 22*3 + 2)).setDim(new PVector(28,20)).setFunction(new MethodRelay(this, "clearTime")).setColor(220,150)); + buttons = (Button[])append(buttons, new Button(mh).setText("Cancel").setPos(new PVector(pos.x + 59 - 43,pos.y + 22*3 + 2)).setDim(new PVector(27,20)).setFunction(new MethodRelay(this, "cancelSetTime")).setColor(220,150)); + + setTimeButton = new Button(mh).setText("Set Time").setPos(new PVector(pos.x-21,pos.y + 2)).setDim(new PVector(42,13)).setFunction(new MethodRelay(this, "triggerSetTime")).setColor(220,150); + + } + + void addChar(B12Digit digit){ + switch(cursorPos){ + case 0: + td.setTime(new Time48().setHour(digit.getValue() * 12)); cursorPos += 1; break; + case 1: + td.setTime(new Time48(td.getTime().tsec()).setHour(digit.getValue() + td.getTime().hours())); cursorPos += 2; break; + case 3: + td.setTime(new Time48(td.getTime().tsec()).setMin(digit.getValue() * 12)); cursorPos += 1; break; + case 4: + td.setTime(new Time48(td.getTime().tsec()).setMin(digit.getValue() + td.getTime().mins())); cursorPos += 2; break; + case 6: + td.setTime(new Time48(td.getTime().tsec()).setSec(digit.getValue() * 12)); cursorPos += 1; break; + case 7: + td.setTime(new Time48(td.getTime().tsec() + digit.getValue())); cursorPos += 1; break; + } + } + + void clearTime(){ + td.setTime(new Time48(0)); + cursorPos = 0; + } + + void lockTime(){ + time.setTime(td.getTime()); + td.setTime(time); + cursorPos = 0; + setTime = false; + } + + void triggerSetTime(){ + clearTime(); + setTime = true; + } + + void cancelSetTime(){ + td.setTime(time); + cursorPos = 0; + setTime = false; + } + + void display(){ + if(setTime){ + for(int i = 0; i < buttons.length; i++){ + buttons[i].display(); + } + stroke(0); + if(cursorPos < 8)line(pos.x - 13 * (4-cursorPos) + 2, pos.y, pos.x - 13 * (4-cursorPos) + 10, pos.y); + }else{ + setTimeButton.display(); + } + td.display(); + } +} diff --git a/B12NumbersV3/zchangelog.pde b/B12NumbersV3/zchangelog.pde index 9f18305..ef812ef 100644 --- a/B12NumbersV3/zchangelog.pde +++ b/B12NumbersV3/zchangelog.pde @@ -3,7 +3,7 @@ Beta version of a clock in base 12. by Nayan Sawyer started Mar 2022 - version 0.2.1.1 May 18 2022 + version 0.2.1.2 May 19 2022 Characters are a variation of Kaktovik Inupiaq numerals reversed and in base 12 instead of 20. I take no credit @@ -11,13 +11,13 @@ 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. - // DONE get clock input to work properly // TODO finish clock applications - // DONE switch B12Int from ArrayList to Array // 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.1.2 + - Finished Stopwatch + changelog 0.2.1.1 - Finished clock implementation