file: MazeGraphicsImpl.mesa
stolen from Greg Nelson's code by Lyle Ramshaw, to fill in a template that was
Pascal-to-Mesa translator output, translated at 18-Apr-83 22:36:31 PST
Last Edited by: Ramshaw, April 20, 1983 3:59 pm
DIRECTORY
Graphics,
GraphicsToPress,
MazePrivate;
MazeGraphicsImpl: CEDAR PROGRAM IMPORTS Graphics, GraphicsToPress, MazePrivate EXPORTS MazePrivate = PUBLIC
BEGIN OPEN MazePrivate;
gc: Graphics.Context;
p: Graphics.Path;
wl: INT ~ 10;
ww: INT ~ 1;
scaleFactor: REAL ~ wl - ww;
strokeWidth: REAL ~ ww / scaleFactor;
InitGc: PROC ~
{TRUSTED {gc ← GraphicsToPress.NewContext["maze.press"]};
p ← Graphics.NewPath[];
Graphics.Translate[gc, 72, 72];
The translate call makes the southwest corner of the maze come out one inch right and
one inch up from the southwest corner of the page
Graphics.Scale[gc, scaleFactor, scaleFactor]};
DrawWall: PROC [w: Wall] ~
{x1, x2, y1, y2: INT;
SELECT TRUE FROM
w.Ns =>
{x1 ← w.X;
x2 ← w.X;
y1 ← w.Y - 1;
y2 ← w.Y};
w.Ew =>
{x1 ← w.X - 1;
x2 ← w.X;
y1 ← w.Y;
y2 ← w.Y};
ENDCASE => ERROR;
Graphics.MoveTo[p, x1, y1];
Graphics.LineTo[p, x2, y2];
Graphics.DrawStroke[gc, p, strokeWidth, FALSE, square]};
DrawMaze: PROC ~
{InitGc[];
draw the interior walls:
FOR i:INT IN [FirstBlack .. NumWalls) DO
TRUSTED {DrawWall[W[i]]} ENDLOOP;
draw the exterior walls:
Graphics.MoveTo[p, 0, N];    -- northwest
Graphics.LineTo [p, 0, 0];    -- southwest
Graphics.MoveTo[p, 0, 0, FALSE]; -- empty step to placate Cedar Graphics
Graphics.LineTo [p, (M - 1), 0];   -- southeast exit, left
Graphics.DrawStroke[gc, p, strokeWidth, FALSE, square];
Graphics.MoveTo[p, M, 0];    -- southeast
Graphics.LineTo [p, M, N];   -- northeast
Graphics.MoveTo[p, M, N, FALSE]; -- another empty step
Graphics.LineTo [p, 1, N];    -- northwest exit, right
Graphics.DrawStroke[gc, p, strokeWidth, FALSE, square] ;
TRUSTED {GraphicsToPress.Close[gc]}};
END.