mirror of
https://github.com/opus-tango/B12NumbersV3.git
synced 2026-03-20 03:55:20 +00:00
Comments and skeleton code
Some additional documentation comments. Ignore the beginning of a dynamic mouse event handler, that is coming later
This commit is contained in:
@@ -1,55 +0,0 @@
|
||||
/*class B12Char extends B12Digit{
|
||||
String valid;
|
||||
char c;
|
||||
|
||||
B12Char(char _c){
|
||||
super(0);
|
||||
valid = "+-*\/.:"; // Defines valid input characters
|
||||
if(inStr(_c)){
|
||||
c = _c;
|
||||
}else{
|
||||
throw new IllegalArgumentException("B12Char only accepts \'+ - * / . :'");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
void display(){
|
||||
pushMatrix();
|
||||
translate(refPos.x,refPos.y);
|
||||
strokeWeight(1);
|
||||
|
||||
switch(c) {
|
||||
case '+':
|
||||
lineMinus(); linePlus(); break;
|
||||
case '-':
|
||||
lineMinus(); break;
|
||||
case '*':
|
||||
lineTimes(); break;
|
||||
case '/':
|
||||
lineMinus(); dotsDiv(); break;
|
||||
case '.':
|
||||
strokeWeight(2); period(); break;
|
||||
case ':':
|
||||
strokeWeight(2); colon(); break;
|
||||
}
|
||||
|
||||
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 linePlus(){ line(6,-8,6,-2); }
|
||||
void period(){ point(5,0); }
|
||||
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;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
@@ -1,4 +1,3 @@
|
||||
//package java.base.lang;
|
||||
class B12Digit{
|
||||
byte value;
|
||||
PVector refPos;
|
||||
|
||||
@@ -44,4 +44,8 @@ void draw(){
|
||||
|
||||
void mouseClicked(){
|
||||
clock.setTime(new Time48(16,0,0));
|
||||
|
||||
// Decide which element is on top at mouse position (maybe by state?)
|
||||
method("");
|
||||
|
||||
}
|
||||
|
||||
@@ -5,40 +5,28 @@ class Clock {
|
||||
B12Int minutes;
|
||||
B12Int seconds;
|
||||
B12Digit sep; // TODO Just deprecated B12Char. Refactor to single array of B12Digits?
|
||||
B12Int fill;
|
||||
int tmillis;
|
||||
//boolean initialized;
|
||||
|
||||
Clock(STime48 _t48) { // TODO refactor time class
|
||||
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(':');
|
||||
fill = new B12Int(0);
|
||||
sep = new B12Digit(':'); // Seperation character between time columns
|
||||
|
||||
hours.setMinLen(2);
|
||||
minutes.setMinLen(2);
|
||||
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);
|
||||
}
|
||||
|
||||
PVector getPos() {
|
||||
return pos;
|
||||
}
|
||||
void setPos(PVector _pos) {
|
||||
pos = _pos.copy();
|
||||
}
|
||||
void setPos(float _x, float _y) {
|
||||
pos = new PVector(_x, _y);
|
||||
}
|
||||
// GETTERS and SETTERS //
|
||||
PVector getPos() { return pos; }
|
||||
void setPos(PVector _pos) { pos = _pos.copy(); }
|
||||
void setPos(float _x, float _y) { pos = new PVector(_x, _y);}
|
||||
|
||||
void setTime(Time48 _time) {
|
||||
t48.setTime(_time);
|
||||
//initialized = true;
|
||||
}
|
||||
|
||||
//public void syncTime(){ initialized = false; } // Allows syncing after time starts running
|
||||
void setTime(Time48 _time) { t48.setTime(_time); }
|
||||
void resetTime() { t48.setTime(new Time48(0)); }
|
||||
|
||||
void display() {
|
||||
if (t48.synced()) {
|
||||
@@ -65,7 +53,6 @@ class Clock {
|
||||
c1.display();
|
||||
seconds.display();
|
||||
popMatrix();
|
||||
//print(seconds.getValue());
|
||||
} else {
|
||||
text("fetching current time", pos.x, pos.y);
|
||||
}
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
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
|
||||
|
||||
16
B12NumbersV3/MouseListener.pde
Normal file
16
B12NumbersV3/MouseListener.pde
Normal file
@@ -0,0 +1,16 @@
|
||||
class MouseHandler{
|
||||
StringList clickListeners;
|
||||
|
||||
MouseHandler(){
|
||||
clickListeners = new StringList();
|
||||
}
|
||||
|
||||
void listen(){
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
class Listen{
|
||||
|
||||
}
|
||||
@@ -1,22 +1,27 @@
|
||||
class STime48 extends Time48{
|
||||
int offset;
|
||||
int tmillis;
|
||||
private int offset; // Time offset in milliseconds
|
||||
private int tmillis; // Actual time at which time was synced to real world in milliseconds
|
||||
private int syncedat; // Offset between the start of the program (when millis() starts counting from) and when the time was last synced
|
||||
private boolean synced;
|
||||
|
||||
STime48(){
|
||||
super();
|
||||
offset = 0;
|
||||
tmillis = 0;
|
||||
syncedat = 0;
|
||||
synced = false;
|
||||
this.start();
|
||||
}
|
||||
|
||||
boolean synced(){return synced;}
|
||||
// Public sync functions
|
||||
public boolean synced(){return synced;}
|
||||
public void syncTime(){ synced = false; } // Allows syncing after time starts running
|
||||
void setTime(Time48 _time){
|
||||
offset = _time.b10millis() - millis() - tmillis;
|
||||
public void setTime(Time48 _time){
|
||||
// To get offset we subtract where the current clock is from where we want it to be
|
||||
offset = _time.b10millis() - millis() - tmillis + syncedat;
|
||||
}
|
||||
|
||||
// Threaded code
|
||||
@Override
|
||||
public void run(){
|
||||
while(true){
|
||||
@@ -24,16 +29,18 @@ class STime48 extends Time48{
|
||||
|
||||
delay(1); // MUST USE DELAY OR OFFSET DOES NOT GET CALCULATED
|
||||
if(tmillis + millis() + offset > 86400000){ tmillis -= 86400000; } // Fall over at 00:00
|
||||
setTsec(int((tmillis + millis() + offset) / 1562.5));
|
||||
setTsec(int((tmillis + millis() - syncedat + offset) / 1562.5)); // Add time at sync, millis since program start, and offset, and subtract the millis between program start and sync (because we're adding millis())
|
||||
}
|
||||
}
|
||||
|
||||
// Initial sync code
|
||||
private void sync(){
|
||||
int sec = second();
|
||||
tmillis = 0;
|
||||
while(true){
|
||||
if(sec != second()){
|
||||
tmillis = second()*1000 + minute()*60*1000 + hour()*60*60*1000;
|
||||
if(sec != second()){ // Wait until seconds changes so as to be as accurate as possible
|
||||
tmillis = second()*1000 + minute()*60*1000 + hour()*60*60*1000; // Current time in total millis
|
||||
syncedat = millis();
|
||||
synced = true;
|
||||
println("synced");
|
||||
break;
|
||||
|
||||
@@ -2,10 +2,11 @@ class Time48 extends Thread{
|
||||
private int sec48;
|
||||
private int min48;
|
||||
private int hour48;
|
||||
private int tsec48;
|
||||
private int tsec48; // Total seconds
|
||||
private boolean initialized;
|
||||
|
||||
// CONSTRUCTORS //
|
||||
// TODO add exceptions to all contructors
|
||||
Time48(){
|
||||
sec48 = 0;
|
||||
min48 = 0;
|
||||
@@ -13,6 +14,7 @@ class Time48 extends Thread{
|
||||
tsec48 = 0;
|
||||
initialized = false;
|
||||
}
|
||||
|
||||
Time48(int _tsec48){
|
||||
tsec48 = _tsec48;
|
||||
flattenTSec();
|
||||
@@ -24,6 +26,7 @@ class Time48 extends Thread{
|
||||
flattenTSec();
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
Time48(int h, int m, int s){
|
||||
if(h >= 0 && h < 24){ hour48 = h;}else{throw new IllegalArgumentException();}
|
||||
if(m >= 0 && m < 48){ min48 = m;}else{throw new IllegalArgumentException();}
|
||||
@@ -40,11 +43,7 @@ class Time48 extends Thread{
|
||||
int[] t48(){int[] out = {hour48,min48,sec48}; return out;}
|
||||
boolean initialized(){return initialized;}
|
||||
int b10millis(){return int(float(tsec48) * 1562.5);}
|
||||
|
||||
Time48 offset(Time48 t){
|
||||
return new Time48(t.tsec() + tsec48);
|
||||
}
|
||||
|
||||
|
||||
Time48 copy(){ return new Time48(this); }
|
||||
|
||||
// SETTERS //
|
||||
@@ -66,7 +65,7 @@ class Time48 extends Thread{
|
||||
flattenOther();
|
||||
initialized = true;
|
||||
}
|
||||
void setTsec(int s){
|
||||
void setTsec(int s){ // TODO add exception
|
||||
tsec48 = s;
|
||||
flattenTSec();
|
||||
initialized = true;
|
||||
@@ -80,7 +79,6 @@ class Time48 extends Thread{
|
||||
|
||||
sec48 -= min48 * 48;
|
||||
min48 -= hour48 * 48;
|
||||
//println(t48());
|
||||
}
|
||||
private void flattenOther(){
|
||||
tsec48 = hour48*48*48 + min48*48 + sec48;
|
||||
|
||||
Reference in New Issue
Block a user