-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMandelBrotSet.java
More file actions
43 lines (29 loc) · 1.01 KB
/
Copy pathMandelBrotSet.java
File metadata and controls
43 lines (29 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/* This class finds out whether a given complex number is part of the mandelbrotset,
* does so by checking the number of iterations it takes for a given number to escape to infinity.
* if the iterations == max_iterations it means the number hasn't escaped to infinity after various iterations
* if iterations < max_iterations that means the number has already escaped to infinity prior to even reaching the MAX_ITERATIONS. **/
public class MandelBrotSet{
private int MAX_ITERATIONS = 1000;
private double ESCAPE_THRESHOLD = 2.0;
private int iterations;
//the algorithm
//returns iterations
public int calculateSets(double xo, double yo) {
double xTemp;
//set the starting point
double x = 0;
double y = 0;
//initialize iterations at 0.
iterations = 0;
while(x*x+y*y<ESCAPE_THRESHOLD*ESCAPE_THRESHOLD && iterations<MAX_ITERATIONS) {
xTemp = x*x - y*y + xo;
y = 2*x*y + yo;
x = xTemp;
iterations++;
}
return iterations;
}
public int getMaxIterations() {
return MAX_ITERATIONS;
}
}