Results 1 to 11 of 11

Thread: Fizzi's Compass Angle Function

  1. #1
    Join Date
    Jun 2007
    Location
    New Jersey, USA
    Posts
    123
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default Fizzi's Compass Angle Function

    Well, the function by Freddy isn't working atm (always returns as 268), and we need it badly for KYAB. I didn't feel like waiting, so I made my own.

    I'll add a description for how it works soon, need to do something first tho .
    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;
    My Scripts:
    Rimmington Soft Clay Farmer 2.0 - Makes approx. 40k gold per hour. Mines clay, softens it, and banks it.

  2. #2
    Join Date
    Jan 2007
    Location
    Kansas
    Posts
    3,760
    Mentioned
    1 Post(s)
    Quoted
    3 Post(s)

    Default

    Very nice again, and I will say it again, you are an amazing scripter. This was needed. I have not tested yet but I'm sure it works. Even if it doesn't that is some great code.


  3. #3
    Join Date
    Nov 2006
    Location
    NSW, Australia
    Posts
    3,487
    Mentioned
    1 Post(s)
    Quoted
    0 Post(s)

    Default

    SCAR Code:
    if not(FindColor(xt, yt, 920735, 561-2, 3+1, 561+2, 3+5)) then
        begin

    Erm..instead of 561 - 2 couldn't you just do 559, and so on?
    [CENTER][img]http://signatures.mylivesignature.com/54486/113/4539C8FAAF3EAB109A3CC1811EF0941B.png[/img][/CENTER]
    [CENTER][BANANA]TSN ~ Vacation! ~ says :I Love Santy[/BANANA][/CENTER]

    [CENTER][BANANA]Raymond - Oh rilie? says :Your smart[/BANANA][/CENTER]

  4. #4
    Join Date
    Apr 2007
    Location
    Australia
    Posts
    4,163
    Mentioned
    9 Post(s)
    Quoted
    19 Post(s)

    Default

    Good stuff. We're learning about the unit circle and trig equations atm in school, so give it a week and I'll be able to do this stuff too, lol.

  5. #5
    Join Date
    Apr 2007
    Location
    Perth, Australia
    Posts
    3,926
    Mentioned
    3 Post(s)
    Quoted
    2 Post(s)

    Default

    Lol they're easy. Just wait until you get to Year 11 and start with Trig Identities and Solving trig equations....

    Oh and BTW, I'm testing it right now.

  6. #6
    Join Date
    Dec 2006
    Location
    utah
    Posts
    1,427
    Mentioned
    2 Post(s)
    Quoted
    7 Post(s)

    Default

    Heres Mine I Like It...
    SCAR Code:
    function DetectCompassAngle : Extended;
    var
      P : TPointArray;
      I, Mx, My, Midx, Midy, L : Integer;
    begin
     Midx :=561;
     Midy :=20;
     FindColorsTolerance(P, 1911089, 539, 0, 581, 38, 0);
     L := Length(P);
     if (l = 0) then exit;
     for i := 0 to L-1 do
     begin
        Mx := Mx + P[i].x;
        My := My + P[i].y;
     end;
     Mx := Mx / L;
     My := My / L;
     Result := FixD(FixD(Degrees(ArcTan2( my - midy,  mx - midx))) + 90);
    end;
    Co Founder of https://www.tagcandy.com

  7. #7
    Join Date
    Apr 2007
    Location
    Australia
    Posts
    4,163
    Mentioned
    9 Post(s)
    Quoted
    19 Post(s)

    Default

    Quote Originally Posted by ZephyrsFury View Post
    Lol they're easy. Just wait until you get to Year 11 and start with Trig Identities and Solving trig equations....

    Oh and BTW, I'm testing it right now.
    I'm in year 11, and we just learnt those today lolz. And you're right, they are pretty easy

  8. #8
    Join Date
    Jun 2007
    Location
    New Jersey, USA
    Posts
    123
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by SantaClause View Post
    SCAR Code:
    if not(FindColor(xt, yt, 920735, 561-2, 3+1, 561+2, 3+5)) then
        begin

    Erm..instead of 561 - 2 couldn't you just do 559, and so on?
    Yes, I did the additions/subtractions just cause it made it easier for me to see if I made any mistakes.
    My Scripts:
    Rimmington Soft Clay Farmer 2.0 - Makes approx. 40k gold per hour. Mines clay, softens it, and banks it.

  9. #9
    Join Date
    Feb 2006
    Location
    Belgium
    Posts
    3,137
    Mentioned
    3 Post(s)
    Quoted
    5 Post(s)

    Default

    Mine works very well, but in SCAR 3.12 which will be one of the biggest updates so far

  10. #10
    Join Date
    Feb 2006
    Location
    Helsinki, Finland
    Posts
    1,395
    Mentioned
    30 Post(s)
    Quoted
    107 Post(s)

    Default

    Quote Originally Posted by Freddy1990 View Post
    Mine works very well, but in SCAR 3.12 which will be one of the biggest updates so far
    I can't wait. (I know, I just have to)

  11. #11
    Join Date
    Jun 2007
    Location
    New Jersey, USA
    Posts
    123
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by SKy Scripter View Post
    Heres Mine I Like It...
    SCAR Code:
    function DetectCompassAngle : Extended;
    var
      P : TPointArray;
      I, Mx, My, Midx, Midy, L : Integer;
    begin
     Midx :=561;
     Midy :=20;
     FindColorsTolerance(P, 1911089, 539, 0, 581, 38, 0);
     L := Length(P);
     if (l = 0) then exit;
     for i := 0 to L-1 do
     begin
        Mx := Mx + P[i].x;
        My := My + P[i].y;
     end;
     Mx := Mx / L;
     My := My / L;
     Result := FixD(FixD(Degrees(ArcTan2( my - midy,  mx - midx))) + 90);
    end;
    I think yours wins Sky
    My Scripts:
    Rimmington Soft Clay Farmer 2.0 - Makes approx. 40k gold per hour. Mines clay, softens it, and banks it.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •