mirror of
https://github.com/opus-tango/B12NumbersV3.git
synced 2026-03-20 12:05:21 +00:00
0.1.5.7 - presentation display setup done
This commit is contained in:
@@ -4,23 +4,25 @@ PVector offset;
|
||||
public static final int DECIMAL = 65;
|
||||
MouseHandler mh; // Mouse event handler
|
||||
|
||||
B12Expression ex;
|
||||
Calculator calc;
|
||||
Button reset;
|
||||
Button eval;
|
||||
Clock clock;
|
||||
Button mode;
|
||||
Button changeTime;
|
||||
STime48 time;
|
||||
|
||||
|
||||
|
||||
void setup(){
|
||||
size(400,400);
|
||||
offset = new PVector(width/4, height/4);
|
||||
offset = new PVector(width/2, height/2);
|
||||
time = new STime48();
|
||||
mh = new MouseHandler(new MouseData(offset, scale));
|
||||
ex = new B12Expression();
|
||||
|
||||
calc = new Calculator(mh);
|
||||
calc = new Calculator(mh, ex);
|
||||
|
||||
reset = new Button(mh).setPos(new PVector(20,-20), new PVector(40,20)).setRadius(2).setColor(#06BA63).autoHighlight().setText("Reset").setFunction(new MethodRelay(this, "reset"));
|
||||
eval = new Button(mh).setPos(new PVector(20,-40), new PVector(40,20)).setRadius(2).setColor(#06BA63).autoHighlight().setText("Eval").setFunction(new MethodRelay(calc.ex, "evaluate"));
|
||||
|
||||
|
||||
|
||||
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"));
|
||||
}
|
||||
|
||||
void draw(){
|
||||
@@ -28,15 +30,14 @@ void draw(){
|
||||
mh.frameUpdate(offset, scale);
|
||||
stroke(0);
|
||||
strokeWeight(1);
|
||||
crossMark();
|
||||
//crossMark();
|
||||
translate(offset.x,offset.y);
|
||||
scale(scale);
|
||||
|
||||
if(calc != null) calc.display();
|
||||
reset.display();
|
||||
eval.display();
|
||||
|
||||
|
||||
if(clock != null) clock.display();
|
||||
if(changeTime != null) changeTime.display();
|
||||
mode.display();
|
||||
}
|
||||
|
||||
void mouseClicked(){
|
||||
@@ -55,11 +56,15 @@ void call(String _call){
|
||||
|
||||
void changeMode(){
|
||||
if(calc == null){
|
||||
calc = new Calculator(mh);
|
||||
eval.setFunction(new MethodRelay(calc.ex, "evaluate"));
|
||||
clock = null;
|
||||
changeTime = null;
|
||||
calc = new Calculator(mh, ex);
|
||||
return;
|
||||
}
|
||||
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.setData(new Time48(12,0,0));
|
||||
Runtime.getRuntime().gc();
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ class Time48 extends Thread{
|
||||
private boolean initialized;
|
||||
|
||||
// CONSTRUCTORS //
|
||||
// TODO add exceptions to all contructors
|
||||
// TODO add throwing exceptions to all contructors
|
||||
Time48(){
|
||||
sec48 = 0;
|
||||
min48 = 0;
|
||||
|
||||
@@ -35,22 +35,25 @@ class B12Expression {
|
||||
}
|
||||
|
||||
void evaluate(){
|
||||
//db println("evaluate"); //<>//
|
||||
String evalString = parseDigits();
|
||||
println(evalString);
|
||||
//<>// //<>//
|
||||
}
|
||||
|
||||
private String parseDigits(){
|
||||
String valid = "+*-/"; // valid characters to accept
|
||||
String evalString = ""; // gets filled with the expression up for evaluation in base 10
|
||||
B12Digit[] cnum = new B12Digit[0]; // used to sum numbers as the array is parsed
|
||||
boolean cfs = false; // float status of currently building number
|
||||
//int count = 0; // counts what column we're at for multiplying base 12 to base 10
|
||||
|
||||
|
||||
// Parse expression[] into a base 10 string that can be evaluated mathematically
|
||||
if(!(expression[expression.length - 1].isNum() || expression[expression.length -1].getValue() == ')' )){throw new IllegalArgumentException("Invalid input");} // check that final character is a number
|
||||
//db println("final char is valid");
|
||||
for (int c = expression.length; c >= 0; c--){
|
||||
//db println("top of for loop " + c);
|
||||
|
||||
int i = c - 1;
|
||||
|
||||
if (i == -1){ // At the end, add the final number if neccessary //<>//
|
||||
if (i == -1){ // At the end, add the final number if neccessary
|
||||
// add number to string if present
|
||||
if(cnum.length != 0 && cfs == false){
|
||||
B12Int num = (B12Int)convert(cnum,cfs);
|
||||
@@ -65,15 +68,13 @@ class B12Expression {
|
||||
}
|
||||
break;
|
||||
}
|
||||
//db println("passed finish clause loop " + c);
|
||||
|
||||
// If there is no number currently being built and the current character is a number start building a new number
|
||||
if (expression[i].isNum() && cnum.length == 0){
|
||||
//count = 0;
|
||||
cnum = (B12Digit[])append(cnum,expression[i]);
|
||||
}
|
||||
// If the current character is a number and there IS a number currently being built add the character into the number
|
||||
else if (expression[i].isNum() && cnum.length != 0){
|
||||
//count += 1;
|
||||
cnum = (B12Digit[])append(cnum,expression[i]);
|
||||
}
|
||||
else if (expression[i].value == '.' && cnum.length != 0){
|
||||
@@ -83,8 +84,6 @@ class B12Expression {
|
||||
}
|
||||
// If any other valid character just add it to the string after making sure to add the last built number if it exists
|
||||
else if (inStr(valid,char(expression[i].value))){
|
||||
// reset number digit multiplier count
|
||||
//count = 0;
|
||||
|
||||
// add number to string if present
|
||||
if(cnum.length != 0 && cfs == false){
|
||||
@@ -104,17 +103,19 @@ class B12Expression {
|
||||
}
|
||||
// In all other cases fail
|
||||
else{
|
||||
//db println("throwing exception");
|
||||
throw new IllegalArgumentException("Invalid input");
|
||||
}
|
||||
}
|
||||
|
||||
println(evalString);
|
||||
return(evalString);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// HELPER FUNCTIONS //
|
||||
private Number convert(B12Digit[] cnum, boolean isFloat){
|
||||
if(!isFloat){
|
||||
int out = 0;
|
||||
//cnum = (B12Digit[])reverse(cnum);
|
||||
for(int i = 0; i < cnum.length; i++){
|
||||
out += cnum[i].getValue() * pow(12,i);
|
||||
}
|
||||
@@ -139,7 +140,6 @@ class B12Expression {
|
||||
return new B12Float(out);
|
||||
}
|
||||
|
||||
// HELPER FUNCTIONS //
|
||||
boolean inStr(String st, char _c){
|
||||
try{
|
||||
int x = st.indexOf(_c);
|
||||
|
||||
@@ -76,7 +76,7 @@ class Button{
|
||||
fill(mouseOver ? highlight : col);
|
||||
rect(pos.x,pos.y,dim.x,dim.y,radius);
|
||||
|
||||
//stroke(textColor); fix this
|
||||
fill(textColor);
|
||||
textSize(textSize);
|
||||
if(renderPriority == 0){
|
||||
while(textWidth(text) > dim.x * 0.95){ // WARNING! NOT ROBUST make this a function at some point to allow other rectModes to render properly
|
||||
|
||||
@@ -3,13 +3,15 @@ class Calculator{
|
||||
MathPad m;
|
||||
MathDisplay d;
|
||||
|
||||
Calculator(MouseHandler _mh){
|
||||
ex = new B12Expression();
|
||||
m = new MathPad(_mh, ex);
|
||||
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,18 +1,28 @@
|
||||
class MathPad{
|
||||
B12Expression ex;
|
||||
MouseHandler mh;
|
||||
Button[] buttons;
|
||||
PVector pos;
|
||||
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[12];
|
||||
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.
|
||||
@@ -21,7 +31,7 @@ class MathPad{
|
||||
// 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[i] = new B12Button(mh ,new B12Digit(i)).setPos(bPos).setDim(new PVector(20,20)).setFunction(new MethodRelay(this, "addChar", B12Digit.class)).setColor(220,150);
|
||||
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));
|
||||
@@ -35,26 +45,20 @@ class MathPad{
|
||||
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));
|
||||
}
|
||||
|
||||
// DONE send characters to display
|
||||
|
||||
void addChar(B12Digit _digit){
|
||||
ex.addChar(_digit);
|
||||
//println("clicked " + _digit.getValue());
|
||||
}
|
||||
|
||||
void display(){
|
||||
pushMatrix();
|
||||
//translate(pos.x,pos.y);
|
||||
for(int i = 0; i < buttons.length; i++){
|
||||
buttons[i].display();
|
||||
}
|
||||
popMatrix();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
class B12Button extends Button{
|
||||
B12Digit digit;
|
||||
|
||||
@@ -68,7 +72,7 @@ class B12Button extends Button{
|
||||
B12Digit getDigit(){ return digit; }
|
||||
B12Button setDigit(B12Digit _digit){ digit = _digit; return this; }
|
||||
|
||||
// Add the B12Digit to the display method
|
||||
// Add drawing the B12Digit to the display method
|
||||
@Override
|
||||
void display(){
|
||||
super.display();
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
Beta version of a clock in base 12.
|
||||
by Nayan Sawyer
|
||||
started Mar 2022
|
||||
version 0.1.5.6 April 30 2022
|
||||
version 0.1.5.7 April 30 2022
|
||||
|
||||
Characters are a variation of Kaktovik Inupiaq numerals
|
||||
reversed and in base 12 instead of 20. I take no credit
|
||||
@@ -11,11 +11,14 @@
|
||||
Includes method relay code be 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
|
||||
// TODO finalize calculator design
|
||||
// TODO 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.1.5.7
|
||||
- Presentation display setup done.
|
||||
|
||||
changelog 0.1.5.6
|
||||
- MathPad complete. Changed internal button mouseOver code
|
||||
from MethodRelay to switch statement. Added delete
|
||||
|
||||
Reference in New Issue
Block a user