#!/usr/bin/perl -w use strict; use PDL; use Algorithm::Loops qw(NestedLoops); my $element = pdl ([1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]); my $tmp = pdl ($element); my @depth = qw (2 3 4 5 6 7 8); foreach my $depth (@depth) { my $same = pdl ($tmp); my $fractal = zeroes 4**$depth,4**$depth; NestedLoops([([0..3])x2],sub{ my ($x,$y) = (@_); my ($a,$b) = ($x*(4**($depth-1)),$y*(4**($depth-1))); my ($c,$d) = ($a+((4**($depth-1))-1),$b+((4**($depth-1))-1)); my $square = slice $fractal, "$a:$c,$b:$d"; $square += $same; },); for my $coord (0..3) { my $a = $coord * (4**($depth-1)); my $b = $a + ((4**($depth-1))-1); my $square = slice $fractal, "$a:$b,$a:$b"; $square += 1; } $tmp = pdl ($fractal); $outFractal = $tmp; }