mirror of
https://github.com/opus-tango/B12NumbersV3.git
synced 2026-03-20 03:55:20 +00:00
Pre-B12Digit refactor save
In the process of adding keypad, math, etc., and about to break B12Digit class
This commit is contained in:
@@ -1,12 +1,14 @@
|
|||||||
class B12Char extends B12Digit{
|
class B12Char extends B12Digit{
|
||||||
|
String valid;
|
||||||
char c;
|
char c;
|
||||||
|
|
||||||
B12Char(char _c){
|
B12Char(char _c){
|
||||||
super(0);
|
super(0);
|
||||||
if(_c == '-' || _c == '.' || _c == ':'){
|
valid = "+-*/.:"; // Defines valid input characters
|
||||||
|
if(inStr(_c)){
|
||||||
c = _c;
|
c = _c;
|
||||||
}else{
|
}else{
|
||||||
throw new IllegalArgumentException("B12Char only accepts \'-\', \'.\', and ':'");
|
throw new IllegalArgumentException("B12Char only accepts \'+ - * / . :'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -17,8 +19,14 @@ class B12Char extends B12Digit{
|
|||||||
strokeWeight(1);
|
strokeWeight(1);
|
||||||
|
|
||||||
switch(c) {
|
switch(c) {
|
||||||
|
case '+':
|
||||||
|
lineMinus(); linePlus(); break;
|
||||||
case '-':
|
case '-':
|
||||||
lineMinus(); break;
|
lineMinus(); break;
|
||||||
|
case '*':
|
||||||
|
lineTimes(); break;
|
||||||
|
case '/':
|
||||||
|
lineMinus(); dotsDiv(); break;
|
||||||
case '.':
|
case '.':
|
||||||
strokeWeight(2); period(); break;
|
strokeWeight(2); period(); break;
|
||||||
case ':':
|
case ':':
|
||||||
@@ -28,7 +36,20 @@ class B12Char extends B12Digit{
|
|||||||
popMatrix();
|
popMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void lineTimes(){ line(4,-7,8,-3); line(4,-3,8,-7); }
|
||||||
|
void dotsDiv(){ point(6,-8); point(6,-2); }
|
||||||
void lineMinus(){ line(3,-5,9,-5); }
|
void lineMinus(){ line(3,-5,9,-5); }
|
||||||
|
void linePlus(){ line(6,-8,6,-2); }
|
||||||
void period(){ point(5,0); }
|
void period(){ point(5,0); }
|
||||||
void colon(){ point(5,-2); point(5,-8); }
|
void colon(){ point(5,-2); point(5,-8); }
|
||||||
|
|
||||||
|
boolean inStr(char _c){
|
||||||
|
try{
|
||||||
|
int x = valid.indexOf(_c);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (Exception e){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
15
B12NumbersV3/B12Math.pde
Normal file
15
B12NumbersV3/B12Math.pde
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
class B12Math {
|
||||||
|
ArrayList <B12Digit> expression;
|
||||||
|
|
||||||
|
B12Math(){
|
||||||
|
expression = new ArrayList<B12Digit>();;
|
||||||
|
}
|
||||||
|
|
||||||
|
void delete(int pos){
|
||||||
|
expression.remove(pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
void evaluate(){
|
||||||
|
//TODO set expression to evaluation of expression
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -13,19 +13,25 @@
|
|||||||
public static int DECIMAL = 65;
|
public static int DECIMAL = 65;
|
||||||
|
|
||||||
Clock clock;
|
Clock clock;
|
||||||
|
B12Char p;
|
||||||
|
B12Char t;
|
||||||
|
|
||||||
void setup(){
|
void setup(){
|
||||||
size(400,400);
|
size(400,400);
|
||||||
clock = new Clock(new STime48());
|
clock = new Clock(new STime48());
|
||||||
println("waiting");
|
println("waiting");
|
||||||
|
p = new B12Char('+');
|
||||||
|
t = new B12Char('/');
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw(){
|
void draw(){
|
||||||
background(196);
|
background(196);
|
||||||
translate(width/2,height/2);
|
translate(width/2,height/2);
|
||||||
scale(1);
|
scale(2);
|
||||||
point(0,0);
|
point(0,0);
|
||||||
clock.display();
|
clock.display();
|
||||||
|
//p.display();
|
||||||
|
t.display();
|
||||||
}
|
}
|
||||||
|
|
||||||
void mouseClicked(){
|
void mouseClicked(){
|
||||||
|
|||||||
16
B12NumbersV3/MathDisplay.pde
Normal file
16
B12NumbersV3/MathDisplay.pde
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
class MathDisplay{
|
||||||
|
B12Math math;
|
||||||
|
|
||||||
|
|
||||||
|
MathDisplay(B12Math _math){
|
||||||
|
math = _math;
|
||||||
|
digits = new ArrayList<B12Digit>();
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO take expression from math and display it in whatever state it is in
|
||||||
|
void display(){
|
||||||
|
for(int i = 0; i < math.expression.size(); i++){
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
16
B12NumbersV3/MathPad.pde
Normal file
16
B12NumbersV3/MathPad.pde
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
class MathPad{
|
||||||
|
B12Math math;
|
||||||
|
|
||||||
|
MathPad(B12Math _math){
|
||||||
|
math = _math;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO draw a grid for buttons
|
||||||
|
// TODO draw characters in grid
|
||||||
|
// TODO detect mousepresses on the buttons (maybe a global mouse handler?)
|
||||||
|
// TODO send characters to math
|
||||||
|
|
||||||
|
void addchar(){
|
||||||
|
math.expression.add(new B12Char('/'));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,96 +0,0 @@
|
|||||||
/*class Time extends Thread{
|
|
||||||
PVector pos;
|
|
||||||
B12Int hours;
|
|
||||||
B12Int minutes;
|
|
||||||
B12Int seconds;
|
|
||||||
B12Char sep;
|
|
||||||
B12Int fill;
|
|
||||||
int tmillis;
|
|
||||||
boolean initialized;
|
|
||||||
|
|
||||||
Time(Time48 t48){ // TODO refactor time class
|
|
||||||
pos = new PVector(0,0);
|
|
||||||
hours = new B12Int(0);
|
|
||||||
minutes = new B12Int(0);
|
|
||||||
seconds = new B12Int(0);
|
|
||||||
sep = new B12Char(':');
|
|
||||||
fill = new B12Int(0);
|
|
||||||
|
|
||||||
hours.setMinLen(2);
|
|
||||||
minutes.setMinLen(2);
|
|
||||||
seconds.setMinLen(2);
|
|
||||||
|
|
||||||
initialized = false;
|
|
||||||
this.start();
|
|
||||||
//thread("this.runTime");
|
|
||||||
}
|
|
||||||
|
|
||||||
PVector getPos(){ return pos; }
|
|
||||||
void setPos(PVector _pos){ pos = _pos.copy(); }
|
|
||||||
void setPos(float _x, float _y){ pos = new PVector(_x,_y); }
|
|
||||||
|
|
||||||
void setTime(int _h, int _m, int _s, boolean twelve){
|
|
||||||
if(twelve){
|
|
||||||
tmillis = int(((_h*48*48 + _m*48 + _s)*1562.5) - millis());
|
|
||||||
}else{
|
|
||||||
tmillis = (_h*60*60*1000 + _m*60*1000 + _s*1000) - millis();
|
|
||||||
}
|
|
||||||
initialized = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void run(){
|
|
||||||
while(true){
|
|
||||||
if(!initialized){ sync(); }
|
|
||||||
if(tmillis + millis() > 86400000){ tmillis -= 86400000; } // Fall over at 00:00
|
|
||||||
int sec48 = int((tmillis + millis()) / 1562.5);
|
|
||||||
int min48 = sec48 / 48;
|
|
||||||
int hour48 = min48 / 48;
|
|
||||||
sec48 -= min48 * 48;
|
|
||||||
min48 -= hour48 * 48;
|
|
||||||
//println(hour48 + ":" + min48 + ":" + sec48);
|
|
||||||
hours.setValue(hour48);
|
|
||||||
minutes.setValue(min48);
|
|
||||||
seconds.setValue(sec48);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void syncTime(){ initialized = false; } // Allows syncing after time starts running
|
|
||||||
private void sync(){
|
|
||||||
int sec = second();
|
|
||||||
tmillis = 0;
|
|
||||||
while(true){
|
|
||||||
if(sec != second()){
|
|
||||||
tmillis = second()*1000 + minute()*60*1000 + hour()*60*60*1000;
|
|
||||||
initialized = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void display(){
|
|
||||||
if(initialized){
|
|
||||||
// Position
|
|
||||||
|
|
||||||
hours.setPos(-64, 0);
|
|
||||||
minutes.setPos(-32, 0);
|
|
||||||
seconds.setPos(0,0);
|
|
||||||
B12Char c1 = new B12Char(':');
|
|
||||||
B12Char c2 = new B12Char(':');
|
|
||||||
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();
|
|
||||||
//print(seconds.getValue());
|
|
||||||
}else{
|
|
||||||
text("initializing " + second(),pos.x,pos.y);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
Reference in New Issue
Block a user