CmSlitherImpl.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Bloomenthal, January 13, 1986 11:00:01 pm PST
DIRECTORY CedarProcess, Commander, Controls, ImagerColor, InterminalBackdoor, ImagerPixelMap, Interminal, IO, Process, Random, Real, Spline3d, Terminal, ViewerClasses;
CmSlitherImpl:
CEDAR
PROGRAM
IMPORTS CedarProcess, Commander, Controls, ImagerColor, InterminalBackdoor, Process, Random, Real, Terminal, Spline3d
~ {
out: IO.STREAM;
Triple: TYPE ~ Spline3d.Triple;
CmSlither: Commander.CommandProc ~ {
outer: ViewerClasses.Viewer ← Controls.OuterViewer[name: "Slither"];
out ← cmd.out;
TRUSTED {Process.Detach[FORK Slither[NARROW[outer.data, Controls.OuterData]]]};
};
Slither:
PROC [data: Controls.OuterData] ~ {
v: ImagerColor.RGB;
r, g, b: Terminal.ColorValue;
vt: Terminal.Virtual ← InterminalBackdoor.terminal;
CedarProcess.SetPriority[background];
WHILE
NOT data.stop
DO
FOR i:
NAT
IN[0..253]
DO
[r, g, b] ← Terminal.GetColor[vt: vt, aChannelValue: 254-i];
Terminal.SetColor[vt, 255-i, , r, g, b];
ENDLOOP;
v ← ImagerColor.RGBFromHSV[GetSlitherHSV[]];
Terminal.SetColor[vt, 1,, Real.RoundI[255.0*v.R], Real.RoundI[255.0*v.G], Real.RoundI[255.0*v.B]];
ENDLOOP;
};
index, count: NAT ← 0;
p0: Triple ← GetRandomPt[];
p1: Triple ← GetRandomPt[];
p2: Triple ← GetRandomPt[];
p3: Triple ← GetRandomPt[];
triples: Spline3d.TripleSequence ← NEW[Spline3d.TripleSequenceRec[50]];
GetSlitherHSV:
PROC
RETURNS [ImagerColor
.HSV] ~ {
Range:
PROC [p: Triple]
RETURNS [Triple] ~ {
InnerRange:
PROC [r:
REAL]
RETURNS [
REAL] ~ {
RETURN[IF r < 0.01 THEN 0.01 ELSE IF r > 0.99 THEN 0.99 ELSE r];
};
RETURN[[InnerRange[p.x], InnerRange[p.y], InnerRange[p.z]]];
};
IF (index ← index+1) >= count
THEN {
index ← 0;
count ← Random.ChooseInt[min: 7, max: 30];
p0 ← p3;
p1 ← [p3.x+p3.x-p2.x, p3.y+p3.y-p2.y, p3.z+p3.z-p2.z];
p2 ← GetRandomPt[];
p3 ← GetRandomPt[];
[] ← Spline3d.Samples[Spline3d.BezierToCoeffs[[p0, p1, p2, p3]], count, triples];
FOR n: NAT IN[0..count) DO triples[n] ← Range[triples[n]]; ENDLOOP;
};
RETURN[[triples[index].x, triples[index].y, triples[index].z]];
};
GetRandomPt:
PROC
RETURNS [Triple] ~ {
ChooseReal:
PROC
RETURNS [
REAL] ~ {
RETURN[(1.0/1024.0)*Random.ChooseInt[min: 1, max: 1024]];
};
RETURN[[ChooseReal[], ChooseReal[], ChooseReal[]]];
};
Commander.Register["CmSlither", CmSlither, "\nSlither through color space."];
}.