Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Лукашевич Евгений 230501 #953

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/demo/parallel/Complex.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,11 @@ public Complex times(Complex b) {
im = imag;
return this;
}

public Complex minus(Complex b) {
re -= b.re;
im -= b.im;
return this;
}
/**
* Square of Complex object's length, we're using square of length to
* eliminate the computation of square root
Expand Down
28 changes: 28 additions & 0 deletions src/demo/parallel/ComplexTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package demo.parallel;

import static org.junit.jupiter.api.Assertions.*;

class ComplexTest {

@org.junit.jupiter.api.Test
void plus() {
Complex a = new Complex(1, 1);
Complex b = new Complex(2, 3);

Complex result = a.plus(b);

assertEquals(3, result.re);
assertEquals(4, result.im);
}

@org.junit.jupiter.api.Test
void minus() {
Complex a = new Complex(5, 7);
Complex b = new Complex(2, 3);

Complex result = a.minus(b);

assertEquals(3, result.re);
assertEquals(4, result.im);
}
}
2 changes: 1 addition & 1 deletion src/demo/parallel/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ private Parent createContent(double minR, double minI, double maxR, double maxI)
antiTranslate.xProperty().bind(canvas.translateXProperty().negate());
antiTranslate.yProperty().bind(canvas.translateYProperty().negate());
snapshotParameters.setTransform(antiTranslate);
snapshotParameters.setFill(Color.BLACK);
snapshotParameters.setFill(Color.WHITE);

//Fetch position when Mouse released
canvas.setOnMouseReleased(e -> {
Expand Down
16 changes: 8 additions & 8 deletions src/demo/parallel/MandelbrotSetTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

/**
* Task to render Mandelbrot set using given parameters. See {@link
* #MandelbrotRendererTask(boolean, javafx.scene.image.PixelWriter, int, int,
* #MandelbrotRendererTask(boolean, javafx.scene.image.PixelWriter, int, int,
* double, double, double, double, double, double, double, double, boolean)
* constructor} for parameters list. The task returns time in milliseconds as
* its calculated value.
Expand Down Expand Up @@ -275,7 +275,7 @@ private int calc(Complex comp) {
int count = 0;
Complex c = new Complex(0, 0);
do {
c = c.times(c).plus(comp);
c = c.times(c).minus(comp);
count++;
} while (count < CAL_MAX_COUNT && c.lengthSQ() < LENGTH_BOUNDARY);
return count;
Expand All @@ -289,8 +289,8 @@ private int calc(Complex comp) {
* @return calculated color of the pixel
*/
private Color calcPixel(double x, double y) {
double re = (minR * (width - x) + x * maxR) / width;
double im = (minI * (height - y) + y * maxI) / height;
double re = (minR * (height - y) + x * maxR) / height;
double im = (minI * (width - x) + y * maxI) / width;
Complex calPixel = new Complex(re, im);
return getColor(calc(calPixel));
}
Expand Down Expand Up @@ -351,13 +351,13 @@ private Color getColor(int count) {
* Color stops for colors table: color values
*/
Color[] cc = {
Color.rgb(40, 0, 0),
Color.rgb(50, 10, 0),
Color.RED,
Color.WHITE,
Color.BLUE,
Color.rgb(90, 20, 15),
Color.RED,
Color.rgb(100, 0, 0),
Color.RED,
Color.rgb(50, 0, 0)
Color.rgb(44, 47, 13)
};

/**
Expand Down