Skip to content

Commit

Permalink
gui & RCL STO
Browse files Browse the repository at this point in the history
  • Loading branch information
cameyo42 committed Nov 11, 2017
1 parent b5b1eba commit 40f4145
Show file tree
Hide file tree
Showing 9 changed files with 163 additions and 69 deletions.
19 changes: 14 additions & 5 deletions ForthCalc.pde
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ int numFloating;
// trig in degrees
boolean inDegrees;
// Memory 1..5
double mem1, mem2, mem3, mem4, mem5;
int Nmem = 5;
Double[] mem = new Double[Nmem];

// GUI
int baseX, baseY;
Expand Down Expand Up @@ -157,6 +158,9 @@ PImage btnASEQ_IMG, btnGSEQ_IMG;
Button btnLR;
PImage btnLR_IMG;

Button btnSLOPE;
PImage btnSLOPE_IMG;

// Forth Buttons
Button btnDUP, btnDROP, btnSWAP, btnOVER, btnROT, btnNIP, btnTUCK;
PImage btnDUP_IMG, btnDROP_IMG, btnSWAP_IMG, btnOVER_IMG, btnROT_IMG, btnNIP_IMG, btnTUCK_IMG;
Expand All @@ -169,10 +173,10 @@ Button btnCLEAR, btnSAVE, btnLOAD, btnHELP;
PImage btnCLEAR_IMG, btnSAVE_IMG, btnLOAD_IMG, btnHELP_IMG;

// Store & Recall buttons
Button btnSTO1, btnSTO2, btnSTO3, btnSTO4, btnSTO5;
PImage btnSTO1_IMG, btnSTO2_IMG, btnSTO3_IMG, btnSTO4_IMG, btnSTO5_IMG;
Button btnRCL1, btnRCL2, btnRCL3, btnRCL4, btnRCL5;
PImage btnRCL1_IMG, btnRCL2_IMG, btnRCL3_IMG, btnRCL4_IMG, btnRCL5_IMG;
Button btnSTO1, btnSTO2, btnSTO3, btnSTO4, btnSTO5, btnSTOALL;
PImage btnSTO1_IMG, btnSTO2_IMG, btnSTO3_IMG, btnSTO4_IMG, btnSTO5_IMG, btnSTOALL_IMG;
Button btnRCL1, btnRCL2, btnRCL3, btnRCL4, btnRCL5, btnRCLALL;
PImage btnRCL1_IMG, btnRCL2_IMG, btnRCL3_IMG, btnRCL4_IMG, btnRCL5_IMG, btnRCLALL_IMG;

//*********************************
void setup()
Expand All @@ -199,6 +203,7 @@ void setup()
outputFont = createFont("Courier New Bold", 14);
textFont(digitFont);
// set global variables
for(int i=0; i<5; i++) { mem[i] = null; }
viewShortcuts = false;
numFloating = -1;
digitRESET = "0." + nf(0, numFloating);
Expand Down Expand Up @@ -352,6 +357,9 @@ void mousePressed()
btnRND.onClick();

// column buttons
btnSTOALL.onClick();
btnRCLALL.onClick();

btnPERC.onClick();
btnDELTA.onClick();
btnCXADD.onClick();
Expand All @@ -365,6 +373,7 @@ void mousePressed()
btnASEQ.onClick();
btnGSEQ.onClick();
btnLR.onClick();
btnSLOPE.onClick();

// Forth
btnDUP.onClick();
Expand Down
Binary file modified data/guiIMAGES.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions drawGUI.pde
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ void showGUI()
btnTRIANGLE.show();

// column buttons
btnSTOALL.show();
btnRCLALL.show();

btnPERC.show();
btnDELTA.show();
btnCXADD.show();
Expand All @@ -219,6 +222,7 @@ void showGUI()
btnASEQ.show();
btnGSEQ.show();
btnLR.show();
btnSLOPE.show();

// Forth
btnDUP.show();
Expand Down
152 changes: 111 additions & 41 deletions functionForth.pde
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,8 @@ void fnCOPYS()
{
pila.push(clipboard[i]);
}
isResult = true;
isBlocked = false;
}

