NKN
2012-09-21 20:36:11
function SetDDTM(tolerance:integer): Integer;
var
dtmMainPoint: TDTMPointDef;
BlackListedColors:Array [0..2] of Integer;
dtmSubPoints: Array [0..2] of TDTMPointDef;
TempTDTM: TDTM;
SB : TBox;
TP,TP1 : TPoint;
i:integer;
begin
SB := IntToBox(MMCX - 5,MMCY- 5,MMCX + 5,MMCY + 5);
for i := 0 to 2 do
BlackListedColors[i] := 1;
repeat
TP.x := randomRange(SB.X1,SB.X2);
TP.y := randomRange(SB.y1,SB.y2);
until(not(PointInBox(TP,IntToBox(625,133 - 50,629,137 - 50))))
dtmMainPoint.x := TP.x;
dtmMainPoint.y := TP.y;
dtmMainPoint.AreaSize := 0;
dtmMainPoint.AreaShape := 0;
dtmMainPoint.Color := GetColor(TP.x,TP.y);
BlackListedColors[0] := GetColor(TP.x,TP.y);
dtmMainPoint.Tolerance := 5;
SMART_DrawDot(True,TP,clPurple);
repeat
TP1.x := TP.x + randomrange(-15,15);
TP1.y := TP.y + randomrange(-15,15);
dtmSubPoints[0].x := TP1.x;
dtmSubPoints[0].y := TP1.y;
dtmSubPoints[0].AreaSize := 0;
dtmSubPoints[0].AreaShape := 0;
dtmSubPoints[0].Color := GetColor(TP1.x,TP1.y);
BlackListedColors[1] := GetColor(TP.x,TP.y);
dtmSubPoints[0].Tolerance := tolerance;
writeln('111');
until(not(dtmSubPoints[0].Color = BlackListedColors[0]));
for i := 0 to High(BlackListedColors) - 1 do
begin
TP1.x := TP.x - randomrange(-5,15);
TP1.y := TP.y - randomrange(-5,15);
SMART_DrawDot(False,TP1,clPurple);
dtmSubPoints[1].x := TP1.x;
dtmSubPoints[1].y := TP1.y;
dtmSubPoints[1].AreaSize := 0;
dtmSubPoints[1].AreaShape := 0;
dtmSubPoints[1].Color := GetColor(TP1.x,TP1.y);
BlackListedColors[2] := GetColor(TP1.x,TP1.y);
dtmSubPoints[1].Tolerance := tolerance;
if(not(dtmSubPoints[1].Color = BlackListedColors[i])) then
Continue;
if(dtmSubPoints[1].Color = BlackListedColors[i]) then
repeat
writeln('222');
writeln(BlackListedColors[i]);
TP1.x := TP.x - randomrange(-5,15);
TP1.y := TP.y - randomrange(-5,15);
SMART_DrawDot(False,TP1,clPurple);
dtmSubPoints[1].x := TP1.x;
dtmSubPoints[1].y := TP1.y;
dtmSubPoints[1].AreaSize := 0;
dtmSubPoints[1].AreaShape := 0;
dtmSubPoints[1].Color := GetColor(TP1.x,TP1.y);
BlackListedColors[2] := GetColor(TP1.x,TP1.y);
dtmSubPoints[1].Tolerance := tolerance;
until(not(dtmSubPoints[1].Color = BlackListedColors[i]))
end;
for i := 0 to High(BlackListedColors) do
begin
TP1.x := TP.x - randomrange(-15,15);
TP1.y := TP.y - randomrange(-15,15);
SMART_DrawDot(False,TP1,clPurple);
dtmSubPoints[2].x := TP1.x;
dtmSubPoints[2].y := TP1.y;
dtmSubPoints[2].AreaSize := 0;
dtmSubPoints[2].AreaShape := 0;
dtmSubPoints[2].Color := GetColor(TP1.x,TP1.y);
dtmSubPoints[2].Tolerance := tolerance;
if(dtmSubPoints[2].Color = BlackListedColors[i]) then
repeat
TP1.x := TP.x - randomrange(-15,15);
TP1.y := TP.y - randomrange(-15,15);
SMART_DrawDot(False,TP1,clPurple);
dtmSubPoints[2].x := TP1.x;
dtmSubPoints[2].y := TP1.y;
dtmSubPoints[2].AreaSize := 0;
dtmSubPoints[2].AreaShape := 0;
dtmSubPoints[2].Color := GetColor(TP1.x,TP1.y);
dtmSubPoints[2].Tolerance := tolerance;
until(not(dtmSubPoints[2].Color = BlackListedColors[i]))
end;
SMART_DrawDot(False,TP1,clPurple);
TempTDTM.MainPoint := dtmMainPoint;
TempTDTM.SubPoints := dtmSubPoints;
Result := AddDTM(TempTDTM);
end; That's my DDTM code, but I'm having trouble getting it to be accurate. D:
What should I set the tolerance to, or change in the points, or even findDTMRotated(), what should the parameters be for that?
I've been trying for two days, and it keeps messing up, no matter what I do. :(