-- ColorKinetic.mesa -- Last edited by Doug Wyatt, 31-Mar-82 15:30:23 -- Pilot version DIRECTORY BitBlt, ColorDisplay, Inline, Keys USING [KeyBits], Process USING [MsecToTicks, Pause], UserTerminal USING[keyboard]; ColorKinetic: PROGRAM IMPORTS BitBlt, ColorDisplay, Inline, Process, UserTerminal = BEGIN keys: LONG POINTER TO Keys.KeyBits _ LOOPHOLE[UserTerminal.keyboard]; sym: BOOLEAN _ FALSE; bbspace: BitBlt.BBTableSpace; bb: BitBlt.BBptr _ InitBB[@bbspace]; grayword: CARDINAL _ 0; bitmap,bitmapB: LONG POINTER _ NIL; wpl,wplB: CARDINAL _ 0; width,height: CARDINAL _ 0; lbpp,lbppB: CARDINAL _ 0; -- log (base 2) bits per pixel bpp,bppB: CARDINAL _ 0; -- bits per pixel full: BOOLEAN _ FALSE; ashow,bshow: BOOLEAN _ TRUE; splat: BOOLEAN _ TRUE; test: BOOLEAN _ FALSE; neg: BOOLEAN _ FALSE; cornerSize: CARDINAL _ 4; cornerColor: CARDINAL _ 8; Triple: TYPE = RECORD[r,g,b: [0..256)]; testmap: ARRAY[0..8] OF Triple _ [ [127,127,127], -- gray (background) [ 0, 0, 0], -- black [255, 0, 0], -- red [ 0,255, 0], -- green [255,255, 0], -- yellow [ 0, 0,255], -- blue [255, 0,255], -- magenta [ 0,255,255], -- cyan [255,255,255] -- white ]; TestPattern: PROC = { x: CARDINAL = 60; h: CARDINAL = 60; w: CARDINAL = 50; gap: CARDINAL = 15; IF NOT full THEN { FOR i: CARDINAL IN[0..9) DO ColorDisplay.SetColor[pixelA: i, r: testmap[i].r, g: testmap[i].g, b: testmap[i].b]; ENDLOOP; ColorDisplay.Show[TRUE,FALSE,FALSE]; }; -- gray background Rect[0,0,width,height,0]; -- four corners { s: CARDINAL = cornerSize; c: CARDINAL = cornerColor; -- color Rect[0,0,s,s,c]; Rect[width-s,0,s,s,c]; Rect[0,height-s,s,s,c]; Rect[width-s,height-s,s,s,c]; }; -- various colors at left edge FOR i: CARDINAL IN[0..8) DO r,g,b: [0..256); r _ (i MOD 2)*255; g _ ((i/2) MOD 2)*255; b _ ((i/4) MOD 2)*255; Rect[4,i*h+10,x,h-20,i+1]; ENDLOOP; -- a bunch of stripes FOR i: CARDINAL IN[0..8) DO r,g,b: [0..256); r _ (i MOD 2)*255; g _ ((i/2) MOD 2)*255; b _ ((i/4) MOD 2)*255; Rect[x+i*w+gap,0,w-gap,8*h,i+1]; ENDLOOP; }; Rect: PROC[x,y,w,h: CARDINAL, i: [0..8]] = { IF NOT (x0, seed is scaled if necessary and then used; if seed<0, a seed --value is derived from the system clock. In any case, the seed value actually used --(after scaling) is the integer value returned. minSeed: CARDINAL = LAST[CARDINAL]/10; g, gPrev, gSave: CARDINAL; IF seed<=0 THEN seed _ defaultSeed; -- Now scale the seed into the proper range (no log routine available...) WHILE seed max THEN ERROR; intervalLen _ max - min + 1; --is 0 when min=0, max=LAST[CARDINAL] IF intervalLen = 0 THEN RETURN[Random[]]; DO -- Draw a number in [0..LAST[CARDINAL]]. We want to reject this number if it lies in the --"odd interval" at the high end of this range (there is no odd interval if intervalLen --divides 2^16). The funny test below does it (claim). The average number of numbers drawn --is less than 2, and much closer to 1 for small intervalLen. r, rem: CARDINAL; -- Inline expansion of Random[]; p _ p-1; IF p=0 THEN { RandomGen[]; p _ 55 }; r _ a[p]; rem _ r MOD intervalLen; IF (r - rem) > LOOPHOLE[-LOOPHOLE[intervalLen,INTEGER],CARDINAL] THEN LOOP; RETURN[min + rem]; ENDLOOP; };--Choose SetLogBitsPerPixel: PROC[n: [0..4)] RETURNS[BOOLEAN] = { b: CARDINAL _ Inline.BITSHIFT[1,n]; mode: ColorDisplay.Mode _ [FALSE,b,1]; IF NOT ColorDisplay.HasMode[mode] THEN { mode.bitsPerPixelB _ 0; IF NOT ColorDisplay.HasMode[mode] THEN RETURN[FALSE]; }; IF NOT ColorDisplay.SetMode[mode] THEN ERROR; lbpp _ n; bpp _ b; full _ FALSE; lbppB _ 0; bppB _ 1; ashow _ bshow _ TRUE; width _ ColorDisplay.width; height _ ColorDisplay.height; bitmap _ ColorDisplay.baseA; wpl _ ColorDisplay.wplA; bitmapB _ ColorDisplay.baseB; wplB _ ColorDisplay.wplB; ClearScreen; SetUpColors; ColorDisplay.TurnOn[]; RETURN[TRUE]; }; Set24BitsPerPixel: PROC = { mode: ColorDisplay.Mode _ [TRUE,0,0]; IF NOT ColorDisplay.HasMode[mode] THEN RETURN; IF NOT ColorDisplay.SetMode[mode] THEN ERROR; lbpp _ 0; bpp _ 0; full _ TRUE; bitmap _ NIL; bitmapB _ NIL; wpl _ 0; ashow _ bshow _ TRUE; width _ ColorDisplay.width; height _ ColorDisplay.height; IF test THEN { TestPattern[]; test _ FALSE } ELSE ClearScreen; IF neg THEN Negative ELSE Positive; ColorDisplay.TurnOn[]; }; Go: PROC = { [] _ InitRandom[0]; SELECT TRUE FROM SetLogBitsPerPixel[3] => NULL; SetLogBitsPerPixel[2] => NULL; ENDCASE => RETURN; -- PrintDirections; DO IF keys[E]=down THEN EXIT; IF keys[One]=down AND bpp#1 THEN { [] _ SetLogBitsPerPixel[0]; IF NOT splat THEN test _ TRUE }; IF keys[Two]=down AND bpp#2 THEN { [] _ SetLogBitsPerPixel[1]; IF NOT splat THEN test _ TRUE }; IF keys[Four]=down AND bpp#4 THEN { [] _ SetLogBitsPerPixel[2]; IF NOT splat THEN test _ TRUE }; IF keys[Eight]=down AND bpp#8 THEN { [] _ SetLogBitsPerPixel[3]; IF NOT splat THEN test _ TRUE }; IF keys[Zero]=down AND NOT full THEN { Set24BitsPerPixel[]; IF NOT splat THEN test _ TRUE }; IF keys[A]=down THEN { ashow _ NOT ashow; ColorDisplay.Show[ashow,bshow,TRUE]; WHILE keys[A]=down DO ENDLOOP }; IF keys[B]=down THEN { bshow _ NOT bshow; ColorDisplay.Show[ashow,bshow,TRUE]; WHILE keys[B]=down DO ENDLOOP }; IF keys[R]=down THEN { splat _ NOT splat; WHILE keys[R]=down DO ENDLOOP }; IF keys[N]=down THEN { neg _ NOT neg; WHILE keys[N]=down DO ENDLOOP }; IF keys[T]=down THEN { test _ TRUE; splat _ FALSE }; IF test THEN { TestPattern[]; test _ FALSE }; IF splat THEN RandomSplat; ENDLOOP; IF NOT ColorDisplay.SetMode[ColorDisplay.disconnected] THEN ERROR; }; Go[]; END.