TT.
TT.

Reputation: 1359

Why does this produce a stretched Fractal?

Here is pseudo-code of how I setup an array representing the MandelBrot set, yet it becomes horribly stretched when leaving an aspect ratio of 1:1.

xStep = (maxX - minX) / width;
yStep = (maxY - minY) / height;

for(i = 0; i < width; i++)
 for(j = 0; j < height; j++)
  {
   constantReal = minReal + xStep * i;
   constantImag = minImag + yStep * j;
   image[i][j] = inSet(constantReal, constantImag);
  }

Thanks!

Upvotes: 4

Views: 485

Answers (3)

Federico A. Ramponi
Federico A. Ramponi

Reputation: 47085

Here is pseudo-code of how I setup an array representing the MandelBrot set, yet it becomes horribly stretched when leaving an aspect ratio of 1:1.

xStep = (maxX - minX) / width;
yStep = (maxY - minY) / height;

Aha! It's because you must keep the same aspect ratio both for the image you will draw and for the region of the complex plane you want to draw. In other words, it must hold

 width     maxX - minX
---------- = ---------------------
 height    maxY - minY

(It follows that xStep == yStep.) Your code probably does not enforce this requirement.

Upvotes: 7

Ned Batchelder
Ned Batchelder

Reputation: 375912

It probably has to do with how you are displaying the image array. You use the width variable i as the first index, but usually the first index should be the slowest changing, that is, the height.

Try changing the last line to image[j][i] = ...

Upvotes: 0

MusiGenesis
MusiGenesis

Reputation: 75376

Make sure your casts are all correct. xStep and yStep might be the products of integer division instead of the expected floating point division (if that's C# in your sample, it would require some explicit casts to work correctly).

Upvotes: 0

Related Questions