// Paste Stack
Expand All @@ -353,7 +355,8 @@ void fnPASTES()
{
lastX = digitNUM;
//pila.clearStack();
pila.push(digitNUM);
if (!isBlocked && isResult) { pila.push(digitNUM); }
//pila.push(digitNUM);
for (int i=clipboardItems-1; i >= 0; i--)
{
pila.push(clipboard[i]);
Expand Down Expand Up @@ -538,59 +541,126 @@ void fnFLIPS()
}
//------------------------------------------------------------
// Memory function
void fnSTO1() { mem1 = digitNUM; outputSTR = String.valueOf(digitNUM); isResult = true; isBlocked = false; }
void fnSTO2() { mem2 = digitNUM; outputSTR = String.valueOf(digitNUM); isResult = true; isBlocked = false; }
void fnSTO3() { mem3 = digitNUM; outputSTR = String.valueOf(digitNUM); isResult = true; isBlocked = false; }
void fnSTO4() { mem4 = digitNUM; outputSTR = String.valueOf(digitNUM); isResult = true; isBlocked = false; }
void fnSTO5() { mem5 = digitNUM; outputSTR = String.valueOf(digitNUM); isResult = true; isBlocked = false; }

void fnSTO1() { mem[0] = digitNUM; outputSTR = String.valueOf(digitNUM); isResult = true; isBlocked = false; }
void fnSTO2() { mem[1] = digitNUM; outputSTR = String.valueOf(digitNUM); isResult = true; isBlocked = false; }
void fnSTO3() { mem[2] = digitNUM; outputSTR = String.valueOf(digitNUM); isResult = true; isBlocked = false; }
void fnSTO4() { mem[3] = digitNUM; outputSTR = String.valueOf(digitNUM); isResult = true; isBlocked = false; }
void fnSTO5() { mem[4] = digitNUM; outputSTR = String.valueOf(digitNUM); isResult = true; isBlocked = false; }
void fnRCL1()
{
lastX = digitNUM;
if (!isBlocked && isResult) { pila.push(digitNUM); }
//pila.push(digitNUM);
digitNUM = mem1;
outputSTR = String.valueOf(digitNUM);
isResult = true;
isBlocked = false;
if (mem[0] != null)
{
lastX = digitNUM;
if (!isBlocked && isResult) { pila.push(digitNUM); }
//pila.push(digitNUM);
digitNUM = mem[0];
outputSTR = String.valueOf(digitNUM);
isResult = true;
isBlocked = false;
}
}
void fnRCL2()
{
lastX = digitNUM;
if (!isBlocked && isResult) { pila.push(digitNUM); }
//pila.push(digitNUM);
digitNUM = mem2;
outputSTR = String.valueOf(digitNUM);
isResult = true;
isBlocked = false;
if (mem[1] != null)
{
lastX = digitNUM;
if (!isBlocked && isResult) { pila.push(digitNUM); }
//pila.push(digitNUM);
digitNUM = mem[1];
outputSTR = String.valueOf(digitNUM);
isResult = true;
isBlocked = false;
}
}
void fnRCL3()
{
lastX = digitNUM;
if (!isBlocked && isResult) { pila.push(digitNUM); }
//pila.push(digitNUM);
digitNUM = mem3;
outputSTR = String.valueOf(digitNUM);
isResult = true;
isBlocked = false;
if (mem[2] != null)
{
lastX = digitNUM;
if (!isBlocked && isResult) { pila.push(digitNUM); }
//pila.push(digitNUM);
digitNUM = mem[2];
outputSTR = String.valueOf(digitNUM);
isResult = true;
isBlocked = false;
}
}
void fnRCL4()
{
lastX = digitNUM;
if (!isBlocked && isResult) { pila.push(digitNUM); }
//pila.push(digitNUM);
digitNUM = mem4;
outputSTR = String.valueOf(digitNUM);
isResult = true;
isBlocked = false;
if (mem[3] != null)
{
lastX = digitNUM;
if (!isBlocked && isResult) { pila.push(digitNUM); }
//pila.push(digitNUM);
digitNUM = mem[3];
outputSTR = String.valueOf(digitNUM);
isResult = true;
isBlocked = false;
}
}
void fnRCL5()
{
lastX = digitNUM;
if (!isBlocked && isResult) { pila.push(digitNUM); }
//pila.push(digitNUM);
digitNUM = mem5;
outputSTR = String.valueOf(digitNUM);
if (mem[4] != null)
{
lastX = digitNUM;
if (!isBlocked && isResult) { pila.push(digitNUM); }
//pila.push(digitNUM);
digitNUM = mem[4];
outputSTR = String.valueOf(digitNUM);
isResult = true;
isBlocked = false;
}
}

// write mem1..mem5 on stack
void fnRCLALL()
{
int valid = 0;
double[] v = new double[Nmem];
for(int i=0; i<Nmem; i++)
{
if (mem[i] != null)
{
v[i] = mem[i];
valid++;
}
}
if (valid > 0)
{
lastX = digitNUM;
if (!isBlocked && isResult) { pila.push(digitNUM); }
for (int i=valid-1; i>=1 ; i--)
{
pila.push(v[i]);
}
digitNUM = v[0];
outputSTR = String.valueOf(digitNUM);
isResult = true;
isBlocked = false;
}
}

// write stack data on mem1..mem5
void fnSTOALL()
{
int n = pila.stackSize();
if (n > Nmem-1) { n = Nmem-1; }
mem[0] = digitNUM;
for(int i = 0; i<n; i++)
{
mem[i+1] = pila.getItem(i);
}
isResult = true;
isBlocked = false;
isBlocked = false;
}

void fnPRINTMEM()
{
println();
for(int i=0; i<Nmem; i++)
{
print(mem[i]+",");
}
println();
}
5 changes: 4 additions & 1 deletion keys.pde
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ void keyPressed()
//fnTADD();
//fnASEQ();
//fnTOBIN();
fnDIST();
//fnDIST();
fnSTOALL();
}

if (key == ']') // test
Expand All @@ -27,13 +28,15 @@ void keyPressed()
//fnGSEQ();
//fnGSEQ();
//fnTODEC();
fnRCLALL();
}

