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;
BEGIN
REAL dx = ABS (x OF stop - x OF start);
REAL dy
REAL err;
IF x OF start > x OF stop THEN
FI;
IF y OF start > y OF stop THEN
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 +:=
err +:= dx
FI;
x OF here +:=
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 +:=
err +:= dy
FI;
y OF here +:=
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;
(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)
Output:
<pre>
|