# [Oberon] FPGA - Simple Graph Line

Tomas Kral thomas.kral at email.cz
Thu Nov 22 11:56:27 CET 2018

```On Sat, 10 Nov 2018 10:25:31 +0100
Jörg <joerg.straube at iaeth.ch> wrote:

> I added a small optimization by drawing the line

Hi,
Talking about line drawing, I tried to parameterise the line algo
below. I am surprised it takes more coding than circle.

PROCEDURE Line*(col, x, y, x0, y0: INTEGER);
VAR w, h, x1, y1, d, u: INTEGER;
BEGIN
w := x0-x; h := y0-y;
IF (w >= 0) & (h >= 0) THEN (*north-east*) d := 1
ELSIF (w < 0) & (h >= 0) THEN (*north-west*) d := -1; u := x0; x0 := x; x := u
ELSIF (w >= 0) & (h < 0) THEN (*south-east*) d := -1; u := y0; y0 := y; y := u
ELSIF (w < 0) & (h < 0) THEN (*south-west*) d := 1; u := x0; x0 := x; x := u; u := y0; y0 := y; y := u
END ; w := ABS(w); h := ABS(h);
IF h < w THEN
x1 := x+w; u := (h-w) DIV 2;
IF d = -1 THEN INC(y, h) END ;
WHILE x < x1 DO
D.Dot(col, x, y, D.replace); INC(x);
IF u < 0 THEN INC(u, h) ELSE INC(u, h-w); INC(y, d) END
END
ELSE y1 := y+h; u := (w-h) DIV 2;
IF d = -1 THEN INC(x, w) END ;
WHILE y < y1 DO
D.Dot(col, x, y, D.replace); INC(y);
IF u < 0 THEN INC(u, w) ELSE INC(u, w-h); INC(x, d) END
END
END
END Line;

--
Tomas Kral <thomas.kral at email.cz>
```