Commit | Line | Data |
---|---|---|
21c4e167 H |
1 | #!/usr/bin/env perl |
2 | # Mandelbrot set ASCII visualisation | |
3 | # http://en.wikipedia.org/wiki/Mandelbrot_set | |
4 | # Copylefted by: Harvie 2oo9 | |
5 | ||
6 | # | |
7 | # aa | |
8 | # aa | |
9 | # aa | |
10 | # aa | |
11 | # aaaccaaa | |
12 | # aaai iaaa | |
13 | # aabaab baabaa | |
14 | # aab baa | |
15 | # aad daa | |
16 | # aab baa | |
17 | # aaaaad daaaaa | |
18 | # aaacccl lcccaaa | |
19 | # dbaaab baaabd | |
20 | # aab baa | |
21 | # aab baa | |
22 | # aaaaah haaaaa | |
23 | # ba aaaak c c kaaaa ab | |
24 | # aabc cbaa | |
25 | # aacabab babacaa | |
26 | # aae CODING ZEN eaa | |
27 | # aaa aaa | |
28 | # ae n cc n ea | |
29 | # aaa ab aa afa afa aa ba aaa | |
30 | # | |
31 | ||
32 | use strict; | |
33 | use warnings; | |
34 | ||
35 | #my @chars=split(//, ' abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'); | |
36 | #my @chars=split(//, ' .-:*+=%@#'); | |
37 | my @chars=split(//, ' .`-_\':,;^=+/\"|)\\<>)iv%xclrs{*}I?!][1taeo7zjLunT#JCwfy325Fp6mqSghVd4EgXPGZbYkOA&8U$@KHDBWNMR0Q'); | |
38 | ||
39 | my $max_iteration = 140; | |
40 | my $zoom = 65; | |
41 | ||
42 | for($max_iteration=0;$max_iteration<1000;$max_iteration++) { | |
43 | ||
44 | print "\033[0;0H"; | |
45 | print "ASCII Mandelbrot Set Visualisation (Harvie 2oo9) - Iterations: $max_iteration \n"; | |
46 | #for(my $x=-1;$x<=1.1;$x+=0.1) { for(my $y=-2;$y<=1;$y+=0.04) { | |
47 | for(my $i=-2;$i<=2;$i+=5/$zoom) { for(my $j=-2.1;$j<=2.1;$j+=2/$zoom) { | |
48 | ||
49 | my $x0 = $i; | |
50 | my $y0 = $j; | |
51 | ||
52 | my $x = 0; | |
53 | my $y = 0; | |
54 | ||
55 | my $iteration = 0; | |
56 | ||
57 | while ( $x*$x + $y*$y <= (2*2) && $iteration < $max_iteration ) { | |
58 | my $xtemp = $x*$x - $y*$y + $x0; | |
59 | $y = 2*$x*$y + $y0; | |
60 | $x = $xtemp; | |
61 | $iteration++; | |
62 | } | |
63 | ||
64 | my $color; | |
65 | if ( $iteration == $max_iteration ) { | |
66 | $color = 0; | |
67 | } else { | |
68 | $color = int( (($iteration/$max_iteration)*@chars) + .5); | |
69 | } | |
70 | #print "$color\n"; | |
71 | print $chars[$color]; | |
72 | ||
73 | ||
74 | } print "\n"; } | |
75 | ||
76 | } |