Mandlebrot task class












0














I'm trying to implement mandelbrot however it my main classes it draws a single color because all of the iteration counts are staying at zero. I've looked for the cause of this for a while and couldn't determine what is causing it to do this. I looked for other sources however their approach was completely different. All of the drawing is done in the main class and the magnitude add and multiply methods were created in a third class.



package edu.ycp.cs201.mandelbrot;

public class MandelbrotTask implements Runnable {
private double x1, y1, x2, y2;
private int startCol, endCol, startRow, endRow;
private int iterCounts;

public MandelbrotTask(double x1, double y1, double x2, double y2,
int startCol, int endCol, int startRow, int endRow,
int iterCounts) {
this.x1 = x1;
this.y1 = y1;
this.x2 = x2;
this.y2 = y2;
this.startCol = startCol;
this.endCol = endCol;
this.startRow = startRow;
this.endRow = endRow;
this.iterCounts = iterCounts;
}

public void run() {
for (int i = startRow; i < endRow; i++) {
for (int j = startCol; j < endCol; j++) {
Complex c = getComplex(i, j);
int iterCount = computeIterCount(c);
iterCounts[i][j] = iterCount;
}
}
}

// TODO: implement getComplex and computeIterCount methods
public Complex getComplex(int x, int y) {
//return new Complex (x, y);
double col = (double) endCol - (double) startCol;
double row = (double) endRow - (double) startRow;
double dx = x2 - x1;
double dy = y2 - y1;
return new Complex(x1 + dx / col * x, y1 + dy / row * y);
}

public int computeIterCount(Complex complex) {
//Zo is initially 0+0i
Complex z = new Complex(0,0);
//# of iterations
int count = 0;
//while z has magnitude of less than 2 and iteration counts have not
exceeded MAX
for (int k = 0; k < 100; k++) {
//iterate complex number
z = z.multiply(z).add(complex);
//if magnitude of complex number is >2 stop
if (z.getMagnitude() > 2) {
break;
}
//increment count
count++;
}
return count;
}
}









share|improve this question






















  • Did you copy and paste this code directly from source? The code as provided wouldn't compile due an exposed comment in the computeIterCount function, right above the for loop.
    – Juan
    Nov 23 at 0:33












  • Are you sure you’re calling the run() method of MandlebrotTask?
    – VGR
    Nov 23 at 2:19
















0














I'm trying to implement mandelbrot however it my main classes it draws a single color because all of the iteration counts are staying at zero. I've looked for the cause of this for a while and couldn't determine what is causing it to do this. I looked for other sources however their approach was completely different. All of the drawing is done in the main class and the magnitude add and multiply methods were created in a third class.



package edu.ycp.cs201.mandelbrot;

public class MandelbrotTask implements Runnable {
private double x1, y1, x2, y2;
private int startCol, endCol, startRow, endRow;
private int iterCounts;

public MandelbrotTask(double x1, double y1, double x2, double y2,
int startCol, int endCol, int startRow, int endRow,
int iterCounts) {
this.x1 = x1;
this.y1 = y1;
this.x2 = x2;
this.y2 = y2;
this.startCol = startCol;
this.endCol = endCol;
this.startRow = startRow;
this.endRow = endRow;
this.iterCounts = iterCounts;
}

public void run() {
for (int i = startRow; i < endRow; i++) {
for (int j = startCol; j < endCol; j++) {
Complex c = getComplex(i, j);
int iterCount = computeIterCount(c);
iterCounts[i][j] = iterCount;
}
}
}

// TODO: implement getComplex and computeIterCount methods
public Complex getComplex(int x, int y) {
//return new Complex (x, y);
double col = (double) endCol - (double) startCol;
double row = (double) endRow - (double) startRow;
double dx = x2 - x1;
double dy = y2 - y1;
return new Complex(x1 + dx / col * x, y1 + dy / row * y);
}

public int computeIterCount(Complex complex) {
//Zo is initially 0+0i
Complex z = new Complex(0,0);
//# of iterations
int count = 0;
//while z has magnitude of less than 2 and iteration counts have not
exceeded MAX
for (int k = 0; k < 100; k++) {
//iterate complex number
z = z.multiply(z).add(complex);
//if magnitude of complex number is >2 stop
if (z.getMagnitude() > 2) {
break;
}
//increment count
count++;
}
return count;
}
}









share|improve this question






















  • Did you copy and paste this code directly from source? The code as provided wouldn't compile due an exposed comment in the computeIterCount function, right above the for loop.
    – Juan
    Nov 23 at 0:33












  • Are you sure you’re calling the run() method of MandlebrotTask?
    – VGR
    Nov 23 at 2:19














0












0








0







I'm trying to implement mandelbrot however it my main classes it draws a single color because all of the iteration counts are staying at zero. I've looked for the cause of this for a while and couldn't determine what is causing it to do this. I looked for other sources however their approach was completely different. All of the drawing is done in the main class and the magnitude add and multiply methods were created in a third class.



package edu.ycp.cs201.mandelbrot;

