<> <> <> <> 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]; <> <> 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[]; <> FOR i:INT IN [FirstBlack .. NumWalls) DO TRUSTED {DrawWall[W[i]]} ENDLOOP; <> 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.