2 * Mandelbrot set ASCII visualisation
3 * http://en.wikipedia.org/wiki/Mandelbrot_set
4 * http://www.root.cz/clanky/barvy-pro-shell/
5 * Copylefted by: Harvie 2oo9
30 aaa ab aa afa afa aa ba aaa
37 public class mandelbrot
{
38 public String
[] chars
= " .`-_\':,;^=+/\\\"|)\\<>)iv%xclrs{*}I?!][1taeo7zjLunT#JCwfy325Fp6mqSghVd4EgXPGZbYkOA&8U$@KHDBWNMR0Q".split("");
39 public int max_iteration
= 140;
40 public float zoom
= 65;
42 public double x_from
= -2;
43 public double x_to
= 2;
44 public double y_from
= -2.1;
45 public double y_to
= 2.1;
47 public boolean color
= false;
48 public boolean background
= false;
64 public int get_pixel_value(double x0
, double y0
) {
70 while( x
*x
+ y
*y
<= (2*2) && iteration
< max_iteration
) {
71 double xtemp
= x
*x
- y
*y
+ x0
;
77 if( iteration
>= max_iteration
) {
85 public String
get_pixel_character(double x
, double y
) {
86 float i
= ((float)get_pixel_value(x
, y
)/(float)max_iteration
) * (chars
.length
-1);
88 return chars
[Math
.round(i
)];
91 public String
get_pixel_xterm_color(double x
, double y
) {
92 int i
= Math
.round( ((float)get_pixel_value(x
, y
)/max_iteration
)*14 );
93 return "\033["+((int)(i
%2))+";"+(30+(int)(i
/2))+"m";
96 public String
get_pixel_xterm_background(double x
, double y
) {
97 int i
= 40+Math
.round( ((float)get_pixel_value(x
, y
)/max_iteration
)*7 );
101 public static void cls() {
102 System
.out
.print("\033[2J");
105 public static void top() {
106 System
.out
.print("\033[0;0H");
110 System
.out
.print("ASCII Mandelbrot Set Visualisation (Harvie 2oo9) - Iterations: "+max_iteration
+", zoom: "+zoom
+" \n");
113 public void render() {
114 //if(color || background) max_iteration = 14;
117 for(x
=x_from
; x
<=x_to
; x
+=5/zoom
) { for(y
=y_from
; y
<=y_to
; y
+=2/zoom
) {
118 if(color
) System
.out
.print(get_pixel_xterm_color(x
, y
));
119 if(background
) System
.out
.print(get_pixel_xterm_background(x
, y
));
121 System
.out
.print(get_pixel_character(x
, y
));
122 //System.out.print(get_pixel_color(x, y)+" ");
123 } System
.out
.println("\033[0m"); }
This page took 1.203521 seconds and 4 git commands to generate.