-
Notifications
You must be signed in to change notification settings - Fork 0
/
JuliaSet.java
68 lines (59 loc) · 1.53 KB
/
JuliaSet.java
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/**
* Represents a Julia set. Extend by implementing the ADD() method, which should
* return the complex offset. Represented by Z_(n+1) = (Z_n)^2 + ADD
*
* @author Samuel Lieberman
*
*/
public abstract class JuliaSet implements RecursiveFractal {
private static final Complex START_POS = new Complex(0, 0);
private static final double DIVERGE_RADIUS = 2;
public abstract Complex ADD();
public boolean IS_COMPLEX() {
return false;
}
public Complex POWER_COM() {
return new Complex(2, 0);
}
public int POWER_RE() {
return 2;
}
@Override
public Complex start(Complex initial) {
return initial;
}
@Override
public Complex step(Complex c, Complex initial) {
return ImMath.add(ImMath.pow(c, 2), ADD());
}
@Override
public boolean diverges(Complex c, int iterations) {
return c.r() > DIVERGE_RADIUS;// && Math.abs(c.im()) < DIVERGE_RADIUS;
}
@Override
public String getName() {
if (IS_COMPLEX()) {
return "Julia Set^(" + POWER_COM() + ") " + ADD();
}else if (POWER_RE() != 2) {
return "Julia Set^" + POWER_RE() + " " + ADD();
}else {
return "Julia Set " + ADD();//1-phi";
}
}
@Override
public String getFormula() {
if (IS_COMPLEX()) {
return "Z_n+1 = (Z_n)^(" + POWER_COM() + ") + " + ADD();
}else {
return "Z_n+1 = (Z_n)^" + POWER_RE() + " + " + ADD();
}
}
@Override
public Complex getInitialScreenCenter() {
return START_POS;
}
@Override
public double getInitialScreenDiameter() {
return DIVERGE_RADIUS*2;
}
}