mirror of
https://github.com/opus-tango/B12NumbersV3.git
synced 2026-03-20 12:05:21 +00:00
0.2.1.0 - base changes and clock stuff
This commit is contained in:
@@ -24,8 +24,8 @@ class B12Digit implements Number{
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SETTERS
|
// SETTERS
|
||||||
B12Digit setRefPos(PVector _refPos){ refPos = _refPos; return this;}
|
B12Digit setPos(PVector _refPos){ refPos = _refPos; return this;}
|
||||||
B12Digit setRefPos(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;}
|
||||||
|
|
||||||
// GETTERS
|
// GETTERS
|
||||||
@@ -123,7 +123,7 @@ class B12Digit implements Number{
|
|||||||
|
|
||||||
|
|
||||||
class B12Int implements Number {
|
class B12Int implements Number {
|
||||||
private ArrayList<B12Digit> digits;
|
private B12Digit[] digits;
|
||||||
private int value;
|
private int value;
|
||||||
private PVector pos;
|
private PVector pos;
|
||||||
private boolean arrayLoaded;
|
private boolean arrayLoaded;
|
||||||
@@ -144,6 +144,11 @@ class B12Int implements Number {
|
|||||||
int getValue(){ return value; }
|
int getValue(){ return value; }
|
||||||
PVector getPos(){ return pos; }
|
PVector getPos(){ return pos; }
|
||||||
B12Float toFloat(){return new B12Float(float(value)); }
|
B12Float toFloat(){return new B12Float(float(value)); }
|
||||||
|
B12Digit[] getDigits(){
|
||||||
|
loadArray(); //<>//
|
||||||
|
B12Digit[] out = digits;
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
// SETTERS //
|
// SETTERS //
|
||||||
B12Int setValue(int _value){ value = _value; arrayLoaded = false; return this;}
|
B12Int setValue(int _value){ value = _value; arrayLoaded = false; return this;}
|
||||||
@@ -161,21 +166,21 @@ class B12Int implements Number {
|
|||||||
if(!inPosition){ positionDigits(); }
|
if(!inPosition){ positionDigits(); }
|
||||||
pushMatrix();
|
pushMatrix();
|
||||||
translate(pos.x,pos.y);
|
translate(pos.x,pos.y);
|
||||||
for(int i = 0; i < digits.size(); i++){
|
for(int i = 0; i < digits.length; i++){
|
||||||
digits.get(i).display();
|
digits[i].display();
|
||||||
}
|
}
|
||||||
popMatrix();
|
popMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void positionDigits(){
|
private void positionDigits(){
|
||||||
if(mode == LEFT || mode == DECIMAL){
|
if(mode == LEFT || mode == DECIMAL){
|
||||||
for(int i = 0; i < digits.size(); i++){
|
for(int i = 0; i < digits.length; i++){
|
||||||
digits.get(i).setRefPos((-12 * (i+1)), 0);
|
digits[i].setPos((-12 * (i+1)), 0);
|
||||||
}
|
}
|
||||||
}else if(mode == RIGHT){
|
}else if(mode == RIGHT){
|
||||||
int count = 0;
|
int count = 0;
|
||||||
for(int i = digits.size() - 1; i >= 0; i--){
|
for(int i = digits.length - 1; i >= 0; i--){
|
||||||
digits.get(count).setRefPos((12 * i) + 3, 0);
|
digits[count].setPos((12 * i) + 3, 0);
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -183,23 +188,23 @@ class B12Int implements Number {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void loadArray(){
|
private void loadArray(){
|
||||||
digits = new ArrayList<B12Digit>();
|
digits = new B12Digit[0];
|
||||||
int mval = abs(value);
|
int mval = abs(value);
|
||||||
if(mval == 0){ digits.add(new B12Digit(0)); }
|
if(mval == 0){ digits = (B12Digit[])append(digits, new B12Digit(0)); }
|
||||||
while(mval != 0){
|
while(mval != 0){
|
||||||
if(mval < 12){
|
if(mval < 12){
|
||||||
digits.add(new B12Digit(mval));
|
digits = (B12Digit[])append(digits, new B12Digit(mval));
|
||||||
mval = 0;
|
mval = 0;
|
||||||
}else{
|
}else{
|
||||||
digits.add(new B12Digit(mval % 12));
|
digits = (B12Digit[])append(digits, new B12Digit(mval % 12));
|
||||||
mval /= 12;
|
mval /= 12;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(digits.size() < minLen){
|
if(digits.length < minLen){
|
||||||
digits.add(new B12Digit(0));
|
digits = (B12Digit[])append(digits, new B12Digit(0));
|
||||||
}
|
}
|
||||||
if(value < 0){
|
if(value < 0){
|
||||||
digits.add(new B12Digit('-'));
|
digits = (B12Digit[])append(digits, new B12Digit('-'));
|
||||||
}
|
}
|
||||||
|
|
||||||
arrayLoaded = true;
|
arrayLoaded = true;
|
||||||
@@ -210,7 +215,6 @@ class B12Int implements Number {
|
|||||||
|
|
||||||
|
|
||||||
class B12Float implements Number{
|
class B12Float implements Number{
|
||||||
//private ArrayList<B12Digit> digits;
|
|
||||||
private B12Digit[] digits;
|
private B12Digit[] digits;
|
||||||
private float value;
|
private float value;
|
||||||
private PVector pos;
|
private PVector pos;
|
||||||
@@ -282,38 +286,38 @@ class B12Float implements Number{
|
|||||||
if(mode == LEFT){
|
if(mode == LEFT){
|
||||||
for(int i = 0; i < pointPlace; i++){
|
for(int i = 0; i < pointPlace; i++){
|
||||||
curPos += -12;
|
curPos += -12;
|
||||||
digits[i].setRefPos(curPos, 0);
|
digits[i].setPos(curPos, 0);
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
curPos += -8;
|
curPos += -8;
|
||||||
digits[count].setRefPos(curPos, 0);
|
digits[count].setPos(curPos, 0);
|
||||||
count++;
|
count++;
|
||||||
curPos += -6;
|
curPos += -6;
|
||||||
digits[count].setRefPos(curPos, 0);
|
digits[count].setPos(curPos, 0);
|
||||||
count++;
|
count++;
|
||||||
|
|
||||||
for(int i = count; i < digits.length; i++){
|
for(int i = count; i < digits.length; i++){
|
||||||
curPos += -12;
|
curPos += -12;
|
||||||
digits[i].setRefPos(curPos, 0);
|
digits[i].setPos(curPos, 0);
|
||||||
}
|
}
|
||||||
}else if(mode == DECIMAL){
|
}else if(mode == DECIMAL){
|
||||||
curPos = -5;
|
curPos = -5;
|
||||||
digits[pointPlace].setRefPos(curPos,0);
|
digits[pointPlace].setPos(curPos,0);
|
||||||
curPos += -2;
|
curPos += -2;
|
||||||
for(int i = pointPlace - 1; i >= 0; i--){
|
for(int i = pointPlace - 1; i >= 0; i--){
|
||||||
curPos += 12;
|
curPos += 12;
|
||||||
digits[i].setRefPos(curPos,0);
|
digits[i].setPos(curPos,0);
|
||||||
}
|
}
|
||||||
curPos = -2;
|
curPos = -2;
|
||||||
|
|
||||||
for(int i = pointPlace + 1; i < digits.length; i++){
|
for(int i = pointPlace + 1; i < digits.length; i++){
|
||||||
curPos += -12;
|
curPos += -12;
|
||||||
digits[i].setRefPos(curPos,0);
|
digits[i].setPos(curPos,0);
|
||||||
}
|
}
|
||||||
}else if(mode == RIGHT){
|
}else if(mode == RIGHT){
|
||||||
for(int i = digits.length - 1; i >= 0; i--){
|
for(int i = digits.length - 1; i >= 0; i--){
|
||||||
digits[count].setRefPos((12 * i) + 3, 0);
|
digits[count].setPos((12 * i) + 3, 0);
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,10 @@ MouseHandler mh; // Mouse event handler
|
|||||||
|
|
||||||
B12Expression ex;
|
B12Expression ex;
|
||||||
Calculator calc;
|
Calculator calc;
|
||||||
|
|
||||||
|
//ClockApp ca;
|
||||||
Clock clock;
|
Clock clock;
|
||||||
|
|
||||||
Button mode;
|
Button mode;
|
||||||
Button changeTime;
|
Button changeTime;
|
||||||
STime48 time;
|
STime48 time;
|
||||||
@@ -17,12 +20,14 @@ STime48 time;
|
|||||||
|
|
||||||
|
|
||||||
void setup(){
|
void setup(){
|
||||||
size(800,800);
|
size(800,800); //<>//
|
||||||
offset = new PVector(width/2, height/2);
|
offset = new PVector(width/2, height/2);
|
||||||
time = new STime48();
|
time = new STime48();
|
||||||
mh = new MouseHandler(new MouseData(offset, scale));
|
mh = new MouseHandler(new MouseData(offset, scale));
|
||||||
ex = new B12Expression();
|
ex = new B12Expression();
|
||||||
|
|
||||||
|
//ca = new ClockApp(mh, time).setPos(-43,0);
|
||||||
|
clock = new Clock(mh, time);
|
||||||
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"));
|
||||||
@@ -36,14 +41,16 @@ void draw(){
|
|||||||
mh.frameUpdate(offset, scale);
|
mh.frameUpdate(offset, scale);
|
||||||
stroke(0);
|
stroke(0);
|
||||||
strokeWeight(1);
|
strokeWeight(1);
|
||||||
//crossMark();
|
crossMark();
|
||||||
translate(offset.x,offset.y);
|
translate(offset.x,offset.y);
|
||||||
scale(scale);
|
scale(scale);
|
||||||
|
|
||||||
if(calc != null) calc.display();
|
//if(calc != null) calc.display();
|
||||||
if(clock != null) clock.display();
|
//if(clock != null) clock.display();
|
||||||
if(changeTime != null) changeTime.display();
|
//if(changeTime != null) changeTime.display();
|
||||||
mode.display();
|
//mode.display();
|
||||||
|
|
||||||
|
clock.display();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,14 +70,14 @@ void call(String _call){
|
|||||||
|
|
||||||
void changeMode(){
|
void changeMode(){
|
||||||
if(calc == null){
|
if(calc == null){
|
||||||
clock = null;
|
//clock = null;
|
||||||
changeTime = null;
|
changeTime = null;
|
||||||
calc = new Calculator(mh, ex);
|
calc = new Calculator(mh, ex);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
calc = null;
|
calc = null;
|
||||||
clock = new Clock(time).setPos(new PVector(30,0));
|
//clock = new Clock(time).setPos(new PVector(30,0));
|
||||||
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 = 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));
|
changeTime.setData(new Time48(12,0,0));
|
||||||
Runtime.getRuntime().gc();
|
Runtime.getRuntime().gc();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -146,67 +146,3 @@ class STime48 extends Time48{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Clock {
|
|
||||||
PVector pos;
|
|
||||||
STime48 t48;
|
|
||||||
B12Int hours;
|
|
||||||
B12Int minutes;
|
|
||||||
B12Int seconds;
|
|
||||||
B12Digit sep; // TODO Just deprecated B12Char. Refactor to single array of B12Digits?
|
|
||||||
int tmillis;
|
|
||||||
|
|
||||||
Clock(STime48 _t48) {
|
|
||||||
pos = new PVector(0, 0);
|
|
||||||
t48 = _t48;
|
|
||||||
hours = new B12Int(t48.hours());
|
|
||||||
minutes = new B12Int(t48.mins());
|
|
||||||
seconds = new B12Int(t48.secs());
|
|
||||||
sep = new B12Digit(':'); // Seperation character between time columns
|
|
||||||
|
|
||||||
hours.setMinLen(2);
|
|
||||||
minutes.setMinLen(2); // Format all the ints to show a 0 in the 12s column if they are less than 12
|
|
||||||
seconds.setMinLen(2);
|
|
||||||
}
|
|
||||||
|
|
||||||
// GETTERS and SETTERS //
|
|
||||||
PVector getPos() { return pos; }
|
|
||||||
Clock setPos(PVector _pos) { pos = _pos.copy(); return this;}
|
|
||||||
Clock setPos(float _x, float _y) { pos = new PVector(_x, _y);return this;}
|
|
||||||
|
|
||||||
Clock setTime(Time48 _time) { t48.setTime(_time); return this;}
|
|
||||||
Clock resetTime() { t48.setTime(new Time48(0)); return this;}
|
|
||||||
|
|
||||||
void display() {
|
|
||||||
if (t48.synced()) {
|
|
||||||
// Time
|
|
||||||
hours.setValue(t48.hours());
|
|
||||||
minutes.setValue(t48.mins());
|
|
||||||
seconds.setValue(t48.secs());
|
|
||||||
|
|
||||||
// Position
|
|
||||||
hours.setPos(-64, 0);
|
|
||||||
minutes.setPos(-32, 0);
|
|
||||||
seconds.setPos(0, 0);
|
|
||||||
B12Digit c1 = new B12Digit(':');
|
|
||||||
B12Digit c2 = new B12Digit(':');
|
|
||||||
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();
|
|
||||||
} else {
|
|
||||||
text("fetching current time", pos.x, pos.y);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -96,6 +96,7 @@ class Button{
|
|||||||
if(mouseOver && mouseButton == LEFT){
|
if(mouseOver && mouseButton == LEFT){
|
||||||
//println("clicked" + this);
|
//println("clicked" + this);
|
||||||
function.execute(data);
|
function.execute(data);
|
||||||
|
mouseOver = false; // Very important. Without this a button retains its mouseOver status forever if it stops being displayed
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,3 +1,22 @@
|
|||||||
|
class Calculator{
|
||||||
|
B12Expression ex;
|
||||||
|
MathPad m;
|
||||||
|
MathDisplay d;
|
||||||
|
|
||||||
|
Calculator(MouseHandler _mh, B12Expression _ex){
|
||||||
|
ex = _ex;
|
||||||
|
m = new MathPad(_mh, ex).setPos(new PVector(-40,0));
|
||||||
|
d = new MathDisplay(ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
void display(){
|
||||||
|
rect(85,-22,1,14);
|
||||||
|
d.setPos(new PVector(83,-10));
|
||||||
|
m.display();
|
||||||
|
d.display();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class B12Expression {
|
class B12Expression {
|
||||||
private B12Digit[] expression;
|
private B12Digit[] expression;
|
||||||
|
|
||||||
@@ -35,7 +54,7 @@ class B12Expression {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void evaluate(){
|
void evaluate(){
|
||||||
String evalString = parseDigits(); //<>//
|
String evalString = parseDigits();
|
||||||
Expression exp = new ExpressionBuilder(evalString).build();
|
Expression exp = new ExpressionBuilder(evalString).build();
|
||||||
expression = new B12Float((float)exp.evaluate()).setPlaces(12).getDigits();
|
expression = new B12Float((float)exp.evaluate()).setPlaces(12).getDigits();
|
||||||
println(exp.evaluate());
|
println(exp.evaluate());
|
||||||
@@ -152,3 +171,122 @@ class B12Expression {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class MathDisplay {
|
||||||
|
PVector pos;
|
||||||
|
B12Expression ex;
|
||||||
|
|
||||||
|
MathDisplay(B12Expression _ex){
|
||||||
|
ex = _ex;
|
||||||
|
pos = new PVector(0,0);
|
||||||
|
}
|
||||||
|
|
||||||
|
PVector getPos(){ return pos; }
|
||||||
|
MathDisplay setPos(PVector _pos){ pos = _pos; return this;}
|
||||||
|
|
||||||
|
void display(){
|
||||||
|
pushMatrix();
|
||||||
|
translate(pos.x,pos.y);
|
||||||
|
int count = 0;
|
||||||
|
for(int i = ex.length() - 1; i >= 0 ; i--){
|
||||||
|
ex.getDigit(i).setPos((-12 * (count+1)), 0);
|
||||||
|
ex.getDigit(i).display();
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
popMatrix();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class MathPad{
|
||||||
|
private B12Expression ex;
|
||||||
|
private MouseHandler mh;
|
||||||
|
private Button[] buttons;
|
||||||
|
private PVector pos;
|
||||||
|
|
||||||
|
MathPad(MouseHandler _mh, B12Expression _ex){
|
||||||
|
ex = _ex;
|
||||||
|
mh = _mh;
|
||||||
|
pos = new PVector(0,0);
|
||||||
|
buttons = new Button[0];
|
||||||
|
initialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
// GETTERS AND SETTERS //
|
||||||
|
PVector getPos(){return pos;}
|
||||||
|
MathPad setPos(PVector _pos){
|
||||||
|
pos = _pos.copy();
|
||||||
|
initialize();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void initialize(){
|
||||||
|
buttons = new Button[0];
|
||||||
|
// 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),pos.y + 22 * 3 - 22 * floor(i/4));
|
||||||
|
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 B12Button(mh, new B12Digit('(')).setPos(new PVector(pos.x,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,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*2,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*3,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)).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("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));
|
||||||
|
}
|
||||||
|
|
||||||
|
void addChar(B12Digit _digit){
|
||||||
|
ex.addChar(_digit);
|
||||||
|
}
|
||||||
|
|
||||||
|
void display(){
|
||||||
|
for(int i = 0; i < buttons.length; i++){
|
||||||
|
buttons[i].display();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class B12Button extends Button{
|
||||||
|
B12Digit digit;
|
||||||
|
|
||||||
|
B12Button(MouseHandler _mh, B12Digit _digit){
|
||||||
|
super(_mh);
|
||||||
|
digit = _digit;
|
||||||
|
setData(_digit);
|
||||||
|
}
|
||||||
|
|
||||||
|
// GETTERS AND SETTERS //
|
||||||
|
B12Digit getDigit(){ return digit; }
|
||||||
|
B12Button setDigit(B12Digit _digit){ digit = _digit; return this; }
|
||||||
|
|
||||||
|
// Add drawing the B12Digit to the display method
|
||||||
|
@Override
|
||||||
|
void display(){
|
||||||
|
super.display();
|
||||||
|
|
||||||
|
pushMatrix();
|
||||||
|
|
||||||
|
translate(super.pos.x,super.pos.y);
|
||||||
|
switch(super.mode){
|
||||||
|
case CORNER: digit.setPos(super.dim.x/2 - 4, super.dim.y - 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
digit.display();
|
||||||
|
|
||||||
|
popMatrix();
|
||||||
|
}
|
||||||
|
}
|
||||||
78
B12NumbersV3/Clock.pde
Normal file
78
B12NumbersV3/Clock.pde
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
class Clock{
|
||||||
|
PVector pos;
|
||||||
|
MouseHandler mh;
|
||||||
|
Button[] buttons;
|
||||||
|
Button setTimeButton;
|
||||||
|
boolean setTime;
|
||||||
|
int cursorPos;
|
||||||
|
STime48 time;
|
||||||
|
TimeDisplay td;
|
||||||
|
|
||||||
|
Clock(MouseHandler _mh, STime48 _time){
|
||||||
|
pos = new PVector(0,0);
|
||||||
|
mh = _mh;
|
||||||
|
time = _time;
|
||||||
|
td = new TimeDisplay(time);
|
||||||
|
setTime = false;
|
||||||
|
cursorPos = 0;
|
||||||
|
initialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
PVector getPos(){return pos;}
|
||||||
|
|
||||||
|
Clock setPos(PVector _pos){pos = _pos.copy(); return this;}
|
||||||
|
Clock setPos(float x, float y){pos = new PVector(x,y); initialize(); return this;}
|
||||||
|
|
||||||
|
void initialize(){
|
||||||
|
buttons = new Button[0];
|
||||||
|
td.setPos(pos.x,pos.y);
|
||||||
|
// 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),pos.y + 22 * 2 - 22 * floor(i/4));
|
||||||
|
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,pos.y + 22*3)).setDim(new PVector(42,20)).setFunction(new MethodRelay(this, "lockTime")).setColor(220,150));
|
||||||
|
buttons = (Button[])append(buttons, new Button(mh).setText("Clear").setPos(new PVector(pos.x + 22*2,pos.y + 22*3)).setDim(new PVector(42,20)).setFunction(new MethodRelay(this, "clearTime")).setColor(220,150));
|
||||||
|
|
||||||
|
setTimeButton = new Button(mh).setText("Set Time").setPos(new PVector(pos.x+21,pos.y)).setDim(new PVector(42,13)).setFunction(new MethodRelay(this, "triggerSetTime")).setColor(220,150);
|
||||||
|
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
void addChar(B12Digit digit){
|
||||||
|
switch(cursorPos){
|
||||||
|
}
|
||||||
|
cursorPos
|
||||||
|
}*/
|
||||||
|
|
||||||
|
void clearTime(){
|
||||||
|
td.setTime(new Time48(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
void lockTime(){
|
||||||
|
time.setTime(td.getTime());
|
||||||
|
td.setTime(time);
|
||||||
|
setTime = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void triggerSetTime(){
|
||||||
|
clearTime();
|
||||||
|
setTime = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void display(){
|
||||||
|
if(setTime){
|
||||||
|
for(int i = 0; i < buttons.length; i++){
|
||||||
|
buttons[i].display();
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
setTimeButton.display();
|
||||||
|
}
|
||||||
|
td.display();
|
||||||
|
}
|
||||||
|
}
|
||||||
97
B12NumbersV3/ClockApp.pde
Normal file
97
B12NumbersV3/ClockApp.pde
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
class ClockApp{
|
||||||
|
PVector pos;
|
||||||
|
MouseHandler mh;
|
||||||
|
Button[] buttons;
|
||||||
|
Button modeButton;
|
||||||
|
Button setTimeButton;
|
||||||
|
int mode;
|
||||||
|
boolean setTime;
|
||||||
|
Time48 time;
|
||||||
|
TimeDisplay td;
|
||||||
|
|
||||||
|
ClockApp(MouseHandler _mh, Time48 _time){
|
||||||
|
pos = new PVector(0,0);
|
||||||
|
mh = _mh;
|
||||||
|
time = _time;
|
||||||
|
td = new TimeDisplay(time);
|
||||||
|
mode = 0;
|
||||||
|
initialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
PVector getPos(){return pos;}
|
||||||
|
|
||||||
|
ClockApp setPos(PVector _pos){pos = _pos.copy(); return this;}
|
||||||
|
ClockApp setPos(float x, float y){pos = new PVector(x,y); initialize(); return this;}
|
||||||
|
ClockApp setMode(int _mode){
|
||||||
|
if(_mode == -1){setTime = true; return this;}
|
||||||
|
mode = _mode;
|
||||||
|
initialize();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
void initialize(){
|
||||||
|
buttons = new Button[0];
|
||||||
|
td.setPos(43,-4);
|
||||||
|
|
||||||
|
if(mode == 0){
|
||||||
|
setTimeButton = new Button(mh).setText("Set Time").setPos(new PVector(pos.x+21,pos.y)).setDim(new PVector(42,13)).setFunction(new MethodRelay(this, "setMode", int.class)).setData(-1).setColor(220,150);
|
||||||
|
|
||||||
|
// 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),pos.y + 22 * 2 - 22 * floor(i/4));
|
||||||
|
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,pos.y + 22*3)).setDim(new PVector(42,20)).setFunction(new MethodRelay(this, "evaluate")).setColor(220,150));
|
||||||
|
buttons = (Button[])append(buttons, new Button(mh).setText("Clear").setPos(new PVector(pos.x + 22*2,pos.y + 22*3)).setDim(new PVector(42,20)).setFunction(new MethodRelay(this, "clear")).setColor(220,150));
|
||||||
|
}
|
||||||
|
else if(mode == 1){
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void display(){
|
||||||
|
switch(mode){
|
||||||
|
case 0:
|
||||||
|
clock(); break;
|
||||||
|
case 1:
|
||||||
|
stopwatch(); break;
|
||||||
|
case 2:
|
||||||
|
timer(); break;
|
||||||
|
case 3:
|
||||||
|
setTime(); break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setTime(){
|
||||||
|
for(int i = 0; i < buttons.length; i++){
|
||||||
|
buttons[i].display();
|
||||||
|
}
|
||||||
|
td.display();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void clock(){
|
||||||
|
td.display();
|
||||||
|
if(!setTime){
|
||||||
|
setTimeButton.display();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int i = 0; i < buttons.length; i++){
|
||||||
|
buttons[i].display();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void timer(){
|
||||||
|
}
|
||||||
|
|
||||||
|
private void stopwatch(){
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
84
B12NumbersV3/TimeDisplay.pde
Normal file
84
B12NumbersV3/TimeDisplay.pde
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
class TimeDisplay {
|
||||||
|
PVector pos;
|
||||||
|
Time48 t48;
|
||||||
|
B12Int hours;
|
||||||
|
B12Int minutes;
|
||||||
|
B12Int seconds;
|
||||||
|
B12Digit[] digits;
|
||||||
|
int tmillis;
|
||||||
|
|
||||||
|
TimeDisplay(Time48 _t48) {
|
||||||
|
pos = new PVector(0, 0);
|
||||||
|
t48 = _t48;
|
||||||
|
hours = new B12Int(t48.hours());
|
||||||
|
minutes = new B12Int(t48.mins());
|
||||||
|
seconds = new B12Int(t48.secs());
|
||||||
|
//sep = new B12Digit(':'); // Seperation character between time columns
|
||||||
|
|
||||||
|
hours.setMinLen(2);
|
||||||
|
minutes.setMinLen(2); // Format all the ints to show a 0 in the 12s column if they are less than 12
|
||||||
|
seconds.setMinLen(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
// GETTERS and SETTERS //
|
||||||
|
PVector getPos() { return pos; }
|
||||||
|
Time48 getTime(){return t48;}
|
||||||
|
TimeDisplay setPos(PVector _pos) { pos = _pos.copy(); return this;}
|
||||||
|
TimeDisplay setPos(float _x, float _y) { pos = new PVector(_x, _y);return this;}
|
||||||
|
|
||||||
|
TimeDisplay setTime(Time48 _time) {
|
||||||
|
if(_time.getClass() == STime48.class){
|
||||||
|
t48 = _time;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
t48 = _time.copy();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
TimeDisplay resetTime(){ // TODO test this. does it work?
|
||||||
|
if(t48.getClass() != STime48.class){ println("Cannot reset a static time"); return this;}
|
||||||
|
t48 = ((STime48)t48).setTime(new Time48(0));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
void display() {
|
||||||
|
digits = new B12Digit[0];
|
||||||
|
if(t48.getClass() == STime48.class){
|
||||||
|
while(!((STime48)t48).synced()){text("fetching current time", pos.x, pos.y);}
|
||||||
|
}
|
||||||
|
// Time
|
||||||
|
hours.setValue(t48.hours());
|
||||||
|
minutes.setValue(t48.mins());
|
||||||
|
seconds.setValue(t48.secs());
|
||||||
|
|
||||||
|
digits = (B12Digit[])concat(digits,seconds.getDigits());
|
||||||
|
digits = (B12Digit[])append(digits,new B12Digit(':'));
|
||||||
|
digits = (B12Digit[])concat(digits,minutes.getDigits());
|
||||||
|
digits = (B12Digit[])append(digits,new B12Digit(':'));
|
||||||
|
digits = (B12Digit[])concat(digits,hours.getDigits());
|
||||||
|
|
||||||
|
for(int i = 0; i < digits.length; i++){
|
||||||
|
digits[i].setPos(i*-13 + pos.x,pos.y).display();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Position
|
||||||
|
/*
|
||||||
|
hours.setPos(-64, 0);
|
||||||
|
minutes.setPos(-32, 0);
|
||||||
|
seconds.setPos(0, 0);
|
||||||
|
B12Digit c1 = new B12Digit(':');
|
||||||
|
B12Digit c2 = new B12Digit(':');
|
||||||
|
c1.setPos(-34, 0);
|
||||||
|
c2.setPos(-66, 0);
|
||||||
|
|
||||||
|
// Display
|
||||||
|
pushMatrix();
|
||||||
|
translate(pos.x, pos.y);
|
||||||
|
hours.display();
|
||||||
|
c2.display();
|
||||||
|
minutes.display();
|
||||||
|
c1.display();
|
||||||
|
seconds.display();
|
||||||
|
popMatrix();*/
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
class Calculator{
|
|
||||||
B12Expression ex;
|
|
||||||
MathPad m;
|
|
||||||
MathDisplay d;
|
|
||||||
|
|
||||||
Calculator(MouseHandler _mh, B12Expression _ex){
|
|
||||||
ex = _ex;
|
|
||||||
m = new MathPad(_mh, ex).setPos(new PVector(-40,0));
|
|
||||||
d = new MathDisplay(ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
void display(){
|
|
||||||
rect(85,-22,1,14);
|
|
||||||
d.setPos(new PVector(83,-10));
|
|
||||||
m.display();
|
|
||||||
d.display();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
class MathDisplay {
|
|
||||||
PVector pos;
|
|
||||||
B12Expression ex;
|
|
||||||
|
|
||||||
MathDisplay(B12Expression _ex){
|
|
||||||
ex = _ex;
|
|
||||||
pos = new PVector(0,0);
|
|
||||||
}
|
|
||||||
|
|
||||||
PVector getPos(){ return pos; }
|
|
||||||
MathDisplay setPos(PVector _pos){ pos = _pos; return this;}
|
|
||||||
|
|
||||||
void display(){
|
|
||||||
pushMatrix();
|
|
||||||
translate(pos.x,pos.y);
|
|
||||||
int count = 0;
|
|
||||||
for(int i = ex.length() - 1; i >= 0 ; i--){
|
|
||||||
ex.getDigit(i).setRefPos((-12 * (count+1)), 0);
|
|
||||||
ex.getDigit(i).display();
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
popMatrix();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,92 +0,0 @@
|
|||||||
|
|
||||||
class MathPad{
|
|
||||||
private B12Expression ex;
|
|
||||||
private MouseHandler mh;
|
|
||||||
private Button[] buttons;
|
|
||||||
private PVector pos;
|
|
||||||
|
|
||||||
MathPad(MouseHandler _mh, B12Expression _ex){
|
|
||||||
ex = _ex;
|
|
||||||
mh = _mh;
|
|
||||||
pos = new PVector(0,0);
|
|
||||||
buttons = new Button[0];
|
|
||||||
initialize();
|
|
||||||
}
|
|
||||||
|
|
||||||
// GETTERS AND SETTERS //
|
|
||||||
PVector getPos(){return pos;}
|
|
||||||
MathPad setPos(PVector _pos){
|
|
||||||
pos = _pos.copy();
|
|
||||||
initialize();
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void initialize(){
|
|
||||||
buttons = new Button[0];
|
|
||||||
// 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),pos.y + 22 * 3 - 22 * floor(i/4));
|
|
||||||
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 B12Button(mh, new B12Digit('(')).setPos(new PVector(pos.x,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,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*2,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*3,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)).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("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));
|
|
||||||
}
|
|
||||||
|
|
||||||
void addChar(B12Digit _digit){
|
|
||||||
ex.addChar(_digit);
|
|
||||||
}
|
|
||||||
|
|
||||||
void display(){
|
|
||||||
for(int i = 0; i < buttons.length; i++){
|
|
||||||
buttons[i].display();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class B12Button extends Button{
|
|
||||||
B12Digit digit;
|
|
||||||
|
|
||||||
B12Button(MouseHandler _mh, B12Digit _digit){
|
|
||||||
super(_mh);
|
|
||||||
digit = _digit;
|
|
||||||
setData(_digit);
|
|
||||||
}
|
|
||||||
|
|
||||||
// GETTERS AND SETTERS //
|
|
||||||
B12Digit getDigit(){ return digit; }
|
|
||||||
B12Button setDigit(B12Digit _digit){ digit = _digit; return this; }
|
|
||||||
|
|
||||||
// Add drawing the B12Digit to the display method
|
|
||||||
@Override
|
|
||||||
void display(){
|
|
||||||
super.display();
|
|
||||||
|
|
||||||
pushMatrix();
|
|
||||||
|
|
||||||
translate(super.pos.x,super.pos.y);
|
|
||||||
switch(super.mode){
|
|
||||||
case CORNER: digit.setRefPos(super.dim.x/2 - 4, super.dim.y - 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
digit.display();
|
|
||||||
|
|
||||||
popMatrix();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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.0.0 April 30 2022
|
version 0.2.1.0 May 18 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
|
||||||
@@ -17,6 +17,10 @@
|
|||||||
// MAYBE start clock widget structure
|
// 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.0
|
||||||
|
- Changes to the base code and the beginning of the clock
|
||||||
|
applications. File condensing (will be reversed)
|
||||||
|
|
||||||
changelog 0.2.0.0
|
changelog 0.2.0.0
|
||||||
- Evaluating expressions has been fully implemented using
|
- Evaluating expressions has been fully implemented using
|
||||||
exp4j. Various things have been added to the base classes
|
exp4j. Various things have been added to the base classes
|
||||||
|
|||||||
Reference in New Issue
Block a user