# Glimmr Drawing Commands

## version 2/101030 by Erik Temple

Chapter - Lines

Section - Basic line
[The code for drawing a line between any two points was ported from the GREX module of the GWindows system by L. Ross Raszewski (http://gwindows.trenchcoatsoft.com). The code is there indicated to having been based on code by Paul Heckbert.]

To linedraw (hue - a number) in (win - a g-window) from (x1 - a number) by/x (y1 - a number) to (x2 - a number) by/x (y2 - a number) with (wgt - a number):
let dd be x2 - x1;
let ax be a number;
let ay be a number;
let sx be a number;
let sy be a number;
if dd >= 0:
let ax be 2 times dd;
let sx be 1;
otherwise:
let ax be -2 times dd;
let sx be -1;
let dd be y2 - y1;
if dd >= 0:
let ay be 2 times dd;
let sy be 1;
otherwise:
let ay be -2 times dd;
let sy be -1;
let x be x1;
let y be y1;
if ax > ay:
let x1 be 1;
let d be ay - (ax / 2);
while x is not x2:
if d >= 0:
let y be y + sy;
let d be d - ax;
let x be x plus sx;
let d be d plus ay;
if x is x2 or y is not y1:
if sx > 0:
dimrectdraw (hue) in win at (x - x1) by y1 with size x1 by wgt;
otherwise:
dimrectdraw (hue) in win at x by y1 with size x1 by wgt;
let y1 be y;
let x1 be 1;
otherwise:
increase x1 by 1;
otherwise:
let y1 be 1;
let d be ax - (ay / 2);
while y is not y2:
if d >= 0:
let x be x + sx;
let d be d - ay;
let y be y + sy;
let d be d + ax;
if x is not x1 or y is y2:
if sy > 0:
dimrectdraw (hue) in win at x1 by (y - y1) with size wgt by y1;
otherwise:
dimrectdraw (hue) in win at x1 by y with size wgt by y1;
let y1 be 1;
let x1 be x;
otherwise:
increase y1 by 1;

To draw a/-- line (hue - a number) in (win - a g-window) from (x1 - a number) by/x (y1 - a number) to (x2 - a number) by/x (y2 - a number) with (wgt - a number) pixel/pixels/px/-- line-weight/stroke:
#if utilizing Glimmr debugging;
say "[>console][DC]Drawing a line of color [hue] in [i][win][/i] from ([x1], [y1]) to ([x2], [y2]), line-weight [wgt] pixels.[<]";
#end if;
linedraw (hue) in (win) from (x1) by (y1) to (x2) by (y2) with (wgt).

To draw a/-- line (hue - a number) in (win - a g-window) from (coord1 - a list of numbers) to (coord2 - a list of numbers) with (wgt - a number) pixel/pixels/px/-- line-weight/stroke:
let x1 be entry 1 of coord1;
let y1 be entry 2 of coord1;
let x2 be entry 1 of coord2;
let y2 be entry 2 of coord2;
Draw a line (hue) in win from x1 by y1 to x2 by y2 with wgt pixel line-weight.

To line (coord1 - a list of numbers) to (coord2 - a list of numbers) at (wgt - a number) px/pixel/pixels:
if the type of the current graphics window is not g-graphics:
say "*** Error: Short-form line-drawing directive ignored. The current graphics window global was not correctly specified.";
rule fails;
let x1 be entry 1 of coord1;
let y1 be entry 2 of coord1;
let x2 be entry 1 of coord2;
let y2 be entry 2 of coord2;
Draw a line (current foreground-color) in current graphics window from x1 by y1 to x2 by y2 with wgt pixel line-weight.