--m.stone October 2, 1980 12:36 PM
DIRECTORY
GraphicsDefs: FROM "GraphicsDefs",
Real: FROM "Real",
RealFns: FROM "RealFns",
IODefs: FROM "IODefs",
ImageDefs: FROM "ImageDefs" USING [StopMesa],
StreamDefs: FROM "StreamDefs";

Wedges: PROGRAM IMPORTS GraphicsDefs, ImageDefs, StreamDefs, RealFns, Real, IODefs =
BEGIN
Screen: POINTER TO GraphicsDefs.Bitmap ←
GraphicsDefs.TurnOnGraphics[8,FALSE,80];
MonitorControlBlock: POINTER TO POINTER = LOOPHOLE[417B];
keys: StreamDefs.KeyboardHandle ← StreamDefs.GetDefaultKey[];

SetColor: PROCEDURE [gray,red,green,blue: CARDINAL] =
BEGIN
GraphicsDefs.SetRed[gray,red];
GraphicsDefs.SetGreen[gray,green];
GraphicsDefs.SetBlue[gray,blue];
END;

twoToThe: PROCEDURE [n: CARDINAL] RETURNS [twoToTheN: CARDINAL] = INLINE
BEGIN
twoToTheN ← SELECT n FROM 0=>1,1=>2,2=>4,3=>8,4=>16,5=>32,6=>64,7=>128,ENDCASE=>256;
END;

Main: PROCEDURE =
BEGIN
white,n: CARDINAL;
nsteps: CARDINAL = 16;
base: REAL ← 2;
value: REAL;
bwidth: CARDINAL ← 32;
width: CARDINAL ← (nsteps)*bwidth;
leftX: CARDINAL ← (606-width)/2;
lx,ty,h,x,v: CARDINAL;
base ← RealFns.SqRt[base];--2↑1/2
ClearScreen[];
--make the colormap [1-16] logrithmic grey
value ← base;
FOR x IN [1..
16] DO
v ← Real.RoundI[value];
IF v=256 THEN v ← 255;
SetColor[x,v,v,v];
IODefs.WriteDecimal[v];
IODefs.WriteChar[’ ];
value ← value*base;
ENDLOOP;
IODefs.WriteLine[" "];
--make the colormap [17..32] compensated logrithmic grey
value ← base;
FOR x IN [17..32] DO
v ← Real.RoundI[Comp[value]];
SetColor[x,v,v,v];
IODefs.WriteDecimal[v];
IODefs.WriteChar[’ ];
value ← value*base;
ENDLOOP;
IODefs.WriteLine[" "];
--make the colormap [33-48] linear grey
v ← 15;
FOR x IN [33..48] DO
SetColor[x,v,v,v];
IODefs.WriteDecimal[v];
IODefs.WriteChar[’ ];
v ← v+16;
ENDLOOP;
IODefs.WriteLine[" "];
--make the colormap [49..64] compensated linear grey
v ← 15;
FOR x IN [49..64] DO
n ← Real.RoundI[Comp[v]];
SetColor[x,n,n,n];
IODefs.WriteDecimal[n];
IODefs.WriteChar[’ ];
v ← v+16;
ENDLOOP;
IODefs.WriteLine[" "];
--draw the log grey scale
lx ← leftX; ty ← 32; h ← 128;
FOR x IN [1..16] DO
GraphicsDefs.SetGrayLevel[x];
GraphicsDefs.ReplaceGray[lx,ty,lx+bwidth,ty+h];
lx ← lx+bwidth;
ENDLOOP;
lx ← leftX; ty ← ty+h+16; h ← 128;
--draw the compensated log grey scale
FOR x IN [17..32] DO
GraphicsDefs.SetGrayLevel[x];
GraphicsDefs.ReplaceGray[lx,ty,lx+bwidth,ty+h];
lx ← lx+bwidth;
ENDLOOP;
--draw the linear grey scale
lx ← leftX; ty ← ty+h+32; h ← 128;
FOR x IN [33..48] DO
GraphicsDefs.SetGrayLevel[x];
GraphicsDefs.ReplaceGray[lx,ty,lx+bwidth,ty+h];
lx ← lx+bwidth;
ENDLOOP;
lx ← leftX; ty ← ty+h+16; h ← 128;
FOR x IN [49..64] DO
GraphicsDefs.SetGrayLevel[x];
GraphicsDefs.ReplaceGray[lx,ty,lx+bwidth,ty+h];
lx ← lx+bwidth;
ENDLOOP;
white ← 255;
SetColor[white,255,255,255];
SetColor[white-1,254,254,254];
ty ← ty+h+32; h ← 64;
GraphicsDefs.SetGrayLevel[white];
GraphicsDefs.SetHalfTone[0,white,125B];
--hope for a screened half gray
GraphicsDefs.ReplaceGray[leftX,ty,leftX+width,ty+h];
END;

WaitAWhile: PROCEDURE[millisecs: CARDINAL] =
BEGIN
i,j: CARDINAL;
FOR i IN [0..millisecs] DO
FOR j IN [0..2000] DO ENDLOOP;
ENDLOOP;
END;

background: CARDINAL ← 0;
ClearScreen: PROCEDURE =
BEGIN
SetColor[0,background,background,background];
GraphicsDefs.EraseArea[0,0,Screen.nBits,Screen.nLines];
END;

level: INTEGER ← 128;
screen: CARDINAL ← 125B;
Blocks: PROCEDURE =
BEGIN
lx,ty: CARDINAL;
white: CARDINAL ← (IF level#255 THEN 255 ELSE 254);
v: INTEGER ← Real.RoundI[Comp[level]];
ClearScreen[];
SetColor[level,v,v,v];
SetColor[
1,0,0,0];
SetColor[white,
255,255,255];
lx ← 100; ty ← 120;
GraphicsDefs.SetGrayLevel[
level];
GraphicsDefs.ReplaceGray[lx,ty,lx+200,ty+300];
lx ← lx+200;
GraphicsDefs.SetGrayLevel[white];
GraphicsDefs.SetHalfTone[1,white,screen];
-- a screened half gray
GraphicsDefs.ReplaceGray[lx,ty,lx+200,ty+300];
END;

gamma: REAL ← 1.0/2.3;
Comp: PROCEDURE[intensity: REAL] RETURNS[REAL] =
BEGIN
intensity ← intensity/255;
intensity ← RealFns.Power[intensity,gamma];
RETURN[intensity*255];
END;

WaitAWhile[40];
Real.InitReals[];
ClearScreen[];
Main[];
DO
IF NOT keys.endof[keys] THEN
BEGIN
new: STRING ← [40];
endline: PROCEDURE[c: CHARACTER] RETURNS[BOOLEAN]=BEGIN
RETURN[c=IODefs.CR];
END;
ch: CHARACTER ← keys.get[keys];
IODefs.WriteChar[ch];
IODefs.WriteChar[’ ];
IF ch = ’q THEN
BEGIN
MonitorControlBlock↑ ← NIL;
WaitAWhile[500];
ImageDefs.StopMesa[];
END;
IF ch = ’w THEN Main[];
IF ch = ’c THEN background ← IODefs.ReadDecimal[];
IF ch = ’e THEN ClearScreen[];
IF ch = ’b THEN Blocks[];
IF ch = ’s THEN screen ← IODefs.ReadOctal[];
IF ch = ’l THEN level ← IODefs.ReadDecimal[];
IF ch = ’g THEN BEGIN
IODefs.ReadString[new,endline];
gamma ← 1/Real.StringToReal[new];
END;
END;
ENDLOOP;

END.