mirror of
https://github.com/opus-tango/B12NumbersV3.git
synced 2026-03-20 03:55:20 +00:00
0.2.1.1 - finished stopwatch
This commit is contained in:
@@ -7,6 +7,7 @@ abstract interface Number{
|
|||||||
class B12Digit implements Number{
|
class B12Digit implements Number{
|
||||||
private byte value;
|
private byte value;
|
||||||
private PVector refPos;
|
private PVector refPos;
|
||||||
|
private color col;
|
||||||
|
|
||||||
B12Digit(int _value){
|
B12Digit(int _value){
|
||||||
if(_value >= 12 || _value < 0){
|
if(_value >= 12 || _value < 0){
|
||||||
@@ -14,6 +15,7 @@ class B12Digit implements Number{
|
|||||||
}
|
}
|
||||||
value = byte(_value);
|
value = byte(_value);
|
||||||
refPos = new PVector(0,0);
|
refPos = new PVector(0,0);
|
||||||
|
col = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
B12Digit(char _c){
|
B12Digit(char _c){
|
||||||
@@ -21,17 +23,20 @@ class B12Digit implements Number{
|
|||||||
if(!inStr(valid, _c)){ throw new IllegalArgumentException("B12Char only accepts \'+ - * / . :'"); }
|
if(!inStr(valid, _c)){ throw new IllegalArgumentException("B12Char only accepts \'+ - * / . :'"); }
|
||||||
value = byte(_c);
|
value = byte(_c);
|
||||||
refPos = new PVector(0,0);
|
refPos = new PVector(0,0);
|
||||||
|
col = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// SETTERS
|
// SETTERS
|
||||||
B12Digit setPos(PVector _refPos){ refPos = _refPos; return this;}
|
B12Digit setPos(PVector _refPos){ refPos = _refPos; return this;}
|
||||||
B12Digit setPos(float _x, float _y){ refPos = new PVector(_x,_y); 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 setValue(int _value){ value = byte(_value); return this;}
|
||||||
|
B12Digit setCol(color _col){col = _col; return this;}
|
||||||
|
|
||||||
// GETTERS
|
// GETTERS
|
||||||
PVector getPos(){ return refPos; }
|
PVector getPos(){ return refPos; }
|
||||||
int getValue(){ return value; }
|
int getValue(){ return value; }
|
||||||
boolean isNum(){return value >= 0 && value < 12; }
|
boolean isNum(){return value >= 0 && value < 12; }
|
||||||
|
color getCol(){return col;}
|
||||||
|
|
||||||
// RENDER CHARACTERS
|
// RENDER CHARACTERS
|
||||||
void display(){
|
void display(){
|
||||||
@@ -39,7 +44,7 @@ class B12Digit implements Number{
|
|||||||
translate(refPos.x,refPos.y);
|
translate(refPos.x,refPos.y);
|
||||||
strokeWeight(1);
|
strokeWeight(1);
|
||||||
noFill();
|
noFill();
|
||||||
stroke(1);
|
stroke(col);
|
||||||
ellipseMode(CORNERS);
|
ellipseMode(CORNERS);
|
||||||
switch(value) {
|
switch(value) {
|
||||||
// NUMBERS //
|
// NUMBERS //
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ Calculator calc;
|
|||||||
|
|
||||||
//ClockApp ca;
|
//ClockApp ca;
|
||||||
Clock clock;
|
Clock clock;
|
||||||
|
Timer timer;
|
||||||
|
Stopwatch st;
|
||||||
|
|
||||||
Button mode;
|
Button mode;
|
||||||
Button changeTime;
|
Button changeTime;
|
||||||
@@ -28,6 +30,8 @@ void setup(){
|
|||||||
|
|
||||||
//ca = new ClockApp(mh, time).setPos(-43,0);
|
//ca = new ClockApp(mh, time).setPos(-43,0);
|
||||||
clock = new Clock(mh, time);//.setPos(40,20);
|
clock = new Clock(mh, time);//.setPos(40,20);
|
||||||
|
timer = new Timer(mh);
|
||||||
|
st = new Stopwatch(mh);
|
||||||
calc = new Calculator(mh, ex);
|
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"));
|
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();
|
//if(changeTime != null) changeTime.display();
|
||||||
//mode.display();
|
//mode.display();
|
||||||
|
|
||||||
clock.display();
|
//clock.display();
|
||||||
|
st.display();
|
||||||
//point(-15,0);
|
//point(-15,0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
51
B12NumbersV3/Stopwatch.pde
Normal file
51
B12NumbersV3/Stopwatch.pde
Normal file
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,6 +6,7 @@ class TimeDisplay {
|
|||||||
B12Int seconds;
|
B12Int seconds;
|
||||||
B12Digit[] digits;
|
B12Digit[] digits;
|
||||||
int tmillis;
|
int tmillis;
|
||||||
|
color col;
|
||||||
|
|
||||||
TimeDisplay(Time48 _t48) {
|
TimeDisplay(Time48 _t48) {
|
||||||
pos = new PVector(0, 0);
|
pos = new PVector(0, 0);
|
||||||
@@ -23,8 +24,10 @@ class TimeDisplay {
|
|||||||
// GETTERS and SETTERS //
|
// GETTERS and SETTERS //
|
||||||
PVector getPos() { return pos; }
|
PVector getPos() { return pos; }
|
||||||
Time48 getTime(){return t48;}
|
Time48 getTime(){return t48;}
|
||||||
|
color getCol(){return col;}
|
||||||
TimeDisplay setPos(PVector _pos) { pos = _pos.copy(); return this;}
|
TimeDisplay setPos(PVector _pos) { pos = _pos.copy(); return this;}
|
||||||
TimeDisplay setPos(float _x, float _y) { pos = new PVector(_x, _y);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) {
|
TimeDisplay setTime(Time48 _time) {
|
||||||
if(_time.getClass() == STime48.class){
|
if(_time.getClass() == STime48.class){
|
||||||
@@ -57,9 +60,10 @@ class TimeDisplay {
|
|||||||
digits = (B12Digit[])append(digits,new B12Digit(':'));
|
digits = (B12Digit[])append(digits,new B12Digit(':'));
|
||||||
digits = (B12Digit[])concat(digits,hours.getDigits());
|
digits = (B12Digit[])concat(digits,hours.getDigits());
|
||||||
|
|
||||||
|
|
||||||
// Position
|
// Position
|
||||||
for(int i = 0; i < digits.length; i++){
|
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
|
// Position
|
||||||
|
|||||||
100
B12NumbersV3/Timer.pde
Normal file
100
B12NumbersV3/Timer.pde
Normal file
@@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
Beta version of a clock in base 12.
|
Beta version of a clock in base 12.
|
||||||
by Nayan Sawyer
|
by Nayan Sawyer
|
||||||
started Mar 2022
|
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
|
Characters are a variation of Kaktovik Inupiaq numerals
|
||||||
reversed and in base 12 instead of 20. I take no credit
|
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
|
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.
|
for more details.
|
||||||
|
|
||||||
// DONE get clock input to work properly
|
|
||||||
// TODO finish clock applications
|
// TODO finish clock applications
|
||||||
// DONE switch B12Int from ArrayList to Array
|
|
||||||
// TODO add throwing exceptions to all contructors
|
// TODO add throwing exceptions to all contructors
|
||||||
// MAYBE start clock widget structure
|
|
||||||
// MAYBE add additional operations like power, log, and trig functions
|
// MAYBE add additional operations like power, log, and trig functions
|
||||||
|
|
||||||
|
changelog 0.2.1.2
|
||||||
|
- Finished Stopwatch
|
||||||
|
|
||||||
changelog 0.2.1.1
|
changelog 0.2.1.1
|
||||||
- Finished clock implementation
|
- Finished clock implementation
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user