# s#((?{$a.=$+})\s?(\S*)\s?)*#$a=~s/Z/ /g;$a#see #### ( $width, $height ) = split /x/, shift || "19x20"; #### $x_max = 10 + 10 * $width; $y_max = 20 + 10 * $height; #### @m = ( ( 31, (15) x ( $width - 1 ) ) x $height, (31) x $width ); #### # 8 # 1 2 # 4 # v u d r l # 1 1 1 1 1 #### $m[$c] |= 16, #### !( #### @a = grep !( $m[ $c + $$_[0] ] & 16 + $| * $$_[1] ), #left [ -1, 8 ], #right [ 1, 1 ], # up [ $width, 4 ], # down [ -$width, 2 ] ) #### ? $c = pop @p : #### ${ ( $i, $j ) = @{ $a[ rand @a ] }; #### $m[$c] &= ~ (8 / $j); #### push @p, $c; #### $m[ $c += $i ] &= ~$j; #### ++$counter - $height * $width + $height || map $_ &= 15, @m, splice(@p), $c = $| = 1 } #### #print"\ec", # map$_%9?($_-$c?$m[$_]&2?_:$":o).($m[$_]&8?"|":_):$/,1..72 #### until $| & $c + 2 > $width * $height; #### $space = $x_max - 4 * int $x_max / 4; #### $image_size = ( $x_max + $space ) * $y_max; #### $image = pack "x" x ( ( $x_max + $space ) * $y_max ); #### sub line { my ( $x1, $x_len, $y1, $y2, $e ) = @_; #### @a = sort { "000$a" <=> "000$b" } $y1, $y2 || $y1; for ( $a[0] .. $a[1] ) { #### $s = ( $y_max - $_ ) * ( $x_max + $space ) + $x1; vec( $image, $_, 8 ) = $e || 2 for $s .. $s + $x_len - 1; } } #### sub t { $a = shift; $x = 10 * ( $a % $width ); $y = 10 * ( 2 + int $a / $width ) } #### # top line 9, $x_max - 20, 10; # bottom line 9, $x_max - 20, $y_max - 10; # left line 9, 1, 10, $y_max - 10; # right line $x_max- 11, 1, 10, $y_max - 10; #### map { #### t $_; #### if ( $_ % $width ) { #### $m[$_] & 2 ? line $x - 1, 11, $y : ""; #### $m[$_] & 8 ? line $x + 9, 1, $y - 10, $y : ""; } #### } 0 .. -1 + $width * $height; #### open( FH, ">al.avi" ); binmode FH; select FH; # a space saver $LIST = "LIST"; #### print pack "V*", /\d/ ? $_ : unpack "V*", $_ for #### "RIFF", # length of file (header length + data length + index length) ( 1256 + ( $image_size + 24 ) * ( $num_frames = 3 + scalar @p ) ), "AVI $LIST", 1216, "hdrl", "avih", 56, 500000, 32, 0, # avi flags (hasindex etc) 2064, $num_frames, 0, 1, $image_size, # movie width $x_max, # movie height $y_max, (0) x 4, $LIST, 1140, "strl", "strh", 56, "vids", (0) x 4, 1, 10, 0, $num_frames, $image_size, -1, (0) x 3, "strf", # length of avi header: # (40) + length of color table (1024) 1064, #### 40, $x_max, $y_max, # 8 is the bits per pixel pack( "vv", 1, 8 ), 0, $image_size, (0) x 4, #### pack( ( "H" x 1024 ), "f", "f", "f", 0, "a" ), #### # "JUNK", # , # #### $LIST, #### ( 4 + ( $image_size + 8 ) * $num_frames ), "movi"; #### map { #### print STDOUT ++$G, $/; #### t $previous|| 1; #### $left = $x; #### $top = $y; #### t $_; $right = $x; #### if ( $left > $x ) { $right = $left; $left = $x } #### line $left+ 2, 5 + $right - $left, ( $top < $y ? $top : $y ) - 7, ( $top < $y ? $y : $top ) - 3, #### 1; $previous = $_; #### print "00db" . pack( "V", $image_size ) . $image } @p, ( -1 + $width * $height ) x 3; #### print "idx1" . pack "V", 16 * $num_frames; $o = 4; #### for ( 1 .. $num_frames ) { print "00db" . pack "VVV", 16, $o, $image_size; $o += $image_size + 8 }