0.1.5.7 - presentation display setup done

This commit is contained in:
61616
2022-05-12 18:45:46 -04:00
parent 534abc229c
commit 83f95e0d04
7 changed files with 67 additions and 53 deletions

View File

@@ -4,23 +4,25 @@ PVector offset;
public static final int DECIMAL = 65; public static final int DECIMAL = 65;
MouseHandler mh; // Mouse event handler MouseHandler mh; // Mouse event handler
B12Expression ex;
Calculator calc; Calculator calc;
Button reset; Clock clock;
Button eval; Button mode;
Button changeTime;
STime48 time;
void setup(){ void setup(){
size(400,400); 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)); 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(){ void draw(){
@@ -28,15 +30,14 @@ 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();
reset.display(); if(clock != null) clock.display();
eval.display(); if(changeTime != null) changeTime.display();
mode.display();
} }
void mouseClicked(){ void mouseClicked(){
@@ -55,11 +56,15 @@ void call(String _call){
void changeMode(){ void changeMode(){
if(calc == null){ if(calc == null){
calc = new Calculator(mh); clock = null;
eval.setFunction(new MethodRelay(calc.ex, "evaluate")); changeTime = null;
calc = new Calculator(mh, ex);
return; return;
} }
calc = null; 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(); Runtime.getRuntime().gc();
} }

View File

@@ -6,7 +6,7 @@ class Time48 extends Thread{
private boolean initialized; private boolean initialized;
// CONSTRUCTORS // // CONSTRUCTORS //
// TODO add exceptions to all contructors // TODO add throwing exceptions to all contructors
Time48(){ Time48(){
sec48 = 0; sec48 = 0;
min48 = 0; min48 = 0;

View File

@@ -35,22 +35,25 @@ class B12Expression {
} }
void evaluate(){ void evaluate(){
//db println("evaluate"); //<>// String evalString = parseDigits();
println(evalString);
//<>// //<>//
}
private String parseDigits(){
String valid = "+*-/"; // valid characters to accept String valid = "+*-/"; // valid characters to accept
String evalString = ""; // gets filled with the expression up for evaluation in base 10 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 B12Digit[] cnum = new B12Digit[0]; // used to sum numbers as the array is parsed
boolean cfs = false; // float status of currently building number 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 // 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 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--){ for (int c = expression.length; c >= 0; c--){
//db println("top of for loop " + c);
int i = c - 1; 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 // add number to string if present
if(cnum.length != 0 && cfs == false){ if(cnum.length != 0 && cfs == false){
B12Int num = (B12Int)convert(cnum,cfs); B12Int num = (B12Int)convert(cnum,cfs);
@@ -65,15 +68,13 @@ class B12Expression {
} }
break; 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 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){ if (expression[i].isNum() && cnum.length == 0){
//count = 0;
cnum = (B12Digit[])append(cnum,expression[i]); 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 // 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){ else if (expression[i].isNum() && cnum.length != 0){
//count += 1;
cnum = (B12Digit[])append(cnum,expression[i]); cnum = (B12Digit[])append(cnum,expression[i]);
} }
else if (expression[i].value == '.' && cnum.length != 0){ 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 // 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))){ else if (inStr(valid,char(expression[i].value))){
// reset number digit multiplier count
//count = 0;
// add number to string if present // add number to string if present
if(cnum.length != 0 && cfs == false){ if(cnum.length != 0 && cfs == false){
@@ -104,17 +103,19 @@ class B12Expression {
} }
// In all other cases fail // In all other cases fail
else{ else{
//db println("throwing exception");
throw new IllegalArgumentException("Invalid input"); throw new IllegalArgumentException("Invalid input");
} }
} }
println(evalString); return(evalString);
} }
// HELPER FUNCTIONS //
private Number convert(B12Digit[] cnum, boolean isFloat){ private Number convert(B12Digit[] cnum, boolean isFloat){
if(!isFloat){ if(!isFloat){
int out = 0; int out = 0;
//cnum = (B12Digit[])reverse(cnum);
for(int i = 0; i < cnum.length; i++){ for(int i = 0; i < cnum.length; i++){
out += cnum[i].getValue() * pow(12,i); out += cnum[i].getValue() * pow(12,i);
} }
@@ -139,7 +140,6 @@ class B12Expression {
return new B12Float(out); return new B12Float(out);
} }
// HELPER FUNCTIONS //
boolean inStr(String st, char _c){ boolean inStr(String st, char _c){
try{ try{
int x = st.indexOf(_c); int x = st.indexOf(_c);

View File

@@ -76,7 +76,7 @@ class Button{
fill(mouseOver ? highlight : col); fill(mouseOver ? highlight : col);
rect(pos.x,pos.y,dim.x,dim.y,radius); rect(pos.x,pos.y,dim.x,dim.y,radius);
//stroke(textColor); fix this fill(textColor);
textSize(textSize); textSize(textSize);
if(renderPriority == 0){ 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 while(textWidth(text) > dim.x * 0.95){ // WARNING! NOT ROBUST make this a function at some point to allow other rectModes to render properly

View File

@@ -3,13 +3,15 @@ class Calculator{
MathPad m; MathPad m;
MathDisplay d; MathDisplay d;
Calculator(MouseHandler _mh){ Calculator(MouseHandler _mh, B12Expression _ex){
ex = new B12Expression(); ex = _ex;
m = new MathPad(_mh, ex); m = new MathPad(_mh, ex).setPos(new PVector(-40,0));
d = new MathDisplay(ex); d = new MathDisplay(ex);
} }
void display(){ void display(){
rect(85,-22,1,14);
d.setPos(new PVector(83,-10));
m.display(); m.display();
d.display(); d.display();
} }

View File

@@ -1,18 +1,28 @@
class MathPad{ class MathPad{
B12Expression ex; private B12Expression ex;
MouseHandler mh; private MouseHandler mh;
Button[] buttons; private Button[] buttons;
PVector pos; private PVector pos;
MathPad(MouseHandler _mh, B12Expression _ex){ MathPad(MouseHandler _mh, B12Expression _ex){
ex = _ex; ex = _ex;
mh = _mh; mh = _mh;
pos = new PVector(0,0); pos = new PVector(0,0);
buttons = new Button[12]; buttons = new Button[0];
initialize(); initialize();
} }
// GETTERS AND SETTERS //
PVector getPos(){return pos;}
MathPad setPos(PVector _pos){
pos = _pos.copy();
initialize();
return this;
}
void initialize(){ void initialize(){
buttons = new Button[0];
// Create numpad buttons // Create numpad buttons
for(int i = 0; i < 12; i++){ for(int i = 0; i < 12; i++){
/* Button position must contain it's absolute position relative to sketch 0,0 for mouseOver to work. /* 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) // x = pos.x + (width + gap) * (i%cols)
// y = pos.y + (height + gap) * b2rows - (height + gap) * row // 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)); 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 // 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,pos.y)).setFunction(new MethodRelay(this, "addChar", B12Digit.class)).setColor(220,150));
@@ -36,25 +46,19 @@ class MathPad{
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)); 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){ void addChar(B12Digit _digit){
ex.addChar(_digit); ex.addChar(_digit);
//println("clicked " + _digit.getValue());
} }
void display(){ void display(){
pushMatrix();
//translate(pos.x,pos.y);
for(int i = 0; i < buttons.length; i++){ for(int i = 0; i < buttons.length; i++){
buttons[i].display(); buttons[i].display();
} }
popMatrix();
} }
} }
class B12Button extends Button{ class B12Button extends Button{
B12Digit digit; B12Digit digit;
@@ -68,7 +72,7 @@ class B12Button extends Button{
B12Digit getDigit(){ return digit; } B12Digit getDigit(){ return digit; }
B12Button setDigit(B12Digit _digit){ digit = _digit; return this; } B12Button setDigit(B12Digit _digit){ digit = _digit; return this; }
// Add the B12Digit to the display method // Add drawing the B12Digit to the display method
@Override @Override
void display(){ void display(){
super.display(); super.display();

View File

@@ -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.1.5.6 April 30 2022 version 0.1.5.7 April 30 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,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 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. for more details.
// TODO add actual math evaluation to B12Expression // TODO add actual math evaluation to B12Expression // Once thiss is done we hit version 0.2.0.0 //
// TODO finalize calculator design // TODO add throwing exceptions to all contructors
// 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.1.5.7
- Presentation display setup done.
changelog 0.1.5.6 changelog 0.1.5.6
- MathPad complete. Changed internal button mouseOver code - MathPad complete. Changed internal button mouseOver code
from MethodRelay to switch statement. Added delete from MethodRelay to switch statement. Added delete