mirror of
https://github.com/opus-tango/B12NumbersV3.git
synced 2026-03-20 03:55:20 +00:00
0.1.5.6 - MathPad complete
This commit is contained in:
@@ -5,9 +5,11 @@ class B12Expression {
|
|||||||
expression = new B12Digit[0];
|
expression = new B12Digit[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GETTERS //
|
||||||
B12Digit getDigit(int index){ return expression[index]; }
|
B12Digit getDigit(int index){ return expression[index]; }
|
||||||
int length(){return expression.length;}
|
int length(){return expression.length;}
|
||||||
|
|
||||||
|
// SETTERS //
|
||||||
B12Expression insertChar(int ind, B12Digit _digit){
|
B12Expression insertChar(int ind, B12Digit _digit){
|
||||||
expression = (B12Digit[])append(expression, _digit); // Add the new digit
|
expression = (B12Digit[])append(expression, _digit); // Add the new digit
|
||||||
if(ind < expression.length - 1){ // Swap new digit
|
if(ind < expression.length - 1){ // Swap new digit
|
||||||
@@ -18,14 +20,18 @@ class B12Expression {
|
|||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
B12Expression addChar(B12Digit _digit){
|
B12Expression addChar(B12Digit _digit){
|
||||||
expression = (B12Digit[])append(expression, _digit);
|
expression = (B12Digit[])append(expression, _digit);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
B12Expression delete(){
|
||||||
|
expression = (B12Digit[])shorten(expression);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
void clear(){
|
B12Expression clear(){
|
||||||
expression = new B12Digit[0];
|
expression = new B12Digit[0];
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
void evaluate(){
|
void evaluate(){
|
||||||
|
|||||||
@@ -9,6 +9,9 @@ class Button{
|
|||||||
private color col; // Stores static color
|
private color col; // Stores static color
|
||||||
private color highlight; // Stores mouseover color
|
private color highlight; // Stores mouseover color
|
||||||
private String text;
|
private String text;
|
||||||
|
private float textSize;
|
||||||
|
private color textColor;
|
||||||
|
private int renderPriority; // 0: default, render text size within button size 1: render button around text
|
||||||
|
|
||||||
private MethodRelay function; // Gets called when button is pressed
|
private MethodRelay function; // Gets called when button is pressed
|
||||||
private boolean mouseOver;
|
private boolean mouseOver;
|
||||||
@@ -25,6 +28,9 @@ class Button{
|
|||||||
colorMode(HSB);
|
colorMode(HSB);
|
||||||
highlight = color(150);
|
highlight = color(150);
|
||||||
text = "";
|
text = "";
|
||||||
|
textSize = dim.y * 0.8;
|
||||||
|
textColor = 0;
|
||||||
|
renderPriority = 0;
|
||||||
|
|
||||||
mouseOver = false;
|
mouseOver = false;
|
||||||
listener = new LiveMethodRelay(this, "clicked", 'p', Object.class);
|
listener = new LiveMethodRelay(this, "clicked", 'p', Object.class);
|
||||||
@@ -38,8 +44,10 @@ class Button{
|
|||||||
color getColor(){return col;}
|
color getColor(){return col;}
|
||||||
color getHighlight(){return highlight;}
|
color getHighlight(){return highlight;}
|
||||||
String getText(){return text;}
|
String getText(){return text;}
|
||||||
|
color getTextColor(){return textColor;}
|
||||||
MethodRelay getFunction(){return function;}
|
MethodRelay getFunction(){return function;}
|
||||||
int getMode(){return mode; }
|
int getMode(){return mode; }
|
||||||
|
int getRenderPriority(){return renderPriority;}
|
||||||
|
|
||||||
// SETTERS //
|
// SETTERS //
|
||||||
Button setPos(PVector _pos){pos = _pos.copy(); return this;}
|
Button setPos(PVector _pos){pos = _pos.copy(); return this;}
|
||||||
@@ -52,6 +60,9 @@ class Button{
|
|||||||
Button autoHighlight(){ colorMode(RGB,255); highlight = color(int(red(col) * .85), int(green(col) * .85), int(blue(col) * .85)); return this; }
|
Button autoHighlight(){ colorMode(RGB,255); highlight = color(int(red(col) * .85), int(green(col) * .85), int(blue(col) * .85)); return this; }
|
||||||
Button setHighlight(color h){ highlight = h; return this; }
|
Button setHighlight(color h){ highlight = h; return this; }
|
||||||
Button setText(String t){text = t; return this;}
|
Button setText(String t){text = t; return this;}
|
||||||
|
Button setTextSize(float s){textSize = s; return this;} // TODO make robust
|
||||||
|
Button setTextColor(color c){textColor = c; return this;}
|
||||||
|
Button setRenderPriority(int p){if(p < 0 || p > 1) throw new IllegalArgumentException(); renderPriority = p; return this;}
|
||||||
|
|
||||||
Button setFunction(MethodRelay _function){function = _function; return this;}
|
Button setFunction(MethodRelay _function){function = _function; return this;}
|
||||||
Button setData(Object... _data){ data = _data; return this;} // Data to pass for button presses. Ugh, note that the array already exists because it's passed as such, no need to create a new one. Stupid bug
|
Button setData(Object... _data){ data = _data; return this;} // Data to pass for button presses. Ugh, note that the array already exists because it's passed as such, no need to create a new one. Stupid bug
|
||||||
@@ -59,13 +70,21 @@ class Button{
|
|||||||
|
|
||||||
// DISPLAY //
|
// DISPLAY //
|
||||||
void display(){
|
void display(){
|
||||||
|
mouseOver(mh.sMouseX(),mh.sMouseY());
|
||||||
noStroke();
|
noStroke();
|
||||||
rectMode(mode);
|
rectMode(mode);
|
||||||
new MethodRelay(this, "mouseOver" + str(mode), float.class, float.class).execute(mh.sMouseX(),mh.sMouseY());
|
|
||||||
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);
|
||||||
fill(0);
|
|
||||||
textSize(dim.y * 0.8);
|
//stroke(textColor); fix this
|
||||||
|
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
|
||||||
|
textSize = textSize - 1;
|
||||||
|
textSize(textSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//textSize(dim.y * 0.8);
|
||||||
textAlign(CENTER,BOTTOM);
|
textAlign(CENTER,BOTTOM);
|
||||||
text(text,pos.x + dim.x/2,pos.y + dim.y);
|
text(text,pos.x + dim.x/2,pos.y + dim.y);
|
||||||
}
|
}
|
||||||
@@ -81,33 +100,27 @@ class Button{
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DETECT IF MOUSE IS OVER BUTTON //
|
// DETECT IF MOUSE IS OVER BUTTON //
|
||||||
// The numbers in the method name correspond to the mode ids because the method gets called with a relay
|
// Must account for rect render mode
|
||||||
void mouseOver0(float x, float y){ // CORNER
|
void mouseOver(float x, float y){ // CORNER
|
||||||
mouseOver = !(x < pos.x || x > pos.x + dim.x || y < pos.y || y > dim.y + pos.y) ;
|
switch(mode){
|
||||||
}
|
case 0:
|
||||||
|
mouseOver = !(x < pos.x || x > pos.x + dim.x || y < pos.y || y > dim.y + pos.y); break;
|
||||||
void mouseOver1(float x, float y){ // CORNERS
|
case 1:
|
||||||
//println("CORNERS");
|
|
||||||
mouseOver = !(x < (pos.x > dim.x ? dim.x : pos.x) ||
|
mouseOver = !(x < (pos.x > dim.x ? dim.x : pos.x) ||
|
||||||
x > (pos.x > dim.x ? pos.x : dim.x) ||
|
x > (pos.x > dim.x ? pos.x : dim.x) ||
|
||||||
y < (pos.y > dim.y ? dim.y : pos.y) ||
|
y < (pos.y > dim.y ? dim.y : pos.y) ||
|
||||||
y > (pos.y > dim.y ? pos.y : dim.y));
|
y > (pos.y > dim.y ? pos.y : dim.y)); break;
|
||||||
}
|
case 2:
|
||||||
|
|
||||||
void mouseOver2(float x, float y){ // RADIUS
|
|
||||||
//println("RADIUS");
|
|
||||||
mouseOver = !(x < pos.x - dim.x ||
|
mouseOver = !(x < pos.x - dim.x ||
|
||||||
x > pos.x + dim.x ||
|
x > pos.x + dim.x ||
|
||||||
y < pos.x - dim.y ||
|
y < pos.x - dim.y ||
|
||||||
y > pos.x + dim.y);
|
y > pos.x + dim.y); break;
|
||||||
}
|
case 3:
|
||||||
|
|
||||||
void mouseOver3(float x, float y){ // CENTER
|
|
||||||
//println("CENTER");
|
|
||||||
mouseOver = !(x < pos.x - dim.x/2 ||
|
mouseOver = !(x < pos.x - dim.x/2 ||
|
||||||
x > pos.x + dim.x/2 ||
|
x > pos.x + dim.x/2 ||
|
||||||
y < pos.x - dim.y/2 ||
|
y < pos.x - dim.y/2 ||
|
||||||
y > pos.y + dim.y/2);
|
y > pos.y + dim.y/2); break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// GARBAGE COLLECTION //
|
// GARBAGE COLLECTION //
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ class MathPad{
|
|||||||
ex = _ex;
|
ex = _ex;
|
||||||
mh = _mh;
|
mh = _mh;
|
||||||
pos = new PVector(0,0);
|
pos = new PVector(0,0);
|
||||||
buttons = new B12Button[12];
|
buttons = new Button[12];
|
||||||
initialize();
|
initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,6 +31,9 @@ class MathPad{
|
|||||||
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)).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)).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 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));
|
||||||
}
|
}
|
||||||
|
|
||||||
// DONE send characters to display
|
// DONE send characters to 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.1.5.5 April 30 2022
|
version 0.1.5.6 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,16 +11,17 @@
|
|||||||
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 addition method to number interface as well as B12Int and B12Float
|
// TODO add actual math evaluation to B12Expression
|
||||||
// TODO change zero character
|
// TODO finalize calculator design
|
||||||
// TODO redo position data handling
|
|
||||||
// TODO add cursor and dynamic position for MathDisplay (Maybe add a "highlighted" attribute to B12Digit?) might need some restructuring
|
|
||||||
// TODO add parsing expression to operable math string (tricky to get base 12 to base 10)
|
|
||||||
// TODO add operator and action buttons to MathPad
|
|
||||||
// TODO add parenthesis functionality
|
|
||||||
// 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.6
|
||||||
|
- MathPad complete. Changed internal button mouseOver code
|
||||||
|
from MethodRelay to switch statement. Added delete
|
||||||
|
functionality to B12Expression. Improved but did not
|
||||||
|
finish button text features.
|
||||||
|
|
||||||
changelog 0.1.5.5
|
changelog 0.1.5.5
|
||||||
- finished parsing input array to string in B12Expression.
|
- finished parsing input array to string in B12Expression.
|
||||||
Added parenthesis chars to B12Digit and changed 0 char.
|
Added parenthesis chars to B12Digit and changed 0 char.
|
||||||
|
|||||||
Reference in New Issue
Block a user