Hi Alex,

On Tue 07 Apr 2026 at 12:28, Alexander Burger <[email protected]> wrote:
> It is based on the new PicoLisp frame buffer library, also separately
> available in
>
>    https://software-lab.de/fb.tgz

that line drawing code in fb.tgz/lib.c seems quite complicated.

Here is what I did in forth:

variable x  variable y
variable x2  variable y2  variable dx  variable dy
variable sx  variable sy  variable e
: line
  x2 @ x @ - abs dx !
  x @ x2 @ < if 1 else -1 then sx !
  y2 @ y @ - abs negate dy !
  y @ y2 @ < if 1 else -1 then sy !
  dx @ dy @ + e !
  begin
    plot
    e @ 2* dy @ >= if
      x @ x2 @ = if exit then
      dy @ e +!
      sx @ x +!
    else e @ 2* dx @ <= if
      y @ y2 @ = if exit then
      dx @ e +!
      sy @ y +!
    then then
  again ;

(tested), which could be written in C as (not tested):

void line(int x, int y, int x2, int y2) {
  int dx = abs(x2 - x);
  int sx = x < x2 ? 1 : -1;
  int dy = -abs(y2 - y);
  int sy = y < y2 ? 1 : -1;
  int e = dx + dy;
  for(;;) {
    point(x, y);
    if((dy << 1) <= e) {
      if(x == x2) break;
      e += dy;
      x += sx;
    }
    else if((dy << 1) <= e) {
      if(y == y2) break;
      e += dx;
      y += sy;
    }
  }
}

Cheers,

Tomas

-- 
Fridays for Functions: 9:00-17:00 UTC
on Jitsi https://meeting.itship.ch/picolisp

UNSUBSCRIBE: mailto:[email protected]?subject=Unsubscribe

Reply via email to