-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmandelbrot.java
64 lines (45 loc) · 1.22 KB
/
mandelbrot.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
import java.util.Scanner;
public class mandelbrot {
public static complex square( complex a ) {
return new complex( a.a * a.a - a.b * a.b, 2*a.a*a.b );
}
public static double abs( complex a ) {
return Math.sqrt( a.a*a.a + a.b*a.b );
}
public static complex add( complex a, complex b ) {
return new complex( a.a + b.a, a.b + b.b );
}
public static void main(String[] args) {
Scanner scan = new Scanner( System.in );
int casenum = 1;
while(scan.hasNextLine()) {
double a = scan.nextDouble();
double b = scan.nextDouble();
int its = scan.nextInt();
its++;
scan.nextLine();
complex start = new complex( 0.0, 0.0 );
complex in = new complex( a, b );
boolean bad = false;
while( its --> 0 ){
if( abs( start ) > 2 )
bad = true;
start = add( square( start ), in );
}
if(!bad)//lens.get( lens.size()-1 ) > 2)
System.out.println("Case " + casenum + ": IN");
else
System.out.println( "Case " + casenum + ": OUT" );
casenum++;
}
scan.close();
}
}
class complex {
double a;
double b;
public complex(double a, double b) {
this.a = a;
this.b = b;
}
}