Preview is now shown

This commit is contained in:
nora 2020-11-18 19:17:15 +01:00
parent eb71992b08
commit 97d87fb1ba
5 changed files with 58 additions and 15 deletions

View file

@ -50,6 +50,8 @@ public class CalculationThread extends Thread {
createImage(image, frameCounter, width, height, values, iterations);
set.frameFinished(frameCounter);
long frameTime = System.currentTimeMillis() - startTime;
System.out.println("Frame " + frameCounter + " finished in " + ((double) frameTime / 1000) + "s");

View file

@ -1,5 +1,9 @@
package mandelbrotCalculator;
import ui.Controller;
import java.io.FileNotFoundException;
public class MandelbrotSet {
private double[][] interestingPoints = {{-0.75, 0}, {-0.77568377, 0.13646737}, {-1.74995768370609350360221450607069970727110579726252077930242837820286008082972804887218672784431700831100544507655659531379747541999999995, 0.00000000000000000278793706563379402178294753790944364927085054500163081379043930650189386849765202169477470552201325772332454726999999995}};
@ -16,16 +20,19 @@ public class MandelbrotSet {
private int width = 1920;
private int threshold = 1000;
private float ratio = 2 / 3f;
private int threadAmount = Runtime.getRuntime().availableProcessors();
private int threadAmount = Runtime.getRuntime().availableProcessors() / 2;
//only declared
private int height;
private int iterations;
private boolean[] complete;
private boolean[] completeThreads;
private boolean[] completeFrames;
private long startTime = System.currentTimeMillis();
private Controller controller;
/**
* Create a new Mandelbrot set manager
@ -34,10 +41,11 @@ public class MandelbrotSet {
* @param zoomSpeed By how much the zoom value is multiplied every frame
* @param frames The number of frames to be calculated
*/
public MandelbrotSet(int pointNumber, int quality, double zoomSpeed, int frames) {
public MandelbrotSet(int pointNumber, int quality, double zoomSpeed, int frames, Controller controller) {
this.pointNumber = pointNumber;
this.zoomSpeed = zoomSpeed;
this.frames = frames;
this.controller = controller;
height = (int) ((float) width * ratio);
@ -50,11 +58,12 @@ public class MandelbrotSet {
default -> quality;
};
complete = new boolean[threadAmount];
completeThreads = new boolean[threadAmount];
completeFrames = new boolean[frames];
}
public MandelbrotSet(){
this(2, 2, 1.2, 1);
public MandelbrotSet(Controller c){
this(2, 2, 1.2, 1, c);
}
public void startMandelbrot() {
@ -115,11 +124,38 @@ public class MandelbrotSet {
return zoomValues;
}
/**
* Call when a new frame is finished
* @param frameNumber The number of the frame
*/
public void frameFinished(int frameNumber){
completeFrames[frameNumber] = true;
int latestFrame = 0;
for(int i = 0; i < completeFrames.length; i++){
if(completeFrames[i]){
latestFrame = i;
}
}
System.err.println(latestFrame);
try {
controller.nextImage(latestFrame);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
/**
* Call when a new Thread is finished
* @param threadNumber The Threadier
*/
public void setFinished(int threadNumber){
complete[threadNumber] = true;
completeThreads[threadNumber] = true;
boolean finished = true;
for(boolean b : complete){
for(boolean b : completeThreads){
if (!b) {
finished = false;
break;

View file

@ -4,6 +4,7 @@ import javafx.event.ActionEvent;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import mandelbrotCalculator.MandelbrotSet;
import util.Values;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
@ -13,18 +14,15 @@ public class Controller {
public ImageView setPreview;
int currentFrame;
public void nextImage(int frameNumber) throws FileNotFoundException {
public void showImage(ActionEvent actionEvent) throws FileNotFoundException {
InputStream stream = new FileInputStream("C:\\Users\\nilsh\\IdeaProjects\\testStuff\\sequence/Sequence" + currentFrame + ".png");
InputStream stream = new FileInputStream(Values.SAVE_IMAGE_PATH + frameNumber + ".png");
Image image = new Image(stream);
setPreview.setImage(image);
currentFrame++;
}
public void startCalculation(ActionEvent actionEvent) {
MandelbrotSet m = new MandelbrotSet(2, 2, 3, 10);
MandelbrotSet m = new MandelbrotSet(2, 1, 3, 100, this);
m.startMandelbrot();
}
}

View file

@ -6,7 +6,7 @@
<GridPane alignment="center" hgap="10.0" prefHeight="143.0" prefWidth="107.0" stylesheets="/ui/sample.css" vgap="10" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ui.Controller">
<Button onAction="#startCalculation" prefHeight="25.0" prefWidth="110.0" text="Start" GridPane.rowIndex="1" />
<ImageView fx:id="setPreview" fitWidth="100" preserveRatio="true" />
<ImageView fx:id="setPreview" fitWidth="500" preserveRatio="true" />
<columnConstraints>
<ColumnConstraints />
</columnConstraints>

7
src/util/Values.java Normal file
View file

@ -0,0 +1,7 @@
package util;
public class Values {
public static final String SAVE_IMAGE_PATH = "C:\\Users\\nilsh\\IdeaProjects\\testStuff\\sequence/Sequence";
}