root/examples/mandel.pl

Revision 17704, 1.5 kB (checked in by moritz, 15 months ago)

updated a few examples to s/err/orelse/

  • Property svn:mime-type set to text/plain; charset=UTF-8
  • Property svn:eol-style set to native
Line 
1use v6-alpha;
2
3# vim:ft=perl:sw=4:syn=perl6
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
26### This is badly hacked to get Parrot compiler going ###
27### Should be fixed in a couple days ###
28
29my ($x, $y, $k);
30my $b = ' .:,;!/>)|&IH%*#';
31
32my ($P, $Q, $X, $L);
33my ($r, $i, $z, $Z, $t, $c, $C);
34loop ($L = 0;; $L++) {
35    last() if $L > 0;
36    loop ($y=30; $P = $y * 0.1, $C = $P - 1.5;) {
37        last() if $y < 27;
38        $y--;
39        loop ($x=0; $P = $x * 0.04, $c = $P - 2, $z=0.0, $Z=0.0;) {
40            last() if $x > 75;
41            $x++;
42            loop (
43                $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; $k++
47            ) {
48                last() if $k > 12;
49                $P = $z * $z;
50                $Q = $Z * $Z;
51                $P = $P + $Q;
52                last() if $P > 10.0;
53            }
54            $P = $k % 12;
55            $X = substr($b, $P, 1);
56            print $X;
57        }
58        say '';
59    }
60}
Note: See TracBrowser for help on using the browser.