ImagerTest.mesa
Michael Plass, August 3, 1983 10:07 am
DIRECTORY
Imager,
ImagerBasic,
ImagerColor,
ImagerTransform,
LFUtil,
Rope,
UnifiedFonts;
ImagerTest: CEDAR PROGRAM
IMPORTS Imager, ImagerColor, ImagerTransform, UnifiedFonts, LFUtil
= BEGIN
Pair: TYPE ~ Imager.Pair;
Context: TYPE ~ Imager.Context;
Path: TYPE ~ Imager.Path;
mercuryPath: Path ← NEW[ImagerBasic.PathRep ← [
generateProc: MercuryProc,
data: NIL
]];
MercuryProc: PROC [path: Path, move: PROC [Pair], line: PROC [Pair], curve: PROC [Pair, Pair, Pair]] = {
Move: PROC [x, y: REAL] ~ INLINE {move[[x, y]]};
Curve: PROC [a,b,c,d,e,f: REAL] ~ INLINE {curve[[a, b], [c, d], [e, f]]};
Move[192.0, 413.353];
Curve[237.5415, 425.809, 255.3458, 401.7666, 288.0, 399.5085];
Curve[297.9937, 398.8174, 308.0844, 403.6591, 318.0, 404.5501];
Curve[331.9086, 405.7998, 448.1434, 401.3464, 450.8684, 396.0001];
Curve[453.3393, 391.1521, 435.2951, 383.4805, 431.9999, 383.0218];
Curve[428.5259, 382.538, 410.233, 382.6307, 409.5, 378.0];
Curve[409.8045, 379.9238, 421.3876, 370.5168, 402.0001, 363.6874];
Curve[386.3301, 358.1678, 345.4535, 362.3779, 345.5, 359.9999];
Curve[345.4942, 360.2959, 368.3762, 359.2238, 372.0, 358.0435];
Curve[389.1935, 352.4433, 364.4147, 343.7253, 364.875, 336.0];
Curve[365.5193, 325.1856, 382.3762, 294.0994, 390.0, 285.675];
Curve[408.286, 265.4687, 417.344, 272.0564, 438.0001, 263.8696];
Curve[454.6547, 257.2686, 417.2523, 242.3468, 408.0, 243.5193];
Curve[383.1711, 246.6655, 383.3985, 232.3274, 366.0, 219.439];
Curve[352.0869, 209.1325, 366.6143, 208.1149, 372.0, 208.9024];
Curve[374.2727, 209.2348, 386.2989, 214.7218, 380.8284, 204.0];
Curve[378.6221, 199.6753, 364.5704, 185.5353, 360.0, 184.8125];
Curve[351.8828, 183.5287, 332.7219, 196.0891, 329.1539, 192.0];
Curve[321.1773, 182.8585, 343.6019, 183.1676, 340.0227, 174.0];
Curve[335.0409, 161.2398, 311.5035, 158.2857, 310.4737, 126.0];
Curve[310.1649, 116.3195, 313.5754, 76.22575, 312.75, 72.0];
Curve[310.7936, 61.98325, 261.8854, 53.60412, 252.0, 52.62712];
Curve[238.5165, 51.29451, 155.6176, 53.91593, 152.55, 65.99998];
Curve[146.1258, 91.30679, 146.1964, 75.57425, 114.0, 83.08163];
Curve[101.5249, 85.9905, 85.49357, 98.83845, 93.0, 114.0];
Curve[96.9852, 122.0493, 101.4202, 118.0211, 96.0, 128.775];
Curve[92.91811, 134.8897, 92.05819, 140.964, 90.00001, 147.577];
Curve[85.48869, 162.0718, 88.40478, 162.2188, 86.83928, 168.0];
Curve[84.31547, 177.3202, 68.65387, 174.0181, 70.27779, 186.0];
Curve[71.84946, 197.5966, 93.93316, 251.462, 87.75, 258.0];
Curve[83.8855, 262.0863, 74.20536, 262.4716, 73.98215, 270.0];
Curve[73.80345, 276.027, 80.97349, 281.9097, 79.26, 288.0];
Curve[76.91487, 296.3353, 44.77308, 305.2533, 60.08572, 324.0];
Curve[64.14451, 328.969, 78.96831, 335.1704, 67.77274, 342.0];
Curve[60.79922, 346.254, -5.558746, 358.62, 30.00002, 372.3488];
Curve[45.19923, 378.2171, 84.23178, 361.5336, 114.0, 376.1087];
Curve[140.1327, 388.9037, 163.6664, 405.2124, 192.0, 413.3529];
};
CrossHatch: PROC [context: Context, area: ImagerBasic.IntRectangle] ~ TRUSTED {
crossHatch: ARRAY [0..8) OF CARDINAL ← [
8080h,
4040h,
2020h,
1010h,
0808h,
0404h,
0202h,
0101h
];
context.MaskBits[base: @crossHatch, area: area, tile: [0, 0, 16, 8], raster: 1];
};
dx, dy: REAL ← 438.0/2;
dTheta: REAL ← 1.0;
SpinMerc: PROC [context: Context, n: INT] = {
buffer: Context ← Imager.CreateBuffer[$LFDisplay, [0, 0, 200, 200]];
rotation: REAL ← 0;
MaskMerc: PROC ~ {
buffer.SetColor[Imager.white];
buffer.MaskIntRectangle[[-400,-400,800,800]];
buffer.TranslateT[100, 100];
buffer.RotateT[rotation];
buffer.ScaleT[200.0/438, 200.0/438];
buffer.TranslateT[-dx, -dy];
buffer.SetColor[Imager.black];
buffer.MaskFill[mercuryPath];
};
FOR i: INT IN [0..n) DO
buffer.DoSave[MaskMerc];
context.TransferBuffer[buffer];
rotation ← rotation + dTheta;
ENDLOOP;
};
SpinText: PROC [context: Context, text: Rope.ROPE, n: INT] = {
buffer: Context ← Imager.CreateBuffer[$LFDisplay, [0, 0, 200, 200]];
save: Context ← Imager.CreateBuffer[$LFDisplay, [0, 0, 200, 200]];
transform: ImagerBasic.Transformation ← ImagerTransform.Scale[textSize, textSize];
font: UnifiedFonts.FONT ← UnifiedFonts.Create[fontName, transform, $Ideal];
textWidth: REAL ← font.TextWidth[text];
rotation: REAL ← 0;
MaskText: PROC ~ {
buffer.TransferBuffer[save];
buffer.TranslateT[100, 100];
buffer.RotateT[rotation];
buffer.TranslateT[0, -textSize/3];
buffer.SetCP[[-textWidth/2, 0]];
buffer.MaskCharacters[font, text];
};
save.TransferBuffer[context];
FOR i: INT IN [0..n) DO
buffer.DoSave[MaskText];
context.TransferBuffer[buffer];
rotation ← rotation + dTheta;
ENDLOOP;
context.TransferBuffer[save];
};
SpinMonk: PROC [context: Context, n: INT] = {
buffers: ARRAY [0..60) OF Context;
color: ImagerBasic.SampledColor ← NARROW[ImagerColor.AISToColor["monk.ais"]];
FOR i: INT IN [0..n) DO
FOR r: INT IN [0..60) DO
IF buffers[r] = NIL THEN {
buffers[r] ← Imager.CreateBuffer[$LFDisplay, [235, 535, 223, 239]];
color.m ← ImagerTransform.Concat[ImagerTransform.Concat[ImagerTransform.Translate[-346,-654],ImagerTransform.Rotate[r*6]],ImagerTransform.Translate[346,654]];
buffers[r].SetColor[color];
buffers[r].MaskIntRectangle[[235, 535, 223, 239]];
};
context.TransferBuffer[buffers[r]];
ENDLOOP;
ENDLOOP;
IF n > 0 THEN context.TransferBuffer[buffers[0]];
};
RotMerc1: PROC [context: Context] = {
gray: Imager.Color ← ImagerColor.MakeGray[0.5];
{action: PROC = {
context.TranslateT[4.25*72, 5.5*72];
context.ScaleT[0.333, 0.333];
context.MaskFill[mercuryPath];
FOR i:NAT IN [0..9) DO
context.SetColor[gray];
context.RotateT[-10];
context.MaskFill[mercuryPath];
context.SetColor[Imager.black];
context.RotateT[-10];
context.MaskFill[mercuryPath];
ENDLOOP;
}; context.DoSave[action]};
};
RotMerc: PROC [context: Context] = {
gray: Imager.Color ← ImagerColor.MakeGray[0.5];
context.TranslateT[4.25*72, 5.5*72];
context.ScaleT[0.333, 0.333];
{action: PROC = {
context.SetColor[Imager.black];
context.MaskFill[mercuryPath];
FOR i: NAT ← 0, i+2 WHILE i<9 DO
context.SetColor[gray];
context.RotateT[-20];
context.MaskFill[mercuryPath];
context.SetColor[Imager.black];
context.RotateT[-20];
context.MaskFill[mercuryPath];
ENDLOOP;
}; context.DoSave[action]};
{action: PROC = {
FOR i: NAT IN [0..2) DO
context.ClipPath[mercuryPath, TRUE];
context.RotateT[-20];
ENDLOOP;
context.RotateT[-160];
FOR i: NAT ← 10, i+2 WHILE i<18 DO
context.SetColor[gray];
context.RotateT[-20];
context.MaskFill[mercuryPath];
context.SetColor[Imager.black];
context.RotateT[-20];
context.MaskFill[mercuryPath];
ENDLOOP;
}; context.DoSave[action]};
};
textSize: REAL ← 12.0;
Times: PROC [size: REAL] RETURNS [UnifiedFonts.FONT] ~ {
transform: ImagerBasic.Transformation ← ImagerTransform.Scale[size, size];
RETURN [UnifiedFonts.Create["Xerox/PressFonts/TimesRoman/MRR", transform, $Ideal]]
};
fontName: Rope.ROPE ← "Xerox/PressFonts/TimesRoman/MRR";
MaskTxt: PROC[context: Context, ropes: LIST OF REF] = {
transform: ImagerBasic.Transformation ← ImagerTransform.Scale[textSize, textSize];
row: INT ← 0;
font: UnifiedFonts.FONT ← UnifiedFonts.Create[fontName, transform, $Ideal];
{action: PROC = {
context.TranslateT[72, 720];
FOR list: LIST OF REF ← ropes, list.rest UNTIL list=NIL DO
row ← row + 1;
context.SetCP[[0, -row * textSize]];
context.MaskCharacters[font, list.first];
ENDLOOP;
}; context.DoSave[action]};
};
MaskText: PROC[context: Context, ropes: LIST OF REF] = {
transform: ImagerBasic.Transformation ← ImagerTransform.Scale[textSize, textSize];
curfont: UnifiedFonts.FONT ← UnifiedFonts.Create["Xerox/PressFonts/TimesRoman/MRR", transform, $Ideal];
altfont: UnifiedFonts.FONT ← UnifiedFonts.Create["Xerox/PressFonts/Helvetica/MRR", transform, $Ideal];
row: INT ← 0;
{action: PROC = {
context.TranslateT[72, 720];
FOR list: LIST OF REF ← ropes, list.rest UNTIL list=NIL DO
tempfont: UnifiedFonts.FONT ~ curfont;
row ← row + 1;
context.SetCP[[0, -row * textSize]];
context.MaskCharacters[tempfont, list.first];
curfont ← altfont; altfont ← tempfont;
ENDLOOP;
}; context.DoSave[action]};
};
Text: PROC RETURNS [ropes: LIST OF REF] = {
new: LIST OF REFNIL;
txt: LIST OF Rope.ROPE ← text;
WHILE txt # NIL DO new ← CONS[txt.first, new]; txt ← txt.rest ENDLOOP;
WHILE new # NIL DO tt: LIST OF REF ← new; new ← new.rest; tt.rest ← ropes; ropes ← tt ENDLOOP;
};
text: LIST OF Rope.ROPELIST["In olden times when wishing still", "helped one, there lived a king", "whose daughters were all", "beautiful, but the youngest was", "so beautiful that the sun itself,", "which has seen so much, was", "astonished whenever it shone in", "her face. Close by the king's", "castle lay a great dark forest,", "and under an old lime-tree in", "the forest was a well, and when", "the day was very warm, the", "king's child went out into the", "forest and sat down by the side", "of the cool fountain, and when", "she was bored she took a golden", "ball, and threw it up on high", "and caught it, and this ball was", "her favorite plaything."];
Msr: PROC [context: Context] RETURNS [worked: BOOLEAN] = {
sMin, fMin, sSize, fSize, sMinDest, fMinDest: INTEGER;
[sMin, fMin, sSize, fSize] ← LFUtil.GetArea[];
[sMin: sMinDest, fMin: fMinDest] ← LFUtil.GetArea[];
worked ← Imager.MoveSurfaceRectangle[context, [fMin, 808-sMin-sSize, fSize, sSize], [fMinDest, 808-sMinDest-sSize]];
};
END.