public class MandelbrotTask implements Runnable {
private double x1, y1, x2, y2;
private int startCol, endCol, startRow, endRow;
private int iterCounts;

public MandelbrotTask(double x1, double y1, double x2, double y2,
int startCol, int endCol, int startRow, int endRow,
int iterCounts) {
this.x1 = x1;
this.y1 = y1;
this.x2 = x2;
this.y2 = y2;
this.startCol = startCol;
this.endCol = endCol;
this.startRow = startRow;
this.endRow = endRow;
this.iterCounts = iterCounts;
}

public void run() {
for (int i = startRow; i < endRow; i++) {
for (int j = startCol; j < endCol; j++) {
Complex c = getComplex(i, j);
int iterCount = computeIterCount(c);
iterCounts[i][j] = iterCount;
}
}
}

// TODO: implement getComplex and computeIterCount methods
public Complex getComplex(int x, int y) {
//return new Complex (x, y);
double col = (double) endCol - (double) startCol;
double row = (double) endRow - (double) startRow;
double dx = x2 - x1;
double dy = y2 - y1;
return new Complex(x1 + dx / col * x, y1 + dy / row * y);
}

public int computeIterCount(Complex complex) {
//Zo is initially 0+0i
Complex z = new Complex(0,0);
//# of iterations
int count = 0;
//while z has magnitude of less than 2 and iteration counts have not
exceeded MAX
for (int k = 0; k < 100; k++) {
//iterate complex number
z = z.multiply(z).add(complex);
//if magnitude of complex number is >2 stop
if (z.getMagnitude() > 2) {
break;
}
//increment count
count++;
}
return count;
}
}









share|improve this question













I'm trying to implement mandelbrot however it my main classes it draws a single color because all of the iteration counts are staying at zero. I've looked for the cause of this for a while and couldn't determine what is causing it to do this. I looked for other sources however their approach was completely different. All of the drawing is done in the main class and the magnitude add and multiply methods were created in a third class.



package edu.ycp.cs201.mandelbrot;

public class MandelbrotTask implements Runnable {
private double x1, y1, x2, y2;
private int startCol, endCol, startRow, endRow;
private int iterCounts;

public MandelbrotTask(double x1, double y1, double x2, double y2,
int startCol, int endCol, int startRow, int endRow,
int iterCounts) {
this.x1 = x1;
this.y1 = y1;
this.x2 = x2;
this.y2 = y2;
this.startCol = startCol;
this.endCol = endCol;
this.startRow = startRow;
this.endRow = endRow;
this.iterCounts = iterCounts;
}

public void run() {
for (int i = startRow; i < endRow; i++) {
for (int j = startCol; j < endCol; j++) {
Complex c = getComplex(i, j);
int iterCount = computeIterCount(c);
iterCounts[i][j] = iterCount;
}
}
}

// TODO: implement getComplex and computeIterCount methods
public Complex getComplex(int x, int y) {
//return new Complex (x, y);
double col = (double) endCol - (double) startCol;
double row = (double) endRow - (double) startRow;
double dx = x2 - x1;
double dy = y2 - y1;
return new Complex(x1 + dx / col * x, y1 + dy / row * y);
}

public int computeIterCount(Complex complex) {
//Zo is initially 0+0i
Complex z = new Complex(0,0);
//# of iterations
int count = 0;
//while z has magnitude of less than 2 and iteration counts have not
exceeded MAX
for (int k = 0; k < 100; k++) {
//iterate complex number
z = z.multiply(z).add(complex);
//if magnitude of complex number is >2 stop
if (z.getMagnitude() > 2) {
break;
}
//increment count
count++;
}
return count;
}
}






java complex-numbers






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 22 at 22:53









Dakota Hilbert

1




1












  • Did you copy and paste this code directly from source? The code as provided wouldn't compile due an exposed comment in the computeIterCount function, right above the for loop.
    – Juan
    Nov 23 at 0:33












  • Are you sure you’re calling the run() method of MandlebrotTask?
    – VGR
    Nov 23 at 2:19


















  • Did you copy and paste this code directly from source? The code as provided wouldn't compile due an exposed comment in the computeIterCount function, right above the for loop.
    – Juan
    Nov 23 at 0:33












  • Are you sure you’re calling the run() method of MandlebrotTask?
    – VGR
    Nov 23 at 2:19
















Did you copy and paste this code directly from source? The code as provided wouldn't compile due an exposed comment in the computeIterCount function, right above the for loop.
– Juan
Nov 23 at 0:33






Did you copy and paste this code directly from source? The code as provided wouldn't compile due an exposed comment in the computeIterCount function, right above the for loop.
– Juan
Nov 23 at 0:33














Are you sure you’re calling the run() method of MandlebrotTask?
– VGR
Nov 23 at 2:19




Are you sure you’re calling the run() method of MandlebrotTask?
– VGR
Nov 23 at 2:19

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53438826%2fmandlebrot-task-class%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53438826%2fmandlebrot-task-class%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

What visual should I use to simply compare current year value vs last year in Power BI desktop

How to ignore python UserWarning in pytest?

Alexandru Averescu