n3ss3s
2007-12-16 14:23:34
I made couple very very similar functions, and then one a little more unique.
You should all be able to see from the code what it does, though if you have questions just ask…
type
TColorArrayInfo = record
Amount, Color: Integer;
End;
////////////////////////////////////////////////////////////////////////////////
Function FindColorDegreesTol(Var Cx, Cy: Integer; Col, MidX, MidY, SD, ED, Dist, Tol: Integer): Boolean;
Var
x1, y1, x2, y2, x, y, I, L: Integer;
pts: TPointArray;
z: Extended;
Begin
x1 := MidX - Dist;
y1 := MidY - Dist;
x2 := MidX + Dist;
y2 := MidY + Dist;
FindColorsSpiralTolerance(MidX, MidY, pts, Col, x1, y1, x2, y2, Tol);
L := High(pts);
For I := 0 To L Do
Begin
If Not InCircle(pts[i].x, pts[i].y, MidX, MidY, Dist) Then Continue;
x := pts[i].x - MidX;
y := pts[i].y - MidY;
z := Round(ArcTan(y / x));
If (z > SD) And (z < ED) Then
Begin
cx := x;
cy := y;
Result := True;
Exit;
End;
End;
End;
Function FindColorDegreesTolEx(Var Cx, Cy, Angle, tDist: Integer; Col, MidX, MidY, SD, ED, Dist, Tol: Integer): Boolean;
Var
x1, y1, x2, y2, x, y, I, L, z: Integer;
pts: TPointArray;
Begin
x1 := MidX - Dist;
y1 := MidY - Dist;
x2 := MidX + Dist;
y2 := MidY + Dist;
FindColorsSpiralTolerance(MidX, MidY, pts, Col, x1, y1, x2, y2, Tol);
L := High(pts);
For I := 0 To L Do
Begin
If Not InCircle(pts[i].x, pts[i].y, MidX, MidY, Dist) Then Continue;
x := pts[i].x - MidX;
y := pts[i].y - MidY;
z := Round(ArcTan(y / x));
If (z > SD) And (z < ED) Then
Begin
cx := x;
cy := y;
Angle := z;
tDist := Distance(MidX, MidY, cx, cy);
Result := True;
Exit;
End;
End;
End;
Function FindColorDegreesTol2(Var Cx, Cy: Integer; Col, MidX, MidY, SD, ED, MinDist, MaxDist, Tol: Integer): Boolean;
Var
x1, y1, x2, y2, x, y, I, L: Integer;
pts: TPointArray;
z: Extended;
Begin
x1 := MidX - MaxDist;
y1 := MidY - MaxDist;
x2 := MidX + MaxDist;
y2 := MidY + MaxDist;
FindColorsSpiralTolerance(MidX, MidY, pts, Col, x1, y1, x2, y2, Tol);
L := High(pts);
For I := 0 To L Do
Begin
If Not InCircle(pts[i].x, pts[i].y, MidX, MidY, MaxDist) Then
Continue;
If Not InRange(Distance(pts[i].x, pts[i].y, MidX, MidY), MinDist, MaxDist) Then
Continue;
x := pts[i].x - MidX;
y := pts[i].y - MidY;
z := Round(ArcTan(y / x));
If (z > SD) And (z < ED) Then
Begin
cx := x;
cy := y;
Result := True;
Exit;
End;
End;
End;
////////////////////////////////////////////////////////////////////////////////
Function ScanCircle(SD, ED, MidX, MidY, Radius: Integer): Array of TColorArrayInfo;
Var
X, Y, I, C, S: Integer;
Exists: Boolean;
Begin
For I := SD To ED Do
Begin
Exists := False;
X := MidX + Round(Radius * Cos(i - 90));
Y := MidY + Round(Radius * Sin(i - 90));
For C := 0 To High(Result) Do
Begin
If Result[i].Color = GetColor(X, Y) Then
Begin
Exists := True;
S := C;
Break;
End;
End;
If Not Exists Then
Begin
SetArrayLength(Result, GetArrayLength(Result) + 1);
Result[High(Result)].Color := GetColor(X, Y);
Result[High(Result)].Amount := 1;
End Else
Begin
Result[s].Amount := Result[s].Amount + 1;
End;
End;
End;
You should all be able to see from the code what it does, though if you have questions just ask…