http://www.perlmonks.org?node_id=288144

Not terribly good ASCII art, but another fun principle that I don't think I've seen used before (though I'm sure I'll be corrected if wrong :)). All analysis and suggestions for improvement / golfing most welcome.
for(2424832,201326592,203754496,2427941,50987779,117900295,151259139, 134613253,51317003,152306448,101778958,152371989,51905302,68813593,688 +14358, 152896285,102827550,153223970){($x,$y,$v,$w)=unpack"c*",pack"l",$_;$e= +$v-$x; $g=$w-$y;$h=abs$e;$k=abs$g;$d=$h>$k;for(0..(($d)?$h:$k)){$f+=$d?$g/$e: +$e/$g; $f1=$f;int$f&&do{$y+=$d?$g>0?1:-1:0;$x+=$d?0:$e>0?1:-1;$f+=$f>0?-1:1}; $c[$y]||=' 'x 60;substr($c[$y],$x+1,1)=abs$f1>=1?$f1>0?"\\":"/":$d?"-" +:"|"; $d?($x+=$e>0?1:-1):($y+=$g>0?1:-1);}};$"="\n";print"@c";
Cheers, Ben.

update Removed all those brackets left over from starting life as a C coder :)
update Stripped a few spare vars etc.

Replies are listed 'Best First'.
Re: LineDraw Japh
by Roger (Parson) on Sep 04, 2003 at 05:32 UTC
    The straight line drawing algorithm. Each number in the list holds information of x,y coordinates and gradient information. The format is x1,y1,x2,y2. I have modified this program to draw a little house ... :-D

    for (589840,117506056,134225920,671555840,534280,1058576,654911248,151718157,269160461,168496907,168627981){($x,$y,$v,$w)=unpack"c*",pack"l",$_;$e=$v-$x;$g=$w-$y;$h=abs$e;$k=abs$g;$d=$h>$k;for(0..(($d)?$h:$k)){$f+=$d?$g/$e:$e/$g;$f1=$f;int$f&&do{$y+=$d?$g>0?1:-1:0;$x+=$d?0:$e>0?1:-1;$f+=$f>0?-1:1};$c$y||=' 'x 60;substr($c$y,$x+1,1)=abs$f1>=1?$f1>0?"\\":"/":$d?"-":"|"; $d?($x+=$e>0?1:-1):($y+=$g>0?1:-1);}};$"="\n";print"@c";
      Opps, the code I posted earlier confused the HTML syntax. Here's the complete code reposted...

      for (589840, 117506056, 134225920, 671555840, 534280, 1058576, 654911248, 151718157, 269160461, 168496907, 168627981) { ($x, $y, $v, $w) = unpack "c*", pack "l", $_; $e = $v - $x; $g = $w - $y; $h = abs $e; $k = abs $g; $d = $h > $k; for (0..(($d) ? $h : $k)) { $f += $d ? $g/$e : $e/$g; $f1 = $f; int $f && do { $y += $d ? ($g > 0 ? 1 : -1) : 0; $x += $d ? 0 : ($e > 0 ? 1 : -1); $f += $f > 0 ? -1 : 1 }; $c[$y] ||= ' ' x 60; substr($c[$y],$x+1,1) = abs $f1 >= 1 ? $f1 > 0 ? "\\" : "/" : $d ? "-" : "|"; $d ? ($x += $e>0 ? 1 : -1) : ($y += $g>0 ? 1 : -1); } } $" = "\n"; print"@c\n"; __END__ The following is the picture data in heximal format, Each number is x1,y1,x2,y2. 0x00090010, 0x07010008, 0x08002000, 0x28072100, 0x00082708, 0x00102710, 0x27092710, 0x090B090D, 0x100B100D, 0x0A0B0F0B, 0x0A0D0F0D