This is similar to “setting up the coordinates” but goes in opposite direction. We now know the coordinates (i,j) of a pixel on the screen and we need to know the corresponding coordinates (x,y) in the complex plane. We want to do magnifications and shift around the image. For this I made up an object called Coordinates.

We can choose the range of coordinate values and make translations of the image. Without translation and for equal screen height and width, the lower left edge is the point (x=-range,y=-range) and the upper right corner is (x=range,y=range). To show an entire fractal one puts approximately range=1. If you want to see details, you need to choose a smaller value and a suitable translation.

The method pixel(i,j) calculates and returns a complex number from the screen coordinates (i,j).

class Coordinates{
float xRange,yRange;
float yTrans,xTrans;
float iWidth,iHeight;
Coordinates(float range){
iWidth=2./width;
iHeight=2./height;
xRange=range;
yRange=range*height/width;
xTrans=0;
yTrans=0;
}
void setRange(float range){
xRange=range;
yRange=range*height/width;
}
void setTrans(float xT,float yT){
xTrans=xT;
yTrans=yT;
}
// complex number from pixel
Complex pixel(int i,int j){
return new Complex((iWidth*i-1.)*xRange+xTrans,-(iHeight*j-1.)*yRange+yTrans);
}
}

### Like this:

Like Loading...

*Related*