#### Java-Code

This function only looks at the calculation process for a given pixel. You need to repeat this function for every pixel in your frame.

Contact me if you do not know how to implement this code in your program or need additional code.

Contact me if you do not know how to implement this code in your program or need additional code.

```
//
```*Screen width and height:*

final int **WIDTH**, **HEIGHT**;

//*Coordinates:*

double **xLoc**, **yLoc**, **zoom**;

//*Iteration limit:*

int **maxIterations**;

private **Color** mandelbrot(int **x**, int **y**) {

//*Adjusts the coordinate system to screen size:*

`x` -= this.`WIDTH` / 2;

`y` -=this.`HEIGHT` / 2;

double **real** = (double) `x` / (this.`WIDTH` / 2);

double **imaginary** = (double) `y` / (this.`HEIGHT` / 2);

//*Moves and zooms in to given x/y-location and zoom:*

`real` = `real` * this.`zoom` + this.`xLoc`;

`imaginary` = `imaginary` * this.`zoom` + this.`yLoc`;

//*Stores the original complex number:*

double **tempReal** = `real`;

double **tempImaginary** = `imaginary`;

int **n** = 0;

while (`n` < this.`maxIterations`) {

double **oldTemporary** = `tempReal`;

//*The following calculation is explained right here.*

`real` = (`real` * `real` - `imaginary` * `imaginary`) + `tempReal`;

`imaginary` = (2 * `oldTemporary` * `imaginary`) + `tempImaginary`;

//*Stops the calculation if the formula is going to infinity*

if (Math.abs(`real` + `imaginary`) > 16) {

**break**;

}

`n++`;

}

if (`n` == this.`maxIterations`) {

//*Returns a black color when the complex number is in the Mandelbrot set:*

return **new Color(0)**;

} else {

//*Returns a color with individual hue when the complex number is not in the Mandelbrot set:*

float **hue** = ((float) `n` / (float) this.`maxIterations`);

return Color.getHSBColor(`hue`, 1.0f, 1.0f);

}

}