G2dWebCmdImpl.mesa
Copyright Ó 1985, 1992 by Xerox Corporation. All rights reserved.
Bloomenthal, July 20, 1992 1:09 pm PDT
Glassner, May 30, 1986 12:32:04 pm PDT
DIRECTORY Draw2d, Commander, Controls, G2dTool, Imager, IO, RealFns, Vector2;
G2dWebCmdImpl:
CEDAR
PROGRAM
IMPORTS Draw2d, Controls, G2dTool, RealFns
~ BEGIN
ProgramData: TYPE ~ REF ProgramDataRep;
ProgramDataRep:
TYPE ~
RECORD [
out: IO.STREAM ¬ NIL,
webNumLines: INT ¬ 0,
webPts: ARRAY [0..1000] OF Imager.VEC
];
G2dWeb: Commander.CommandProc ~ {
d: ProgramData ¬ NEW[ProgramDataRep];
d.out ¬ cmd.out;
MakeWeb[d];
[] ¬ Controls.OuterViewer[graphicsHeight: 300, drawProc: DrawProc, clientData: d];
};
MakeWeb:
PROC [d: ProgramData] ~ {
ngon: INT ¬ 25;
center: Imager.VEC ¬ [150.0, 150.0];
radius: REAL ¬ 150.0;
ptnum: INT ¬ 0;
dtor: REAL ¬ 2.0 * 3.14159;
FOR i:
INT
IN[0..ngon)
DO
FOR j:
INT
IN [i+1..ngon)
DO
theta: REAL ¬ (dtor * i) / (1.0 * ngon);
d.webPts[ptnum].x ¬ center.x + (radius * RealFns.Cos[theta]);
d.webPts[ptnum].y ¬ center.y + (radius * RealFns.Sin[theta]);
ptnum ¬ ptnum + 1;
theta ¬ (dtor * j) / (1.0 * ngon);
d.webPts[ptnum].x ¬ center.x + (radius * RealFns.Cos[theta]);
d.webPts[ptnum].y ¬ center.y + (radius * RealFns.Sin[theta]);
ptnum ¬ ptnum + 1;
d.webNumLines ¬ d.webNumLines + 1;
ENDLOOP;
ENDLOOP;
};
DrawProc: Controls.DrawProc ~ {
d: ProgramData ¬ NARROW[clientData];
FOR i:
INT
IN[0..d.webNumLines)
DO
j: INT ¬ i+i;
Draw2d.Line[context, d.webPts[j], d.webPts[j+1]];
ENDLOOP;
};
G2dTool.Register["Web", G2dWeb, "\nWeb."];