Bitmap/Bresenham's line algorithm: Difference between revisions

Content deleted Content added
m →‎[[Bresenham's_line_algorithm#ALGOL 68]]: '''pragmat''' '''read''' "filename" is an extension
m →‎[[Bresenham's line algorithm#ALGOL 68]]: virtualise member, and tidy code
Line 82:
{{works with|ALGOL 68G|Any - tested with release mk15-0.8b.fc9.i386}}
<!-- {{does not work with|ELLA ALGOL 68|Any (with appropriate job cards) - tested with release 1.8.8d.fc9.i386 - '''pragmat''' '''read''' is not part of algol68rs}} -->
 
<lang algol>PRAGMAT READ "Basic_bitmap_storage.a68" PRAGMAT;
PROC line OF class image := (REF IMAGE picture, POINT start, stop, PIXEL color)VOID:
BEGIN
REAL dx = ABS (x OF stop - x OF start);
REAL dy = ABS (y OF stop - y OF start);
REAL err;
INTPOINT xhere := x OF start;
INTPOINT ystep := y(1, OF start1);
INT step x := 1;
INT step y := 1;
IF x OF start > x OF stop THEN
step x OF step := -1
FI;
IF y OF start > y OF stop THEN
step y OF step := -1
FI;
IF dx > dy THEN
err := dx / 2;
WHILE x OF here /= x OF stop DO
picture[x OF here, y OF here] := color;
err -:= dy;
IF err < 0 THEN
y OF here +:= step y OF step;
err +:= dx
FI;
x OF here +:= step x OF step
OD
ELSE
err := dy / 2;
WHILE y OF here /= y OF stop DO
picture[x OF here, y OF here] := color;
err := err - dx;
IF err < 0 THEN
x OF here +:= step x OF step;
err +:= dy
FI;
y OF here +:= step y OF step
OD
FI;
picture[x OF here, y OF here] := color # ensure dots to be drawn #
END # line #;
 
IF test THEN
###
the test program's
###
REF IMAGE x = INIT LOC[1:16, 1:16]PIXEL;
BEGIN
(fill OF class image)(x, white OF class image);
(line OF class image)(x, ( 1, 8), ( 8,16), black OF class image);
(line OF class image)(x, ( 8,16), (16, 8), black OF class image);
(line OF class image)(x, (16, 8), ( 8, 1), black OF class image);
(line OF class image)(x, ( 8, 1), ( 1, 8), black OF class image);
(print OF class image)(x)
ENDFI</lang>
Output:
<pre>