added finish message

This commit is contained in:
nora 2020-11-18 16:43:04 +01:00
parent 36384cd7bc
commit eb71992b08
3 changed files with 41 additions and 26 deletions

View file

@ -18,6 +18,8 @@ public class CalculationThread extends Thread {
double[][] zoomValues; double[][] zoomValues;
CNumber[][] samples; CNumber[][] samples;
MandelbrotSet set;
public void run() { public void run() {
long totalStartTime = System.currentTimeMillis(); long totalStartTime = System.currentTimeMillis();
@ -49,16 +51,19 @@ public class CalculationThread extends Thread {
createImage(image, frameCounter, width, height, values, iterations); createImage(image, frameCounter, width, height, values, iterations);
long frameTime = System.currentTimeMillis() - startTime; long frameTime = System.currentTimeMillis() - startTime;
System.out.println("------------------------Frame " + frameCounter + " finished in " + ((double) frameTime / 1000) + "s------------------------"); System.out.println("Frame " + frameCounter + " finished in " + ((double) frameTime / 1000) + "s");
} }
long totalTime = System.currentTimeMillis() - totalStartTime; long totalTime = System.currentTimeMillis() - totalStartTime;
System.out.println("Thread " + threadNumber + " completed. Process took " + ((double) totalTime / 1000) + "s"); System.out.println("--Thread " + threadNumber + " completed. Process took " + ((double) totalTime / 1000) + "s");
set.setFinished(threadNumber);
} }
public CalculationThread(int number, int threads, int frames, int widthC, int heightC, int iterationsC, int thresholdC, double[][] zoomValuesC) { public CalculationThread(MandelbrotSet set, int number, int threads, int frames, int widthC, int heightC, int iterationsC, int thresholdC, double[][] zoomValuesC) {
this.set = set;
this.threadNumber = number; this.threadNumber = number;
this.threadAmount = threads; this.threadAmount = threads;
this.frameAmount = frames; this.frameAmount = frames;
@ -80,8 +85,6 @@ public class CalculationThread extends Thread {
*/ */
void createImage(BufferedImage image, int counter, int width, int height, double[][] values, int iterations) { void createImage(BufferedImage image, int counter, int width, int height, double[][] values, int iterations) {
//System.out.println("Frame: " + counter + " | Started creating image...");
int p0 = getColorAsInt(0, 0, 0, 0); int p0 = getColorAsInt(0, 0, 0, 0);
int t0 = -1; int t0 = -1;
@ -100,16 +103,15 @@ public class CalculationThread extends Thread {
} }
} }
try { try {
File f = new File("C:\\Users\\nilsh\\Desktop\\testordner/sterbi" + counter + ".png"); File f = new File("C:\\Users\\nilsh\\Desktop\\testordner/image" + counter + ".png");
ImageIO.write(image, "png", f); ImageIO.write(image, "png", f);
System.out.println(f.getAbsolutePath());
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
/** /**
* Checks wheter the number is in the Mandelbrot set * Checks whether the number is in the Mandelbrot set
* @param number The Complex Number to be checked * @param number The Complex Number to be checked
* @param iterations The amount of iterations the program should do * @param iterations The amount of iterations the program should do
* @param threshold The threshold for a number not being in the set * @param threshold The threshold for a number not being in the set

View file

@ -1,11 +1,5 @@
package mandelbrotCalculator; package mandelbrotCalculator;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
public class MandelbrotSet { public class MandelbrotSet {
private double[][] interestingPoints = {{-0.75, 0}, {-0.77568377, 0.13646737}, {-1.74995768370609350360221450607069970727110579726252077930242837820286008082972804887218672784431700831100544507655659531379747541999999995, 0.00000000000000000278793706563379402178294753790944364927085054500163081379043930650189386849765202169477470552201325772332454726999999995}}; private double[][] interestingPoints = {{-0.75, 0}, {-0.77568377, 0.13646737}, {-1.74995768370609350360221450607069970727110579726252077930242837820286008082972804887218672784431700831100544507655659531379747541999999995, 0.00000000000000000278793706563379402178294753790944364927085054500163081379043930650189386849765202169477470552201325772332454726999999995}};
@ -22,12 +16,16 @@ public class MandelbrotSet {
private int width = 1920; private int width = 1920;
private int threshold = 1000; private int threshold = 1000;
private float ratio = 2 / 3f; private float ratio = 2 / 3f;
private int threadAmount = 10; private int threadAmount = Runtime.getRuntime().availableProcessors();
//only declared //only declared
private int height; private int height;
private int iterations; private int iterations;
private boolean[] complete;
private long startTime = System.currentTimeMillis();
/** /**
* Create a new Mandelbrot set manager * Create a new Mandelbrot set manager
@ -51,6 +49,8 @@ public class MandelbrotSet {
case 4 -> 5000; case 4 -> 5000;
default -> quality; default -> quality;
}; };
complete = new boolean[threadAmount];
} }
public MandelbrotSet(){ public MandelbrotSet(){
@ -59,6 +59,8 @@ public class MandelbrotSet {
public void startMandelbrot() { public void startMandelbrot() {
System.out.println("Started calculating " + frames + " frame/s");
double forceCenterX; double forceCenterX;
double forceCenterY; double forceCenterY;
if(pointNumber == -1){ if(pointNumber == -1){
@ -69,23 +71,14 @@ public class MandelbrotSet {
forceCenterY = interestingPoints[pointNumber][1]; forceCenterY = interestingPoints[pointNumber][1];
} }
// TIME
long startTime = System.currentTimeMillis();
double[][] zoomValues = zoomValues(frames, width, height, forceCenterX, forceCenterY, zoomSpeed, zoom); double[][] zoomValues = zoomValues(frames, width, height, forceCenterX, forceCenterY, zoomSpeed, zoom);
//create the threads //create the threads
CalculationThread[] threads = new CalculationThread[threadAmount]; CalculationThread[] threads = new CalculationThread[threadAmount];
for (int i = 0; i < threadAmount; i++) { for (int i = 0; i < threadAmount; i++) {
threads[i] = new CalculationThread(i, threadAmount, frames, width, height, iterations, threshold, zoomValues); threads[i] = new CalculationThread(this, i, threadAmount, frames, width, height, iterations, threshold, zoomValues);
threads[i].start(); threads[i].start();
} }
// TIME should probably not be here and serves no practical purpose but that doesn't stop me from keeping it here
long endTime = System.currentTimeMillis();
long completionTimeLong = endTime - startTime;
double completionTimeSec = (double) completionTimeLong / 1000.0;
System.out.println("Prepared " + frames + " frame/s in " + completionTimeSec + "s");
} }
@ -122,6 +115,26 @@ public class MandelbrotSet {
return zoomValues; return zoomValues;
} }
public void setFinished(int threadNumber){
complete[threadNumber] = true;
boolean finished = true;
for(boolean b : complete){
if (!b) {
finished = false;
break;
}
}
if(finished){
System.out.println("CALCULATION FINISHED");
// TIME should probably not be here and serves no practical purpose but that doesn't stop me from keeping it here
long endTime = System.currentTimeMillis();
long completionTimeLong = endTime - startTime;
double completionTimeSec = (double) completionTimeLong / 1000.0;
System.out.println("Calculated " + frames + " frame/s in " + completionTimeSec + "s");
}
}
//SETTER //SETTER
public void setZoom(double zoom) { public void setZoom(double zoom) {

View file

@ -24,7 +24,7 @@ public class Controller {
} }
public void startCalculation(ActionEvent actionEvent) { public void startCalculation(ActionEvent actionEvent) {
MandelbrotSet m = new MandelbrotSet(2, 3, 3, 10); MandelbrotSet m = new MandelbrotSet(2, 2, 3, 10);
m.startMandelbrot(); m.startMandelbrot();
} }
} }