#!/usr/bin/perl use strict; use warnings; my%R=map{split"=",$_,-1}"L=+RF-LFL-FR+=R=-LF+RFR+FL-",@ARGV;my$s=eval"use Tk;1"; ($s=0)if$R{n};my($x,$m,$h,$t,$r,$A,@s,@p)=($R{t}||($s?511:33),0,0,0,$R{i}||5, ($R{a}||90)*.0174532925);my$n=$s?[]:[map[map[0,0,0],1..$R{w}||$x],1..$R{h}||$x]; my$v=$s?MainWindow->new->Canvas(bg=>black=>-w=>$R{w}||$x,-he=>$R{h}||$x)->grid( -st=>"news"):0;$x-=3;my@r=my@m=my@o=my@n=(0,0);sub u{$r[0]+cos$m,$r[1]+sin$m} my%f=("-",sub{$m+=$A},"+",sub{$m-=$A},"[",sub{@s=(@s,[$m,@r])},"]",sub{($m,@r)= @{pop@s}},F=>sub{push@p,@r,u;@r=u},M=>sub{@r=u});sub R{map{255*($_>1?1:$_<0?0:$_ )}abs(3-6*$h)-1,map{2-abs(6*$h-$_)}2,4}sub l{$_=int.1+$_ for@_[1..4];my($r,$x,$y ,$X,$Y)=@_;return$v->create(line=>$x,$y,$X,$Y,-f=>sprintf"#%02x%02x%02x",R)if$v; my($V,$c)=($Y-$y,$X-$x);return l($r,$X,$Y,$x,$y)if$c<0;my$s=$V>0?1:-1;$V=abs$V; return l(1,$y,$x,$Y,$X)if$V>abs$c;my$R=$V+$V-$c;for$x($x..$X){$$n[($r?$x:$y)-1] [($r?$y:$x)-1]=[R];$y+=$s*($R<0?0:1);$R+=$V+$V-($R<0?0:2*$c)}}for my$V(1,0){$m= $R{m}||0;@r=(0,0);@s=my@u=@p=();@n=sort{$b<=>$a}map$o[$_]-$m[$_],0,1;@n=($n[0])x 2;my@G=([split"",$R{S}||"L"],map([],2..$r),\@u);while(map@$_,@G){my$i=@G-1;$i-- while$i&&!@{$G[$i]};push@{$G[$i+1]},map{split""}map$R{$_}||$_,shift@{$G[$i]};for (@u){$f{$_}->()if$f{$_};if($V){for(0,1){$m[$_]=$r[$_]if$m[$_]>$r[$_];$o[$_]=$r [$_]if$r[$_]>$o[$_]}$t+=@p;@p=()}@p=map{2+$x*($p[$_]-$m[$_&1])/$n[$_&1]}0..@p-1; while(@p){l 0,splice@p,0,4;$h+=4/$t}}@u=()}}$s&&eval"MainLoop";if($R{b}){print map{chr}map@$_,map@$_,@$n;exit}print(map((grep$_,@$_)&&"*"||" ",@$_),$/)for@$n