root/examples/mandel-p5.pl

Revision 11263, 1.3 kB (checked in by Darren_Duncan, 3 years ago)

renamed about 23 example Perl 6 scripts from *.p6 to *.pl ... there are many yet to do

  • Property svn:mime-type set to text/plain; charset=UTF-8
  • Property svn:eol-style set to native
Line 
1#!perl
2
3# vim:ft=perl:sw=4:
4# Print the Mandlebrot set
5#
6# Translated from C code by Glenn Rhoads
7# to perl6 by Leopold Toetsch <lt@toetsch.at>
8#
9# The C code is:
10#
11# main(){
12#
13#  int x, y, k;
14#  char *b = " .:,;!/>)|&IH%*#";
15#  float r, i, z, Z, t, c, C;
16#  for (y=30; puts(""), C = y*0.1 - 1.5, y--;){
17#     for (x=0; c = x*0.04 - 2, z=0, Z=0, x++ < 75;){
18#        for (r=c, i=C, k=0; t = z*z - Z*Z + r, Z = 2*z*Z + i, z=t, k<112; k++)
19#           if (z*z + Z*Z > 10) break;
20#        printf (b[k%16]);
21#        }
22#     }
23# }
24#
25
26my ($x, $y, $k);
27my $b = ' .:,;!/>)|&IH%*#';
28
29my ($P, $Q, $X, $L);
30my ($r, $i, $z, $Z, $t, $c, $C);
31for ($L = 0;; $L++) {
32    last() if $L > 0;
33for ($y=30;
34    $P = $y * 0.1, $C = $P - 1.5, 1;
35    ) {
36    last() if $y < 0;
37    $y--;
38    for ($x=0;
39        $P = $x * 0.04, $c = $P - 2,
40        $z=0.0, $Z=0.0, 1;) {
41        last() if $x > 75;
42        $x++;
43        for ($r=$c, $i=$C, $k=0;
44            $P = $z*$z, $Q = $Z*$Z, $P = $P-$Q, $t = $P+$r,
45            $P = $z*2.0,$P = $P*$Z, $Z = $P + $i,
46            $z=$t, 1; $k++) {
47            last() if $k > 12;
48            $P = $z * $z;
49            $Q = $Z * $Z;
50            $P = $P + $Q;
51            last() if $P > 10.0;
52        }
53        $P = $k % 12;
54        $X = substr($b, $P, 1);
55        print $X;
56    }
57    print "\n";
58}
59
60}
Note: See TracBrowser for help on using the browser.