first version calculating the result
This commit is contained in:
parent
62f2149d5a
commit
86c9c50a3c
Binary file not shown.
@ -28,17 +28,32 @@ import java.util.Hashtable;
|
||||
import org.apache.commons.collections.functors.FalsePredicate;
|
||||
|
||||
import de.ahrgr.animal.kohnert.asugen.Font;
|
||||
import de.ahrgr.animal.kohnert.asugen.Text;
|
||||
import generators.framework.properties.AnimationPropertiesContainer;
|
||||
import algoanim.animalscript.AnimalScript;
|
||||
|
||||
|
||||
/*
|
||||
* TODO:
|
||||
* - erste Folie die drei Schritte der Funktionsweise animieren
|
||||
* - Abschlussfolie(n) mit Komplexitätsbetrachtung der Funktion (sollte n^3 sein)
|
||||
* - Properties für Textfarbe usw. einfügen
|
||||
* - Benutzerinteraktionen einfügen
|
||||
* - Elemente der Matrizen A und B einfärben, wenn diese miteinander multipliziert werden.
|
||||
* - Texte nicht als SourceCode-Objekte, sonder als Textobjekte erstellen.
|
||||
* Somit können die Properties geändert werden.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
public class MatrixGenerator implements Generator {
|
||||
|
||||
/**
|
||||
* static variables -> simple testing
|
||||
*/
|
||||
static int[][] matrixA;
|
||||
static int[][] matrixB;
|
||||
static int[][] matrixA = {{1, 2},{3, 4}};
|
||||
static int[][] matrixB = {{5, 6}, {7, 8}};
|
||||
static SourceCodeProperties SC_PROPS;
|
||||
static SourceCodeProperties TEXT_PROPS;
|
||||
static int HIGHLIGHTING_TIME = 100; // in ticks
|
||||
@ -63,10 +78,34 @@ public class MatrixGenerator implements Generator {
|
||||
/**
|
||||
* The matrices
|
||||
*/
|
||||
private StringMatrix summe = null;
|
||||
private IntMatrix intMatrixA = null;
|
||||
private IntMatrix intMatrixB = null;
|
||||
private IntMatrix intMatrixResult = null;
|
||||
|
||||
/**
|
||||
* unhighlightingTime
|
||||
*/
|
||||
private Timing unhighTime = new Timing(UNHIGHLIGHTING_TIME) {
|
||||
|
||||
@Override
|
||||
public String getUnit() {
|
||||
// TODO Auto-generated method stub
|
||||
return "ticks";
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* highlightTime
|
||||
*/
|
||||
private Timing highTime = new Timing(HIGHLIGHTING_TIME) {
|
||||
|
||||
@Override
|
||||
public String getUnit() {
|
||||
// TODO Auto-generated method stub
|
||||
return "ticks";
|
||||
}
|
||||
};
|
||||
// =========================================================================================================
|
||||
|
||||
/**
|
||||
@ -146,17 +185,17 @@ public class MatrixGenerator implements Generator {
|
||||
/**
|
||||
* Generates the one single matrix including matrixA, matrixB und the calculated result matrix
|
||||
*/
|
||||
public void generateMatrix(){
|
||||
public void generateMatrices(){
|
||||
|
||||
MatrixProperties mp = new MatrixProperties();
|
||||
mp.set(AnimationPropertiesKeys.FILL_PROPERTY, Color.WHITE);
|
||||
|
||||
|
||||
//generate matrixB // X-Achse, Y-Achse
|
||||
//generate matrixB
|
||||
this.intMatrixB = lang.newIntMatrix(new Offset(20, 40, sc, AnimalScript.DIRECTION_S), matrixB, "matrixB", null, mp);
|
||||
|
||||
//generate matrixA with an offset to matrixB
|
||||
this.intMatrixA = lang.newIntMatrix(new Offset((-23*matrixB.length), 10, intMatrixB, AnimalScript.DIRECTION_SW), matrixA, "matrixA", null, mp);
|
||||
this.intMatrixA = lang.newIntMatrix(new Offset((-30*matrixB.length), 10, intMatrixB, AnimalScript.DIRECTION_SW), matrixA, "matrixA", null, mp);
|
||||
|
||||
|
||||
//generate result matrix
|
||||
@ -171,6 +210,13 @@ public class MatrixGenerator implements Generator {
|
||||
this.intMatrixResult = lang.newIntMatrix(new Offset(0, 10, intMatrixB, AnimalScript.DIRECTION_SW), result, "table", null, mp);
|
||||
|
||||
|
||||
String[][] data = new String[1][2];
|
||||
data[0][0] = "Summe = ";
|
||||
data[0][1] = "0";
|
||||
|
||||
this.summe = lang.newStringMatrix(new Offset(15, 0, intMatrixB, AnimalScript.DIRECTION_E), data, "stumme", null);
|
||||
this.summe.changeColor(AnimationPropertiesKeys.FILL_PROPERTY, Color.WHITE, null, null);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -189,7 +235,7 @@ public class MatrixGenerator implements Generator {
|
||||
generateSourceCode();
|
||||
|
||||
//generate matrices
|
||||
generateMatrix();
|
||||
generateMatrices();
|
||||
|
||||
//STEP
|
||||
lang.nextStep();
|
||||
@ -207,6 +253,7 @@ public class MatrixGenerator implements Generator {
|
||||
|
||||
int[][] result = new int[matrixA.length][matrixB[0].length]; // 1
|
||||
int summe = 0; // 2
|
||||
int summetmp = 0;
|
||||
for(int i=0; i<matrixA.length; i++){ // 3
|
||||
//STEP
|
||||
lang.nextStep();
|
||||
@ -223,42 +270,63 @@ public class MatrixGenerator implements Generator {
|
||||
//STEP
|
||||
lang.nextStep();
|
||||
sc.unhighlight(7);
|
||||
intMatrixResult.unhighlightCell(i, j, highTime, unhighTime);
|
||||
sc.unhighlight(4);
|
||||
sc.highlight(5);
|
||||
summetmp = summe;
|
||||
summe = summe + matrixA[i][k]*matrixB[k][j]; // 6
|
||||
//STEP
|
||||
lang.nextStep();
|
||||
sc.unhighlight(5);
|
||||
sc.highlight(6);
|
||||
this.summe.put(0, 1, summetmp+"+("+matrixA[i][k]+"*"+matrixB[k][j]+")", null, null);
|
||||
this.summe.highlightCell(0, 1, highTime, unhighTime);
|
||||
result[i][j]=summe; // 7
|
||||
//STEP
|
||||
lang.nextStep();
|
||||
sc.unhighlight(6);
|
||||
sc.highlight(7);
|
||||
this.summe.unhighlightCell(0, 1, highTime, unhighTime);
|
||||
intMatrixResult.highlightCell(i, j, highTime, unhighTime);
|
||||
intMatrixResult.put(i, j, summe, null, null);
|
||||
} // 8
|
||||
//STEP
|
||||
lang.nextStep();
|
||||
sc.unhighlight(7);
|
||||
sc.highlight(9);
|
||||
summe = 0; // 9
|
||||
intMatrixResult.unhighlightCell(i, j, highTime, unhighTime);
|
||||
summetmp = summe = 0; // 9
|
||||
this.summe.put(0, 1, summetmp+"", null, null);
|
||||
}
|
||||
}
|
||||
//STEP
|
||||
lang.nextStep();
|
||||
sc.unhighlight(9);
|
||||
|
||||
//STEP
|
||||
lang.nextStep();
|
||||
|
||||
//hide all and show the result
|
||||
intMatrixA.hide();
|
||||
intMatrixB.hide();
|
||||
this.summe.hide();
|
||||
|
||||
|
||||
algoanim.primitives.Text ergebnis = lang.newText(new Offset(-60, 0, intMatrixResult, AnimalScript.DIRECTION_NW), "Ergebnis: ", "name", null);
|
||||
|
||||
//STEP
|
||||
lang.nextStep();
|
||||
intMatrixResult.hide();
|
||||
ergebnis.hide();
|
||||
sc.hide();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the statement for the last slides
|
||||
*/
|
||||
private void generateStatement(){
|
||||
|
||||
//hide old stuff
|
||||
sc.hide();
|
||||
intMatrixA.hide();
|
||||
intMatrixB.hide();
|
||||
intMatrixResult.hide();
|
||||
|
||||
|
||||
//TODO: implement the statement for the last view slides!
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user