This commit is contained in:
Gatecraft 2016-07-14 23:07:48 +02:00
parent 4c23e1c3ed
commit 1e91428ce6
11 changed files with 38 additions and 235 deletions

View File

@ -2,8 +2,13 @@
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry combineaccessrules="false" kind="src" path="/New2DGame"/>
<classpathentry combineaccessrules="false" kind="src" path="/DrakeEngine2"/>
<classpathentry kind="lib" path="D:/Programmazione/Java/Progetti Eclipse/GatePack/libs/objenesis-2.4.jar"/>
<classpathentry kind="src" path="res"/>
<classpathentry kind="lib" path="D:/Users/Andrea/Downloads/PNGDecoder.jar"/>
<classpathentry kind="lib" path="D:/Programmazione/Java/Progetti Eclipse/lwjgl-3.0.0b-raspberry/jar/lwjgl.jar">
<attributes>
<attribute name="org.eclipse.jdt.launching.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY" value="D:/Programmazione/Java/Progetti Eclipse/lwjgl-3.0.0b-raspberry/native"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@ -3,8 +3,10 @@ encoding//src/org/nevec/rjm/BigSurd.java=UTF-8
encoding//src/org/nevec/rjm/BigSurdVec.java=UTF-8
encoding//src/org/nevec/rjm/NumeroAvanzato.java=UTF-8
encoding//src/org/nevec/rjm/NumeroAvanzatoVec.java=UTF-8
encoding//src/org/warp/engine/lwjgl/Display.java=UTF-8
encoding//src/org/warpgate/pi/calculator/Main.java=UTF-8
encoding//src/org/warpgate/pi/calculator/Parentesi.java=UTF-8
encoding//src/org/warpgate/pi/calculator/Radice.java=UTF-8
encoding//src/org/warpgate/pi/calculator/RadiceQuadrata.java=UTF-8
encoding//src/org/warpgate/pi/calculator/Simboli.java=UTF-8
encoding//src/org/warpgate/pi/calculator/screens/EquationScreen.java=UTF-8

View File

@ -220,7 +220,7 @@ public class BigDecimalMath
break ;
s = s.add(x.divide(s,locmc)).divide(half,locmc) ;
/* debugging*/
System.out.println("itr "+x.round(locmc).toString() + " " + s.round(locmc).toString()) ;
//System.out.println("itr "+x.round(locmc).toString() + " " + s.round(locmc).toString()) ;
}
return s ;
} /* BigDecimalMath.sqrt */

View File

