[Oberon] FPGA - Simple Graph Line
Jörg
joerg.straube at iaeth.ch
Thu Nov 22 12:39:41 CET 2018
Hi Tomas
I would discriminate the special case of horizontal/vertical lines...
And try to optimize your IF ELSIF structure..
Jörg
-----Original Message-----
From: Oberon <oberon-bounces at lists.inf.ethz.ch> On Behalf Of Tomas Kral
Sent: Thursday, November 22, 2018 11:56 AM
To: oberon at lists.inf.ethz.ch
Subject: [Oberon] FPGA - Simple Graph Line
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>
--
Oberon at lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon
More information about the Oberon
mailing list