SCAR Code:
//Returns the compass angle in degrees going clockwise. By Fizzi
function FizCompassAngle : integer;
var
x1, y1, x2, y2, x3, y3, x4, y4, dx, dy, xt, yt : integer;
StartAngle, PerfectTest, theta : integer;
UseQ3 : boolean;
begin
//Quadrant 1: 562, 3 to 578, 19
//Quadrant 2: 544, 3 to 560, 19
//Quadrant 3: 544, 21 to 560, 38
//Quadrant 4: 562, 21 to 578, 38
//center : 561, 20
PerfectTest := 4;
if FindColorSkipBox(x1, y1, 920735, 562, 2, 579, 19, IntToBox(561, 11, 566, 20)) then
begin
Writeln('Found point in Quadrant 1');
PerfectTest := PerfectTest - 1;
end;
if FindColorSkipBox(x2, y2, 920735, 543, 2, 560, 19, IntToBox(552, 11, 561, 20)) then
begin
Writeln('Found point in Quadrant 2');
PerfectTest := PerfectTest - 1;
end;
if FindColorSkipBox(x3, y3, 920735, 543, 21, 560, 39, IntToBox(552, 20, 561, 26)) then
begin
Writeln('Found point in Quadrant 3');
PerfectTest := PerfectTest - 1;
end;
if FindColorSkipBox(x4, y4, 920735, 562, 21, 579, 39, IntToBox(561, 20, 566, 26)) then
begin
Writeln('Found point in Quadrant 4');
PerfectTest := PerfectTest - 1;
end;
if(PerfectTest > 1) then
begin
if not(FindColor(xt, yt, 920735, 561-2, 3+1, 561+2, 3+5)) then
begin
Writeln('Found perfect angle 0!');
Result := 0;
Exit;
end;
if not(FindColor(xt, yt, 920735, 578-5, 20-2, 578+1, 20+2)) then
begin
Writeln('Found perfect angle 90!');
Result := 90;
Exit;
end;
if not(FindColor(xt, yt, 920735, 561-2, 38-5, 561+2, 38+1)) then
begin
Writeln('Found perfect angle 180!');
Result := 180;
Exit;
end;
if not(FindColor(xt, yt, 920735, 544-1, 20-2, 544+5, 20+2)) then
begin
Writeln('Found perfect angle 270!');
Result := 270;
Exit;
end;
end else
begin
if(x1 = 0) and (y1 = 0) then
begin
StartAngle := 0;
UseQ3 := True;
end;
if(x2 = 0) and (y2 = 0) then StartAngle := 270;
if(x3 = 0) and (y3 = 0) then StartAngle := 180;
if(x4 = 0) and (y4 = 0) then StartAngle := 90;
if not(UseQ3) then
begin
dx := x1 - 561;
dy := y1 - 20;
theta := (Round(Degrees(ArcTan(dx/dy))))*(-1);
Writeln('Found tilted angle ' + inttostr(StartAngle + theta) + '!');
Result := (StartAngle + theta);
Exit;
end else
begin
dx := 561 - x3;
dy := 20 - y3;
theta := (Round(Degrees(ArcTan(dx/dy))))*(-1);
Writeln('Found tilted angle ' + inttostr(StartAngle + theta) + '!');
Result := (StartAngle + theta);
Exit;
end;
end;
Result := -1;
end;