DIRECTORY Random, Terminal, Imager, ImagerPath, Draw2d, Real, RealFns, IIBox, Basics, BasicTime, CedarProcess, II, IIBackdoor, Rope, IIStroke, IIFont, IIPath, IITransformation;
TimeIt: CEDAR PROGRAM IMPORTS Random, Terminal, Imager, Draw2d, Real, RealFns, IIBox, BasicTime, IIBackdoor, IIStroke, CedarProcess, II, IIFont, IIPath, IITransformation
~ BEGIN
CorrectRope: PROC [context: II.Context, rope: Rope.ROPE, p, v: II.VEC] ~ {
action: PROC ~ { II.ShowRope[context, rope] };
II.SetXY[context, p];
II.SetCorrectTolerance[context, [2, 5]];
II.SetCorrectMeasure[context, v];
II.Correct[context, action];
};
prevBB: II.Box ← [0, 0, 0, 0];
CorrectBufferedRope: PROC [context: II.Context, rope: Rope.ROPE, p, v: II.VEC] ~ {
fBB: II.Box ~ IIBox.BoxFromExtents[IIFont.FontBoundingBox[IIBackdoor.GetFont[context]]];
bb: II.Box ~ IIBox.BoundingBox[[fBB.xmin+p.x, fBB.ymin+p.y, fBB.ymin+p.x, fBB.ymax+p.y], [fBB.xmin+p.x+v.x, fBB.ymin+p.y+v.y, fBB.ymin+p.x+v.x, fBB.ymax+p.y+v.y]];
bb2: II.Box ~ IIBox.BoundingBox[prevBB, bb];
buffered: PROC ~ {
action: PROC ~ { II.ShowRope[context, rope] };
II.SetXY[context, p];
II.SetCorrectTolerance[context, [2, 5]];
II.SetCorrectMeasure[context, v];
II.Correct[context, action];
};
II.DoWithBuffer[context, buffered, Real.Round[bb2.xmin-1], Real.Round[bb2.ymin-1], Real.Round[bb2.xmax-bb2.xmin+2], Real.Round[bb2.ymax-bb2.ymin+2], II.white];
prevBB ← bb;
};
Run: PROC [context: II.Context, n: INT] RETURNS [microseconds: LONG CARDINAL] ~ {
pulses: BasicTime.Pulses;
action: PROC ~ {
f0: II.Font ~ IIFont.Find["Xerox/TiogaFonts/Tioga10"];
f1: II.Font ~ IIFont.Find["Xerox/TiogaFonts/Tioga10B"];
f2: II.Font ~ IIFont.Find["Xerox/TiogaFonts/TimesRoman8"];
f3: II.Font ~ IIFont.Find["Xerox/TiogaFonts/TimesRoman10"];
II.SetXY[context, [2409.0/80, 774]];
II.SetFont[context, f0];
II.ShowText[context, "CedarProcess.SetPriority[normal];"];
II.SetXY[context, [2409.0/80, 762]];
II.SetFont[context, f0];
II.ShowText[context, "microseconds ← BasicTime.PulsesToMicroseconds[pulses];"];
II.SetXY[context, [2409.0/80, 750]];
II.SetFont[context, f0];
II.ShowText[context, "};"];
II.SetXY[context, [13385.0/889, 738]];
II.SetXY[context, [13385.0/889, 726]];
II.SetFont[context, f1];
II.ShowText[context, "AllChars2"];
II.SetFont[context, f0];
II.ShowText[context, ": "];
II.SetFont[context, f2];
II.ShowText[context, "PROC"];
II.SetFont[context, f0];
II.ShowText[context, " [dst: IISample.SampleMap, chars: "];
II.SetFont[context, f2];
II.ShowText[context, "LIST"];
II.SetFont[context, f0];
II.ShowText[context, " "];
II.SetFont[context, f2];
II.ShowText[context, "OF"];
II.SetFont[context, f0];
II.ShowText[context, " IIDevice.CharMask, function:"];
II.SetXY[context, [2409.0/40, 714]];
II.SetFont[context, f0];
II.ShowText[context, "IISample.Function ← IISample.nullFunction, n: "];
II.SetFont[context, f2];
II.ShowText[context, "INT"];
II.SetFont[context, f0];
II.ShowText[context, " ← 1] "];
II.SetFont[context, f2];
II.ShowText[context, "RETURNS"];
II.SetFont[context, f0];
II.ShowText[context, " [microseconds: "];
II.SetFont[context, f2];
II.ShowText[context, "LONG"];
II.SetXY[context, [2409.0/40, 702]];
II.SetFont[context, f2];
II.ShowText[context, "CARDINAL"];
II.SetFont[context, f0];
II.ShowText[context, "] ~ {"];
II.SetXY[context, [2409.0/80, 690]];
II.SetFont[context, f0];
II.ShowText[context, "pulses: BasicTime.Pulses;"];
II.SetXY[context, [2409.0/80, 678]];
II.SetFont[context, f0];
II.ShowText[context, "maxN: "];
II.SetFont[context, f2];
II.ShowText[context, "NAT"];
II.SetFont[context, f0];
II.ShowText[context, " ~ IISampleExtras.rawArraySize;"];
II.SetXY[context, [2409.0/80, 666]];
II.SetFont[context, f1];
II.ShowText[context, "Gen"];
II.SetFont[context, f0];
II.ShowText[context, ": "];
II.SetFont[context, f2];
II.ShowText[context, "PROC"];
II.SetFont[context, f0];
II.ShowText[context, " ~ "];
II.SetFont[context, f2];
II.ShowText[context, "TRUSTED"];
II.SetFont[context, f0];
II.ShowText[context, " {"];
II.SetXY[context, [7227.0/160, 654]];
II.SetFont[context, f0];
II.ShowText[context, "box: "];
II.SetFont[context, f2];
II.ShowText[context, "SF"];
II.SetFont[context, f0];
II.ShowText[context, ".Box ~ IISample.GetBox[dst];"];
II.SetXY[context, [7227.0/160, 642]];
II.SetFont[context, f0];
II.ShowText[context, "s: "];
II.SetFont[context, f2];
II.ShowText[context, "INTEGER"];
II.SetFont[context, f0];
II.ShowText[context, " ← box.min.s;"];
II.SetXY[context, [7227.0/160, 630]];
II.SetFont[context, f0];
II.ShowText[context, "f: "];
II.SetFont[context, f2];
II.ShowText[context, "INTEGER"];
II.SetFont[context, f0];
II.ShowText[context, " ← box.min.f;"];
II.SetXY[context, [7227.0/160, 618]];
II.SetFont[context, f0];
II.ShowText[context, "nextS: "];
II.SetFont[context, f2];
II.ShowText[context, "INTEGER"];
II.SetFont[context, f0];
II.ShowText[context, " ← 0;"];
II.SetXY[context, [7227.0/160, 606]];
II.SetFont[context, f0];
II.ShowText[context, "i: "];
II.SetFont[context, f2];
II.ShowText[context, "NAT"];
II.SetFont[context, f0];
II.ShowText[context, " ← 0;"];
II.SetXY[context, [7227.0/160, 594]];
II.SetFont[context, f0];
II.ShowText[context, "a: "];
II.SetFont[context, f2];
II.ShowText[context, "ARRAY"];
II.SetFont[context, f0];
II.ShowText[context, " [0..maxN) "];
II.SetFont[context, f2];
II.ShowText[context, "OF"];
II.SetFont[context, f0];
II.ShowText[context, " IISampleExtras.RawDescriptor;"];
II.SetXY[context, [7227.0/160, 582]];
II.SetFont[context, f0];
II.ShowText[context, "a0: "];
II.SetFont[context, f2];
II.ShowText[context, "POINTER"];
II.SetFont[context, f0];
II.ShowText[context, " "];
II.SetFont[context, f2];
II.ShowText[context, "TO"];
II.SetFont[context, f0];
II.ShowText[context, " IISampleExtras.RawDescriptor ~ @(a[0]);"];
II.SetXY[context, [7227.0/160, 570]];
II.SetFont[context, f0];
II.ShowText[context, "p: "];
II.SetFont[context, f2];
II.ShowText[context, "POINTER"];
II.SetFont[context, f0];
II.ShowText[context, " "];
II.SetFont[context, f2];
II.ShowText[context, "TO"];
II.SetFont[context, f0];
II.ShowText[context, " IISampleExtras.RawDescriptor ← a0;"];
II.SetXY[context, [7227.0/160, 558]];
II.SetFont[context, f2];
II.ShowText[context, "FOR"];
II.SetFont[context, f0];
II.ShowText[context, " each: "];
II.SetFont[context, f2];
II.ShowText[context, "LIST"];
II.SetFont[context, f0];
II.ShowText[context, " "];
II.SetFont[context, f2];
II.ShowText[context, "OF"];
II.SetFont[context, f0];
II.ShowText[context, " IIDevice.CharMask ← chars, each.rest "];
II.SetFont[context, f2];
II.ShowText[context, "UNTIL"];
II.SetFont[context, f0];
II.ShowText[context, " each = "];
II.SetFont[context, f2];
II.ShowText[context, "NIL"];
II.SetFont[context, f0];
II.ShowText[context, " "];
II.SetFont[context, f2];
II.ShowText[context, "DO"];
II.SetXY[context, [2409.0/40, 546]];
II.SetFont[context, f2];
II.ShowText[context, "WITH"];
II.SetFont[context, f0];
II.ShowText[context, " each.first "];
II.SetFont[context, f2];
II.ShowText[context, "SELECT"];
II.SetFont[context, f0];
II.ShowText[context, " "];
II.SetFont[context, f2];
II.ShowText[context, "FROM"];
II.SetXY[context, [2409.0/32, 534]];
II.SetFont[context, f0];
II.ShowText[context, "raster: "];
II.SetFont[context, f2];
II.ShowText[context, "REF"];
II.SetFont[context, f0];
II.ShowText[context, " IIDevice.CharMaskRep.raster =\076 {"];
II.SetXY[context, [7227.0/80, 522]];
II.SetFont[context, f2];
II.ShowText[context, "IF"];
II.SetFont[context, f0];
II.ShowText[context, " f+"];
II.SetFont[context, f2];
II.ShowText[context, "NAT"];
II.SetFont[context, f0];
II.ShowText[context, "[raster.fSizeBB] \076 box.max.f "];
II.SetFont[context, f2];
II.ShowText[context, "THEN"];
II.SetFont[context, f0];
II.ShowText[context, " { f ← 0; s ← nextS };"];
II.SetXY[context, [7227.0/80, 510]];
II.SetFont[context, f2];
II.ShowText[context, "IF"];
II.SetFont[context, f0];
II.ShowText[context, " f+"];
II.SetFont[context, f2];
II.ShowText[context, "NAT"];
II.SetFont[context, f0];
II.ShowText[context, "[raster.fSizeBB] <= box.max.f "];
II.SetFont[context, f2];
II.ShowText[context, "AND"];
II.SetFont[context, f0];
II.ShowText[context, " "];
II.SetFont[context, f2];
II.ShowText[context, "NAT"];
II.SetFont[context, f0];
II.ShowText[context, "[s+raster.sSizeBB] <= box.max.s "];
II.SetFont[context, f2];
II.ShowText[context, "THEN"];
II.SetFont[context, f0];
II.ShowText[context, " {"];
II.SetXY[context, [16863.0/160, 498]];
II.SetFont[context, f2];
II.ShowText[context, "IF"];
II.SetFont[context, f0];
II.ShowText[context, " i = maxN "];
II.SetFont[context, f2];
II.ShowText[context, "THEN"];
II.SetFont[context, f0];
II.ShowText[context, " { IISampleExtras.MultipleTransfer[dst, i, @a, function]; i ← 0; p ←"];
II.SetXY[context, [2409.0/16, 486]];
II.SetFont[context, f0];
II.ShowText[context, "a0 };"];
II.SetXY[context, [16863.0/160, 474]];
II.SetFont[context, f0];
II.ShowText[context, "p^.box ← "];
II.SetFont[context, f2];
II.ShowText[context, "SF"];
II.SetFont[context, f0];
II.ShowText[context, ".Displace[[max: [raster.sSizeBB, raster.fSizeBB]], [s, f]];"];
II.SetXY[context, [16863.0/160, 462]];
II.SetFont[context, f0];
II.ShowText[context, "f ← p^.box.max.f;"];
II.SetXY[context, [16863.0/160, 450]];
II.SetFont[context, f0];
II.ShowText[context, "nextS ← "];
II.SetFont[context, f2];
II.ShowText[context, "MAX"];
II.SetFont[context, f0];
II.ShowText[context, "[nextS, p^.box.max.s];"];
II.SetXY[context, [16863.0/160, 438]];
II.SetFont[context, f0];
II.ShowText[context, "p^.bitsPerLine ← Basics."];
II.SetFont[context, f2];
II.ShowText[context, "BITAND"];
II.SetFont[context, f0];
II.ShowText[context, "[raster.fSizeBB+15, 0FFF0H];"];
II.SetXY[context, [16863.0/160, 426]];
II.SetFont[context, f0];
II.ShowText[context, "p^.basePointer ← @(raster[0]);"];
II.SetXY[context, [16863.0/160, 414]];
II.SetFont[context, f0];
II.ShowText[context, "p ← p + "];
II.SetFont[context, f2];
II.ShowText[context, "SIZE"];
II.SetFont[context, f0];
II.ShowText[context, "[IISampleExtras.RawDescriptor];"];
II.SetXY[context, [16863.0/160, 402]];
II.SetFont[context, f0];
II.ShowText[context, "i ← i + 1;"];
II.SetXY[context, [16863.0/160, 390]];
II.SetFont[context, f0];
II.ShowText[context, "};"];
II.SetXY[context, [7227.0/80, 378]];
II.SetFont[context, f0];
II.ShowText[context, "};"];
II.SetXY[context, [2409.0/32, 366]];
II.SetFont[context, f2];
II.ShowText[context, "ENDCASE"];
II.SetFont[context, f0];
II.ShowText[context, " =\076 "];
II.SetFont[context, f2];
II.ShowText[context, "NULL"];
II.SetFont[context, f0];
II.ShowText[context, ";"];
II.SetXY[context, [2409.0/40, 354]];
II.SetFont[context, f2];
II.ShowText[context, "ENDLOOP"];
II.SetFont[context, f0];
II.ShowText[context, ";"];
II.SetXY[context, [7227.0/160, 342]];
II.SetFont[context, f2];
II.ShowText[context, "IF"];
II.SetFont[context, f0];
II.ShowText[context, " i # 0 "];
II.SetFont[context, f2];
II.ShowText[context, "THEN"];
II.SetFont[context, f0];
II.ShowText[context, " { IISampleExtras.MultipleTransfer[dst, i, @a, function]; i ← 0; p ← a0 };"];
II.SetXY[context, [7227.0/160, 330]];
II.SetFont[context, f0];
II.ShowText[context, "};"];
II.SetXY[context, [2409.0/80, 318]];
II.SetFont[context, f0];
II.ShowText[context, "CedarProcess.SetPriority[foreground];"];
II.SetXY[context, [2409.0/80, 306]];
II.SetFont[context, f0];
II.ShowText[context, "pulses ← BasicTime.GetClockPulses[];"];
II.SetXY[context, [2409.0/80, 294]];
II.SetFont[context, f2];
II.ShowText[context, "FOR"];
II.SetFont[context, f0];
II.ShowText[context, " i: "];
II.SetFont[context, f2];
II.ShowText[context, "INT"];
II.SetFont[context, f0];
II.ShowText[context, " "];
II.SetFont[context, f2];
II.ShowText[context, "IN"];
II.SetFont[context, f0];
II.ShowText[context, " [0..n) "];
II.SetFont[context, f2];
II.ShowText[context, "DO"];
II.SetFont[context, f0];
II.ShowText[context, " Gen[] "];
II.SetFont[context, f2];
II.ShowText[context, "ENDLOOP"];
II.SetFont[context, f0];
II.ShowText[context, ";"];
II.SetXY[context, [2409.0/80, 282]];
II.SetFont[context, f0];
II.ShowText[context, "pulses ← BasicTime.GetClockPulses[]-pulses;"];
II.SetXY[context, [2409.0/80, 270]];
II.SetFont[context, f0];
II.ShowText[context, "CedarProcess.SetPriority[normal];"];
II.SetXY[context, [2409.0/80, 258]];
II.SetFont[context, f0];
II.ShowText[context, "microseconds ← BasicTime.PulsesToMicroseconds[pulses];"];
II.SetXY[context, [2409.0/80, 246]];
II.SetFont[context, f0];
II.ShowText[context, "};"];
II.SetXY[context, [13385.0/889, 234]];
II.SetXY[context, [0, 222]];
II.SetFont[context, f2];
II.ShowText[context, "END"];
II.SetFont[context, f0];
II.ShowText[context, "."];
II.SetXY[context, [0, 210]];
II.SetXY[context, [0, 198]];
II.SetFont[context, f0];
II.ShowText[context, "ColorDisplay on 1 640x480"];
II.SetXY[context, [0, 186]];
II.SetFont[context, f0];
II.ShowText[context, "← &b ← IISample.MapFromFrameBuffer[Terminal.GetColorFrameBufferA[Terminal.Current[]]]"];
II.SetXY[context, [0, 174]];
II.SetFont[context, f0];
II.ShowText[context, "← IISample.Clear[&b]"];
II.SetXY[context, [0, 162]];
II.SetFont[context, f0];
II.ShowText[context, "← Test.AllChars[&b, IICache.GetList[IICache.GetNamedCache[$Bitmap, 4000]], [null,null]]"];
II.SetXY[context, [0, 150]];
II.SetXY[context, [0, 138]];
II.SetFont[context, f0];
II.ShowText[context, "← NIL=(&list ← IICache.GetList[IICache.GetNamedCache[$Bitmap, 4000]])"];
II.SetXY[context, [0, 126]];
II.SetFont[context, f0];
II.ShowText[context, "← IISample.Clear[&b]"];
II.SetXY[context, [0, 114]];
II.SetFont[context, f0];
II.ShowText[context, "← Test.AllChars[&b, IICache.GetList[IICache.GetNamedCache[$Bitmap, 4000]], [null,null], 10]"];
II.SetXY[context, [0, 102]];
II.SetFont[context, f0];
II.ShowText[context, "← Test.AllChars2[&b, IICache.GetList[IICache.GetNamedCache[$Bitmap, 4000]], [null,null],"];
II.SetXY[context, [7227.0/160, 90]];
II.SetFont[context, f0];
II.ShowText[context, "10]"];
II.SetXY[context, [0, 78]];
II.SetXY[context, [0, 60]];
II.SetFont[context, f3];
II.ShowText[context, "Character Transfer Times"];
II.SetXY[context, [0, 42]];
II.SetFont[context, f3];
II.ShowText[context, "(all times in microseconds per character, on a dorado)"];
II.SetXY[context, [0, 24]];
II.SetFont[context, f3];
II.ShowText[context, "Callback: "];
II.SetXRel[context, 104];
II.ShowText[context, "84.29583"];
II.SetXY[context, [0, 6]];
II.SetFont[context, f3];
II.ShowText[context, "Array: "];
II.SetXRel[context, 119];
II.ShowText[context, "79.58922"];
};
CedarProcess.SetPriority[foreground];
pulses ← BasicTime.GetClockPulses[];
FOR i: INT IN [0..n) DO action[] ENDLOOP;
pulses ← BasicTime.GetClockPulses[]-pulses;
CedarProcess.SetPriority[normal];
microseconds ← BasicTime.PulsesToMicroseconds[pulses];
};
priority: CedarProcess.Priority ← foreground;
Vectors: PROC [context: II.Context, n: INT] RETURNS [microseconds: LONG CARDINAL] ~ {
theta: REAL ~ 360.0/MAX[n, 1];
rot: II.VEC ~ [RealFns.CosDeg[theta], RealFns.SinDeg[theta]];
r: II.Rectangle ~ IIBackdoor.GetBoundingRectangle[context];
center: II.VEC ~ [r.x+r.w/2.0, r.y+r.h/2.0];
radius: REAL ~ MIN[r.w, r.h]/2.0;
pulses: BasicTime.Pulses;
CMul: PROC [a, b: II.VEC] RETURNS [II.VEC] ~ {
RETURN [[(a.x*b.x - a.y*b.y), (a.x*b.y + a.y*b.x)]] -- complex product
};
Add: PROC [a, b: II.VEC] RETURNS [II.VEC] ~ INLINE {
RETURN [[(a.x+b.x), (a.y+b.y)]]
};
action: PROC ~ {
v: II.VEC ← [radius, 0];
FOR i: INT IN [0..n) DO
II.MaskVector[context, center, Add[center, v]];
v ← CMul[v, rot];
ENDLOOP;
};
CedarProcess.SetPriority[priority];
pulses ← BasicTime.GetClockPulses[];
action[];
pulses ← BasicTime.GetClockPulses[]-pulses;
CedarProcess.SetPriority[normal];
microseconds ← BasicTime.PulsesToMicroseconds[pulses];
};
Vectors2d: PROC [context: Imager.Context, n: INT] RETURNS [microseconds: LONG CARDINAL] ~ {
theta: REAL ~ 360.0/MAX[n, 1];
rot: II.VEC ~ [RealFns.CosDeg[theta], RealFns.SinDeg[theta]];
r: Imager.Rectangle ~ [0, 0, 480, 640];
center: II.VEC ~ [r.x+r.w/2.0, r.y+r.h/2.0];
radius: REAL ~ MIN[r.w, r.h]/2.0;
pulses: BasicTime.Pulses;
CMul: PROC [a, b: II.VEC] RETURNS [II.VEC] ~ {
RETURN [[(a.x*b.x - a.y*b.y), (a.x*b.y + a.y*b.x)]] -- complex product
};
Add: PROC [a, b: II.VEC] RETURNS [II.VEC] ~ INLINE {
RETURN [[(a.x+b.x), (a.y+b.y)]]
};
action: PROC ~ {
v: II.VEC ← [radius, 0];
FOR i: INT IN [0..n) DO
Draw2d.Line[context, center, Add[center, v]];
v ← CMul[v, rot];
ENDLOOP;
};
CedarProcess.SetPriority[priority];
pulses ← BasicTime.GetClockPulses[];
action[];
pulses ← BasicTime.GetClockPulses[]-pulses;
CedarProcess.SetPriority[normal];
microseconds ← BasicTime.PulsesToMicroseconds[pulses];
};
Traj: PROC [context: II.Context, t: IIPath.Trajectory, n: INT ← 1, closed: BOOLFALSE] RETURNS [microseconds: LONG CARDINAL] ~ {
pulses: BasicTime.Pulses;
action: PROC ~ {
II.MaskStrokeTrajectory[context, t, closed];
};
CedarProcess.SetPriority[priority];
pulses ← BasicTime.GetClockPulses[];
FOR i: INT IN [0..n) DO action[] ENDLOOP;
pulses ← BasicTime.GetClockPulses[]-pulses;
CedarProcess.SetPriority[normal];
microseconds ← BasicTime.PulsesToMicroseconds[pulses];
};
TTraj: PROC [context: Imager.Context, t: ImagerPath.Trajectory, n: INT ← 1, closed: BOOLFALSE] RETURNS [microseconds: LONG CARDINAL] ~ {
pulses: BasicTime.Pulses;
action: PROC ~ {
Imager.MaskStrokeTrajectory[context, t, closed];
};
CedarProcess.SetPriority[priority];
pulses ← BasicTime.GetClockPulses[];
FOR i: INT IN [0..n) DO action[] ENDLOOP;
pulses ← BasicTime.GetClockPulses[]-pulses;
CedarProcess.SetPriority[normal];
microseconds ← BasicTime.PulsesToMicroseconds[pulses];
};
StrokeOutline: PROC [context: II.Context, t: IIPath.Trajectory, closed: BOOL, box: IIBox.Box ← IIStroke.bigBox] ~ {
m: II.Transformation ~ IIBackdoor.GetT[context];
w: REAL ~ IIBackdoor.GetReal[context, strokeWidth];
end: INT ~ IIBackdoor.GetInt[context, strokeEnd];
joint: INT ~ IIBackdoor.GetInt[context, strokeJoint];
p: PROC ~ {
tpath: II.PathProc ~ { IIPath.MapTrajectory[t, moveTo, lineTo, curveTo, conicTo, arcTo] };
fp: II.VEC ← [0, 0];
lp: II.VEC ← [0, 0];
moveTo: IIPath.MoveToProc ~ { IF fp # [0, 0] THEN lineTo[fp]; fp ← lp ← p };
lineTo: IIPath.LineToProc ~ { II.MaskVector[context, lp, p1]; lp ← p1 };
conicTo: IIPath.ConicToProc ~ { II.MaskVector[context, lp, p1]; II.MaskVector[context, p1, p2]; II.MaskVector[context, lp, p2]; lp ← p2 };
IIBackdoor.SetT[context, IITransformation.Scale[1]];
II.SetStrokeWidth[context, 0];
II.SetStrokeEnd[context, round];
II.SetStrokeJoint[context, round];
IIStroke.PathFromStroke[path: tpath, closed: closed, width: w, end: end, joint: joint, m: m, moveTo: moveTo, lineTo: lineTo, conicTo: conicTo, box: box];
IF fp # [0, 0] THEN lineTo[fp];
};
II.DoSave[context, p];
};
ObjectFromTraj: PROC [t: IIPath.Trajectory, m: II.Transformation ← NIL] RETURNS [II.Object] ~ {
foo: LIST OF REF ~ LIST[t, m];
o: II.Object ~ NEW[II.ObjectRep ← [draw: DrawTrajObject, clip: GetBounds[], data: foo]];
GetBounds: PROC RETURNS [IIBox.Rectangle] ~ {
box: IIBox.Box ← [xmin: t.lp.x, ymin: t.lp.y, xmax: t.lp.x, ymax: t.lp.y];
FOR each: IIPath.Trajectory ← t, each.prev UNTIL each = NIL DO
box ← IIBox.BoundPoint[box, each.lp];
WITH each SELECT FROM
curve: REF IIPath.TrajectoryRep.curve => { box ← IIBox.BoundPoint[box, curve.p1]; box ← IIBox.BoundPoint[box, curve.p2] };
conic: REF IIPath.TrajectoryRep.conic => { box ← IIBox.BoundPoint[box, conic.p1] };
arc: REF IIPath.TrajectoryRep.arc => ERROR;
ENDCASE => NULL;
ENDLOOP;
RETURN [IIBox.RectangleFromBox[box]];
};
RETURN [o]
};
DrawTrajObject: PROC [self: II.Object, context: II.Context] ~ {
foo: LIST OF REF ~ NARROW[self.data];
t: IIPath.Trajectory ~ NARROW[foo.first];
m: II.Transformation ~ NARROW[foo.rest.first];
II.ConcatT[context, m];
II.MaskFillTrajectory[context, t];
};
TestTrans: PROC [t: IITransformation.Transformation] ~ {
FOR s: IITransformation.Direction IN IITransformation.Direction DO
FOR f: IITransformation.Direction IN IITransformation.Direction DO
m1: IITransformation.Transformation ~ IITransformation.Concat[IITransformation.SFToXY[[slow: s, fast: f], 100, 200], t];
m2: IITransformation.Transformation ~ IITransformation.Copy[t];
IITransformation.ApplySFToXY[m2, [slow: s, fast: f], 100, 200];
IF NOT IITransformation.Equal[m1, m2] THEN ERROR;
ENDLOOP;
ENDLOOP;
};
Paint: PROC [context: II.Context, object: II.Object, interactive: BOOLTRUE] ~ {
vt: Terminal.Virtual ~ Terminal.Current[];
UNTIL Terminal.GetKeys[vt][Red] = down DO ENDLOOP;
WHILE Terminal.GetKeys[vt][Red] = down DO
mouse: Terminal.Position ← Terminal.GetBWCursorPosition[vt];
mouse.y ← 808-mouse.y;
II.DrawObject[context: context, object: object, position: [mouse.x, mouse.y], interactive: interactive];
ENDLOOP;
};
Sketch: PROC [context: II.Context] RETURNS [II.Trajectory] ~ {
vt: Terminal.Virtual ~ Terminal.Current[];
t: II.Trajectory ← NIL;
mouse: Terminal.Position ← Terminal.GetBWCursorPosition[vt];
UNTIL Terminal.GetKeys[vt][Red] = down DO ENDLOOP;
mouse ← Terminal.GetBWCursorPosition[vt];
mouse.y ← 808-mouse.y;
t ← IIPath.MoveTo[[mouse.x, mouse.y]];
II.SetStrokeWidth[context, 0];
II.SetStrokeEnd[context, round];
WHILE Terminal.GetKeys[vt][Red] = down DO
m: Terminal.Position ← Terminal.GetBWCursorPosition[vt];
m.y ← 808-m.y;
IF m # mouse THEN {
II.MaskVector[context, [mouse.x, mouse.y], [m.x, m.y]];
t ← IIPath.LineTo[t, [m.x, m.y]];
};
mouse ← m;
ENDLOOP;
RETURN [t]
};
MakeStrokeObject: PROC [t: IIPath.Trajectory, w: REAL ← 0] RETURNS [II.Object] ~ {
wr: REF REAL ~ NEW[REAL ← w];
foo: LIST OF REF ~ LIST[t, wr];
o: II.Object ~ NEW[II.ObjectRep ← [draw: DrawStrokeObject, clip: GetBounds[], data: foo]];
GetBounds: PROC RETURNS [IIBox.Rectangle] ~ {
box: IIBox.Box ← [xmin: t.lp.x, ymin: t.lp.y, xmax: t.lp.x, ymax: t.lp.y];
FOR each: IIPath.Trajectory ← t, each.prev UNTIL each = NIL DO
box ← IIBox.BoundPoint[box, each.lp];
WITH each SELECT FROM
curve: REF IIPath.TrajectoryRep.curve => { box ← IIBox.BoundPoint[box, curve.p1]; box ← IIBox.BoundPoint[box, curve.p2] };
conic: REF IIPath.TrajectoryRep.conic => { box ← IIBox.BoundPoint[box, conic.p1] };
arc: REF IIPath.TrajectoryRep.arc => ERROR;
ENDCASE => NULL;
ENDLOOP;
box.xmin ← box.xmin-w;
box.ymin ← box.ymin-w;
box.xmax ← box.xmax+w;
box.ymax ← box.ymax+w;
RETURN [IIBox.RectangleFromBox[box]];
};
RETURN [o]
};
DrawStrokeObject: PROC [self: II.Object, context: II.Context] ~ {
foo: LIST OF REF ~ NARROW[self.data];
t: IIPath.Trajectory ~ NARROW[foo.first];
w: REF REAL ~ NARROW[foo.rest.first];
II.SetStrokeEnd[context, round];
II.SetStrokeJoint[context, round];
II.SetStrokeWidth[context, w^];
II.MaskStrokeTrajectory[context, t, TRUE];
};
MultiObject: PROC [context: II.Context, object: II.Object, n: INT ← 1, interactive: BOOLTRUE] RETURNS [microseconds: LONG CARDINAL] ~ {
rs: Random.RandomStream ~ Random.Create[seed: n];
pulses: BasicTime.Pulses;
CedarProcess.SetPriority[foreground];
pulses ← BasicTime.GetClockPulses[];
FOR i: INT IN [0..n) DO
II.DrawObject[context: context, object: object, position: [Random.ChooseInt[rs, -50, 600], Random.ChooseInt[rs, -50, 400]], interactive: interactive];
ENDLOOP;
pulses ← BasicTime.GetClockPulses[]-pulses;
CedarProcess.SetPriority[normal];
microseconds ← BasicTime.PulsesToMicroseconds[pulses];
};
END.
ColorDisplay on 1 640x480
← &b ← IISample.MapFromFrameBuffer[Terminal.GetBWFrameBuffer[Terminal.Current[]]]
← &c ← IIBitmapContext.Create[[480, 640], [slow: down, fast: right], [60.0, 60.0], TRUE, $Bitmap]
← IIBitmapContext.SetBitmap[&c, &b]
← &C ← ImagerTerminal.BWContext[Terminal.Current[], TRUE]
← II.SetStrokeEnd[&c, round]
← TimeIt.Vectors[&c, 1000]
← TimeIt.Vectors2d[&C, 1000]

(there are 1186 characters below the line)
← &show ← &c.class.Show
← II.SetFont[&c, IIFont.Find["Xerox/TiogaFonts/Tioga10"]]
← II.SetCorrectTolerance[&c, [50, 50]]
{ DO &p ← Terminal.GetMousePosition[Terminal.Current[]]; II.SetGray[&c, 1]; TimeIt.CorrectBufferedRope[&c, "Now is the time for all good men to come to the aid of their party.", [10, 300], [&p.x, 404-&p.y]]; ENDLOOP }
{ DO &p ← Terminal.GetMousePosition[Terminal.Current[]]; II.SetGray[&c, 1]; &c.class.Show ← &show; TimeIt.CorrectRope[&c, "Now is the time for all good men to come to the aid of their party.", [10, 300], [&p.x, 404-&p.y]]; II.SetGray[&c, 0]; Process.Pause[15]; &c.class.Show ← IIRasterImpl.RasterShow; TimeIt.CorrectRope[&c, "Now is the time for all good men to come to the aid of their party.", [10, 300], [&p.x, 404-&p.y]]; ENDLOOP }