Draw2dLines: Commander.CommandProc ~ {
MakeButton:
PROC [name:
ROPE, x, y:
NAT, proc: ClickProc]
RETURNS [r: Viewer] ~ {
r ¬ Buttons.Create[info: [parent: v, name: name, wx: x, wy: y], clientData: d, proc: proc];
};
d: REF Data ¬ NEW[Data];
v: Viewer ¬ d.viewer ¬ ViewerOps.CreateViewer[
flavor: $Lines,
paint: FALSE,
info: [name: "Draw2d Lines", openHeight: 420, scrollable: FALSE, data: d, iconic: TRUE]];
[] ¬ MakeButton["Repaint", 20, 380, Repaint];
d.modeBut ¬ MakeButton["Fixed ", 77, 380, ToggleFixed];
d.colorBut ¬
ChoiceButtons.BuildTextPrompt[v, 173, 380, "Color:", "0.0 0.0 0.0 ",, 100, d].textViewer;
RawViewers.SetColorWorld[ViewersWorldInstance.GetWorld[], $dense];
ViewerOps.OpenIcon[d.viewer];
};
Lines: ViewerClasses.PaintProc ~ {
Time:
PROC
[proc:
PROC, nTimes:
NAT ¬ 1]
RETURNS
[time:
REAL]
~
{
ENABLE Convert.Error => GOTO Bad;
s: IO.STREAM ¬ IO.RIS[ViewerTools.GetContents[d.colorBut]];
r ¬ IO.GetReal[s ! IO.EndOfStream => CONTINUE];
g ¬ IO.GetReal[s ! IO.EndOfStream => CONTINUE];
b ¬ IO.GetReal[s ! IO.EndOfStream => CONTINUE];
Imager.SetColor[context, ImagerColor.ColorFromRGB[[r, g, b]]];
time ¬ BasicTime.PulsesToSeconds[BasicTime.GetClockPulses[]];
THROUGH [0..nTimes) DO proc[]; ENDLOOP;
time ¬ (BasicTime.PulsesToSeconds[BasicTime.GetClockPulses[]]-time)/REAL[nTimes];
EXITS Bad => MessageWindow.Append["Bad color", TRUE];
};
Label:
PROC [v:
VEC, time, ref:
REAL, name:
ROPE]
RETURNS [arg:
REAL] ~ {
Imager.SetGray[context, 1.0];
Draw2d.Label[context, v, IO.PutFR1[Rope.Concat[name, ": %6.4f"], IO.real[arg ¬ time]]];
IF ref # 0.0
THEN
Draw2d.Label[context, [v.x, v.y-12], IO.PutFR1["(%7.6f times faster)", IO.real[ref/time]]];
};
SetImagerColor:
PROC [f:
REAL] ~ {
Imager.SetColor[context, ImagerColor.ColorFromRGB[[f+r*(1-f), f+g*(1-f), f+b*(1-f)]]]
};
ImagerLine:
PROC ~ {
Imager.SetStrokeEnd[context, round];
FOR i:
NAT
IN [0..nVecs)
DO
IF NOT d.fixed THEN SetImagerColor[i/REAL[nVecs]];
Imager.MaskVector[context, imager[i], [100, 160]];
ENDLOOP;
};
Draw2dLine:
PROC ~ {
zip: Draw2d.Zip ¬ Draw2d.GetZip[context];
FOR i:
NAT
IN [0..nVecs)
DO
IF NOT d.fixed THEN SetImagerColor[i/REAL[nVecs]];
Draw2d.Line[context, draw2d[i], [300, 160], solid, zip];
ENDLOOP;
Draw2d.ReleaseZip[zip];
};
CG6Line:
PROC ~ {
Inner:
PROC ~ {
ImagerCG6Context.SetCG6SubScreen[context,
self.wx+self.cx, self.wy+self.cy, self.cw, self.ch];
FOR i:
NAT
IN [0..nVecs)
DO
vec: IntegerPair ¬ cg6[i];
IF
NOT d.fixed
THEN {
f: REAL ¬ REAL[i]/REAL[nVecs];
ImagerCG6Context.SetCG6RGBColor[context, f+r*(1-f), f+g*(1-f), f+b*(1-f)];
};
ImagerCG6Context.LineCG6[context, vec.x, vec.y, 500, 160];
ENDLOOP;
};
ImagerCG6Context.DoSaveCG6[context, Inner];
};
refTime: REAL;
nVecs: NAT ~ 200;
r, g, b: REAL ¬ 0.0;
d: REF Data ¬ NARROW[self.data];
cg6: ARRAY [0..200) OF IntegerPair;
imager, draw2d: ARRAY [0..200) OF VEC;
FOR i:
NAT
IN [0..nVecs)
DO
t: REAL ¬ REAL[i]*2.0*3.1415926535/REAL[nVecs];
vec: VEC ¬ [90.0*RealFns.Cos[t], 150.0*RealFns.Sin[t]];
imager[i] ¬ [vec.x+100.0, vec.y+160.0];
draw2d[i] ¬ [vec.x+300.0, vec.y+160.0];
cg6[i] ¬ [Real.Round[vec.x]+500, Real.Round[vec.y]+160];
ENDLOOP;
refTime ¬ Label[[20, 350], Time[ImagerLine, 3], 0.0, "Imager.MaskVector"];
[] ¬ Label[[220, 350], Time[Draw2dLine, 3], refTime, "Draw2d.Solid"];
[] ¬ Label[[420, 350], Time[CG6Line, 3], refTime, "CG6Context.Line"];
};