@ -1,20 +1,22 @@
package org.warpgate.pi.calculator;
import org.nevec.rjm.NumeroAvanzatoVec;
import org.warp.engine.lwjgl.Screen;
public class Calculator {
public Calculator(boolean b) {
Utils.debugOn = b;
}
public Termine calcolarisultato(String string) throws Errore {
public static String angleMode = "deg";
public static Screen[] sessions = new Screen[5];
public static int currentSession = 0;
public static boolean haxMode = true;
public static Termine calcolarisultato(String string) throws Errore {
System.out.println("INPUT: " + string);
Parentesi espressione = new Parentesi(string);
return espressione.calcola();
}
public RisultatoEquazione calcolaequazione(String string) throws Errore {
public static RisultatoEquazione calcolaequazione(String string) throws Errore {
if (string.split("=").length == 0) {
return new RisultatoEquazione(new Termine("0"), true);
}

View File

@ -5,7 +5,6 @@ import java.awt.Graphics;
import org.nevec.rjm.NumeroAvanzatoVec;
import org.nevec.rjm.Rational;
import org.warp.engine.Display;
public class Divisione extends FunzioneDueValori {
@ -37,17 +36,17 @@ public class Divisione extends FunzioneDueValori {
return false;
}
public void draw(int x, int y, Display g, boolean small, boolean drawMinus) {
public void draw(int x, int y, boolean small, boolean drawMinus) {
boolean beforedrawminus = this.drawMinus;
this.drawMinus = drawMinus;
draw(x, y, g, small);
draw(x, y, small);
this.drawMinus = beforedrawminus;
}
private boolean drawMinus = true;
@Override
public void draw(int x, int y, Display g, boolean small) {
public void draw(int x, int y, boolean small) {
Object var1 = variable1;
Object var2 = variable2;
small = true;

View File

@ -1,13 +1,11 @@
package org.warpgate.pi.calculator;
import org.warp.engine.Display;
import com.rits.cloning.Cloner;
public interface Funzione {
public String simbolo();
public Termine calcola() throws Errore;
public void draw(int x, int y, Display g, boolean small);
public void draw(int x, int y, boolean small);
public int getWidth();
public int getHeight(boolean small);
public int getLine(boolean small);

View File

@ -1,7 +1,6 @@
package org.warpgate.pi.calculator;
import org.nevec.rjm.NumeroAvanzatoVec;
import org.warp.engine.Display;
import com.rits.cloning.Cloner;

View File

@ -1,216 +1,34 @@
package org.warpgate.pi.calculator;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.image.BufferStrategy;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import javax.imageio.ImageIO;
import org.warp.engine.lwjgl.Display;
import org.warpgate.pi.calculator.screens.EmptyScreen;
import org.warpgate.pi.calculator.screens.EquationScreen;
import org.gatecraft.game2d.utils.BitmapImage;
import org.nevec.rjm.NumeroAvanzato;
import org.nevec.rjm.NumeroAvanzatoVec;
import org.nevec.rjm.Rational;
import org.warp.engine.ActionInterface;
import org.warp.engine.Display;
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.util.Duration;
public class Main implements ActionInterface {
public static final int[] screenSize = new int[]{300, 150};
public class Main {
public static final int[] screenSize = new int[]{480, 320};
public static final int screenScale = 1;
public volatile static Display d;
public static Display d;
public static Main instance;
@SuppressWarnings({ "unchecked", "rawtypes" })
public Main() {
Display.start(this, screenSize[0], screenSize[1]);
d = Display.INSTANCE;
d.g().setFill(new javafx.scene.paint.Color(0.796875, 0.90234375, 0.828125, 1));
d.g().fillRect(0, 0, screenSize[0], screenSize[0]);
Utils.writeLetter(d, "Loading...".toUpperCase(), (screenSize[0]-Utils.getPlainTextWidth("Loading...".toUpperCase()))/2, (screenSize[1]-Utils.getFontHeight(false))/2, false);
try {
//Parentesi f = new Parentesi("(Ⓐ(2X)*3Y)/(5Z^2)+(Ⓐ(11A)*13B)/(7CZ)=19XZ");
//PARENTESI CON CALCOLI
//Funzione f = new Sottrazione(new Somma(new Parentesi("Ⓐ9/2+Ⓐ7/2", "").calcola(), new Termine("3.5")), new Parentesi("3*2√14","").calcola());
//PARENTESI CON DUE NUMERI FRAZIONALI COMPLETI CON INCOGNITE:
//Funzione f = new Parentesi("(Ⓐ(2X)*3Y)/(5Z^2)+(Ⓐ(11A)*13B)/(7CZ)", "");
//PARENTESI CON DUE NUMERI FRAZIONALI DISALLINEATI GRAFICAMENTE:
//Funzione f = new Parentesi("((5^2-1)/2)/5-5/(5/2)=2", "");
//TERMINE DI PROVA COMPLETO:
//Funzione f = new Termine(new NumeroAvanzato(new Rational(3, 2), new Rational(7, 1), new Incognite(new Incognita('X', Rational.ONE)), new Incognite(new Incognita('Y', Rational.ONE)), new Incognite(new Incognita('z', Rational.ONE))));
//PARENTESI REALISTICA CON INCOGNITE:
//Funzione f = new Equazione(new Parentesi("X^2+(MX-M+4)^2-4X-4(MX-M+4)^2+7", ""), new Termine("0"));
//POTENZA:
//Funzione f = new Parentesi("(MX-M+4)^2", "");
//NUMERO SEMPLICE LUNGO:
//Funzione f = new Parentesi("-1219999799999996934.42229", "");
//:
//Funzione f = new Parentesi("5Y+XY=2", "")
equazione = "";
c = new Calculator(true);
f = new Parentesi(equazione);
f2 = f.calcolaSistema();
ew1 = f.getWidth();
ew2 = f2.getWidth();
eh2 = f2.getHeight(false);
x1 = 2;
x2 = 2;
requiresleep1 = false;
requiresleep2 = false;
aftersleep = false;
autoscroll = false;
final Timeline timeline = new Timeline();
timeline.setCycleCount(Timeline.INDEFINITE);
timeline.setAutoReverse(true);
timeline.getKeyFrames().add(new KeyFrame(Duration.millis(1000/25), new EventHandler() {
@Override
public void handle(Event arg0) {
refresh();
}
}));
timeline.play();
/*
long start = System.nanoTime();
Termine result = c.calcolarisultato("((5^2+3√(100/0.1))*Ⓐ7+9/15*2√(26/2))/21");
long end = System.nanoTime();
long timeElapsed = end-start;
System.out.println("RESULT: " + result);
System.out.println("DECIMAl RESULT: " + result.getTerm().toBigDecimal());
System.out.println("Time elapsed: " + (double) timeElapsed / 1000000000 + "\n");
start = System.nanoTime();
RisultatoEquazione eresult = c.calcolaequazione("((5^2+3√(100/0.1))*Ⓐ7+9/15*2√(26/2))/21=(175*(2√7)+3*(2√13))/105");
end = System.nanoTime();
timeElapsed = end-start;
System.out.println("Is an equation: " + eresult.isAnEquation);
System.out.println("L-R: " + eresult.LR);
System.out.println("Time elapsed: " + (((double) timeElapsed / 1000000000)) + "\n");
*/
} catch (Errore e) {
d.setColor(new Color(204, 231, 212));
d.fillRect(0, 0, screenSize[0], screenSize[1]);
Utils.writeLetter(d, e.id.toString(), 2, 2, false);
System.err.println(e.id);
}
}
public static volatile String equazione = "";
public static Calculator c;
public static Parentesi f;
public static Funzione f2;
public static int ew1;
public static int ew2;
public static int eh2;
public static int x1;
public static int x2;
public static boolean requiresleep1;
public static boolean requiresleep2;
public static boolean aftersleep;
public static boolean autoscroll;
protected static void refresh() {
long delta = System.currentTimeMillis();
d.setColor(new Color(204, 231, 212));
d.fillRect(0, 0, screenSize[0], screenSize[1]);
if (equazione == "") {
d.setColor(Color.BLACK);
d.drawString("Scrivi qua sopra un'espressione,".toUpperCase(), 10, 20);
d.drawString("dopodiche premi il tasto execute".toUpperCase(), 10, 35);
d.setColor(Color.RED);
d.drawBoldString( "Leggi ATTENZIONE.txt!".toUpperCase(), 10, 60);
} else {
if (ew1 + x1 + 5 > screenSize[0] && !requiresleep1 && autoscroll) {
x1-=1;
} else if(autoscroll) {
requiresleep1 = true;
}
if (ew2 + x2 + 5 > screenSize[0] && !requiresleep2 && autoscroll) {
x2-=1;
} else if(autoscroll) {
requiresleep2 = true;
}
if (requiresleep1 && requiresleep2 && autoscroll) {
requiresleep1 = false;
requiresleep2 = false;
try {
Thread.sleep(500);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
x1 = 2;
x2 = 2;
aftersleep = true;
}
f.draw(x1,2,d, false);
f2.draw(x2,screenSize[1]-2-eh2,d, false);
}
if (aftersleep && autoscroll) {
aftersleep = false;
try {
Thread.sleep(500);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
try {
delta = System.currentTimeMillis() - delta;
if (50-delta > 0 && autoscroll) {
Thread.sleep(50-delta);
}
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
public Main() throws InterruptedException {
instance = this;
d = new Display(new EmptyScreen(), screenSize[0], screenSize[1]);
d.setBackground(0.796875f, 0.90234375f, 0.828125f);
Thread t = new Thread("Graphic thread"){@Override public void run() {d.run("");}};
t.start();
}
public static void main(String[] args) throws InterruptedException {
new Main();
}
@Override
public synchronized void refresh(String args) {
equazione = args.replace("sqrt", "").replace("^", "");
c = new Calculator(true);
try {
f = new Parentesi(equazione);
} catch (Errore e) {
e.printStackTrace();
}
try {
f2 = f.calcolaSistema();
} catch (Errore e) {
e.printStackTrace();
}
ew1 = f.getWidth();
ew2 = f2.getWidth();
eh2 = f2.getHeight(false);
x1 = 2;
x2 = 2;
requiresleep1 = false;
requiresleep2 = false;
aftersleep = false;
autoscroll = false;
}
}

View File

@ -10,7 +10,6 @@ import java.util.regex.Pattern;
import org.nevec.rjm.NumeroAvanzato;
import org.nevec.rjm.NumeroAvanzatoVec;
import org.warp.engine.Display;
public class Parentesi extends FunzioneMultipla {
@ -356,6 +355,7 @@ public class Parentesi extends FunzioneMultipla {
fase = "sistemi"; //SESTA FASE
} else {
System.out.println("errore?");//BOH
throw new Errore(Errori.SYNTAX_ERROR);
}
while (i < funzioniOLD.size() && change == false && funzioniOLD.size() > 1) {
Funzione funzioneTMP = funzioniOLD.get(i);

View File

@ -11,7 +11,6 @@ import org.nevec.rjm.BigDecimalMath;
import org.nevec.rjm.NumeroAvanzato;
import org.nevec.rjm.NumeroAvanzatoVec;
import org.nevec.rjm.Rational;
import org.warp.engine.Display;
import com.rits.cloning.Cloner;

View File

@ -13,8 +13,6 @@ import java.util.ArrayList;
import org.nevec.rjm.BigDecimalMath;
import org.nevec.rjm.Rational;
import org.warp.engine.Display;
import org.warp.engine.Display.Font;
public class Utils {
@ -23,8 +21,6 @@ public class Utils {
public static final int scaleMode = BigDecimal.ROUND_HALF_UP;
public static final RoundingMode scaleMode2 = RoundingMode.HALF_UP;
public static final Font fontBig = new Font("CalcBig", Font.PLAIN, 16);
public static final Font fontSmall = new Font("CalcSmall", Font.PLAIN, 16);
public static DebugStream debug = new DebugStream();
@ -337,21 +333,6 @@ public class Utils {
g.drawOrthoLine(x+3, y, x+3+1+w1+2, y);
}
public static final int getPlainTextWidth(String text) {
Graphics graphics = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB).getGraphics();
// get metrics from the graphics
FontMetrics metrics = graphics.getFontMetrics(fontBig.getFontAwt());
// get the advance of my text in this font
// and render context
int adv = metrics.stringWidth(text);
// calculate the size of a box to hold the
// text with some padding.
if (adv > 0) {
adv-=1;
}
return adv;
}
public static final int getFontHeight() {
return getFontHeight(false);
}