ASCII art Bresenham line drawing
Perl, 74
/ /;print int(.5+$_*$'/$`)>int(.5+--$_*$'/$`)?$/.$"x$_.'\\':'_'for 1..$`
Run with -n
option (counted in code size).
$ perl -n bresenham.pl <<<'11 3'
_
\___
\___
\_
$ perl -n bresenham.pl <<<'11 1'
_____
\_____
$ perl -n bresenham.pl <<<'5 4'
\
\_
\
\
$ perl -n bresenham.pl <<<'10 1'
____
\_____
C 136 123 Characters
z,x,y,i,f;main(){for(scanf("%d%d",&x,&y);i<=x;i++){f=f?printf("_"):1;z+=y;if(2*z>=x&&i<x)f=0,z-=x,printf("\n%*c",i+1,92);}}
Delphi, 109 bytes
Quite small if you ask me :
var x,y,i:Word;begin Read(x,y);for i:=1to(x)do if(i*y+x div 2)mod x<y then Write(^J,'\':i)else Write('_')end.
The 2 integers are read from the command line.
The newline is written by the seldomly used ^J
syntax (meaning LineFeed), the following '\
' character is indented using the little-known syntax :Write(string:width)
.
It's a pitty Delphi div
for integer-divide (instead of just \
). Ah well...