if (key == ';') // test
{
//fnTRIANGLE();
//fnCXDIV();
//fnCXMUL();
//fnPRINTMEM();
}

// Sound keys (on/off)
Expand Down
8 changes: 5 additions & 3 deletions saveButtons.pde
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@ void saveButtons()
//btnCXPOW_IMG.save("btnCXPOW_IMG.png");
//btnTADD_IMG.save("btnTADD_IMG.png");
//btnTSUB_IMG.save("btnTSUB_IMG.png");
btnASEQ_IMG.save("btnASEQ_IMG.png");
btnGSEQ_IMG.save("btnGSEQ_IMG.png");

//btnASEQ_IMG.save("btnASEQ_IMG.png");
//btnGSEQ_IMG.save("btnGSEQ_IMG.png");
//btnSTOALL_IMG.save("btnSTOALL_IMG.png");
//btnRCLALL_IMG.save("btnRCLALL_IMG.png");
//btnSLOPE_IMG.save("btnSLOPE_IMG.png");
}
8 changes: 8 additions & 0 deletions setGUI.pde
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ void setGUI()
btnASEQ_IMG = guiIMG.get(296, 645, 37, 33);
btnGSEQ_IMG = guiIMG.get(333, 645, 37, 33);
btnLR_IMG = guiIMG.get(370, 645, 37, 33);
btnSLOPE_IMG = guiIMG.get(407, 645, 37, 33);

btnSTOALL_IMG = guiIMG.get(0, 678, 37, 33);
btnRCLALL_IMG = guiIMG.get(37, 678, 37, 33);


// Forth Image Buttons
Expand Down Expand Up @@ -288,6 +292,10 @@ void setGUI()
btnASEQ = new Button(baseX, baseY+stepY*5, btnASEQ_IMG, "", color(240), "fnASEQ");
btnGSEQ = new Button(baseX+stepX, baseY+stepY*5, btnGSEQ_IMG, "", color(240), "fnGSEQ");
btnLR = new Button(baseX, baseY+stepY*6, btnLR_IMG, "", color(240), "fnLR");
btnSLOPE = new Button(baseX+stepX, baseY+stepY*6, btnSLOPE_IMG, "", color(240), "fnSLOPE");

btnSTOALL = new Button(baseX, baseY+stepY*12, btnSTOALL_IMG, "", color(240), "fnSTOALL");
btnRCLALL = new Button(baseX+stepX, baseY+stepY*12, btnRCLALL_IMG, "", color(240), "fnRCLALL");

// Forth buttons
baseX = 8;
Expand Down
28 changes: 14 additions & 14 deletions stat.pde
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,11 @@ void fnLR()
listaY[i] = pila.pop();
listaX[i] = pila.pop();
}
println(items);
for (int i=0; i<items; i++)
{
println(listaX[i],listaY[i]);
}
//println(items);
//for (int i=0; i<items; i++)
//{
// println(listaX[i],listaY[i]);
//}
// calculate statistic parameters
//Arrays.sort(listaX); // sort array
//Arrays.sort(listaY); // sort array
Expand All @@ -170,7 +170,7 @@ void fnLR()
mediaX += listaX[i];
mediaY += listaY[i];
sommaXY = sommaXY + listaX[i]*listaY[i];
println(listaX[i]*listaY[i]);
//println(listaX[i]*listaY[i]);
X2 = X2 + listaX[i]*listaX[i];
Y2 = Y2 + listaY[i]*listaY[i];
}
Expand All @@ -181,25 +181,25 @@ void fnLR()
mediaY2 = Y2 / listaY.length;
mediaXY = sommaXY / listaX.length;

println("medie=",mediaX, mediaY);
println("sommaXY=",sommaXY);
println("X2=",X2);
//println("medie=",mediaX, mediaY);
//println("sommaXY=",sommaXY);
//println("X2=",X2);
if ((X2/items - mediaX*mediaX) == 0) { b = 0; }
else { b = ((sommaXY/items) - mediaX*mediaY) / (X2/items - mediaX*mediaX); }
a = mediaY - b*mediaX;
println(a,b);
//println(a,b);
// coefficiente di correlazione
println(mediaX,mediaY,mediaX2,mediaY2,mediaXY);
//println(mediaX,mediaY,mediaX2,mediaY2,mediaXY);
double R = 0.0;
double sX = 0.0, sY = 0.0, sXY = 0.0;
sX = mediaX2 - mediaX*mediaX;
sY = mediaY2 - mediaY*mediaY;
sXY = mediaXY - mediaX*mediaY;
println(sX,sY,sXY);
//println(sX,sY,sXY);
if (sX == 0 || sY == 0 || sX*sY < 0 ) { R = 0; }
else { R = sXY/Math.sqrt(sX*sY); }
println("correlazione = ", R);
println(Math.toDegrees(Math.atan(b)));
//println("correlazione = ", R);
//println(Math.toDegrees(Math.atan(b)));
// write results on stack
pila.push(R);
pila.push(b);
Expand Down
Loading

0 comments on commit 40f4145

Please sign in to comment.