Jump to content
LordJashin

Colors & Tolerance Examples

Recommended Posts

Made this way back when I was testing/learning about Colors and Tolerance. I've yet to expand this to arrays but w/e.

 

Learn from this code, just run it in SCAR and then read the debug box, go through the code, and the comments. I could sum it up here, but the code proves it, and could be a good resource to use later.

 

[sCAR]

program ColorsAndTolerance;

var

C, w, h, bmp: Integer;

// x, y: Integer;

 

procedure SetupBitmapDebug;

begin

ClearDebug;

bmp := BitmapFromString(45, 38, 'ceNrdWAdQVNcaXkACUYyDJ' + 'FiRtpQFXRaWJlVBQEBcisLuKkrQKIoaAy9oREFRWZQqRKoLAYUnI' +'MXCC+KzEDUjSrBgVCxBqYpolHpE4X//vSjjmOSxljxn3p0zd86ee' +'+5/vvvX718G430vKSmGk8MEKcbHvGRlpcVp5kCEmzZM/VgY5OVlD' + 'h6wQQxw33OgWxAYoP1RMJQfngm9QqieBaWm8PPMFx0+vDmT/5cYR' +'oyQLi6whh4BVFhCnBYkaEE2G5E8fTBfnzXmAx408lMZgY+ajZWy6' +'pRRMjJvOmByogn0CuDMDEjVg+1qIFKHDH04ZAZ1LtcuzRmtMOJDw' +'TAyHEsZvVcw0CvoeuRdU+Wcnmz6lT9TQ12B763a3yO4ecIuP1QnZ' +'sGkiLnKMfPH53+jUZdj3H/FCZ54J8UbfygY/PmqFIwaByi3gKMWc' +'M4Obs+Bx/NTk0wQjN8iXdFW34qyxLrafzbd2VtXG32szE+0zchPq' +'B6+YWrDLZ6O9mdZGeZVp52KC2zWf6vHYStKvVNIfxvEomAUGUMyC' +'9L04AD3eaVtVAhr5TK9G1digdwE8hhIB5BHQBqB3ABSA6QcyNa62' +'rkYMizdzzrbvSkJnXzoRpUKr1+eEx46TUVl1FvB2BXLhQ4fSNKBc' +'BVI0G4TGwhdJpys8KDPugrkNyBNQFrp+x165TyQU0DKgKQAWVx5b' + 'JbAR/VBoyc0u8N5ezg7g1Jmj+B5F7+kwMba8gsJlZMjno7ZAHbrQ' + 'rxWW6Ket+P4xtt8ICVAzgD5hT63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qg9LBQoEZ32VJeHiqnTzgMhs/cv7PHHzlyx' + 'KXzzhQfuGAPT3062r3dXCe98ReQAVsxIowtYcJ854upqTAYL/V1P' + 'I6B4kf8x8nGShlz2hefyzH+X67/ACjydsU=');

w := 300;

h := 300;

bmp := ResizeBitmap(bmp, w, h);

DebugBitmap(bmp);

FindWindowTitlePart('Debug Image', false);

ActivateClient;

wait(1000);

end;

 

begin

SetupBitmapDebug;

//PickColor(C, x, y); Allows user to pick color using SCAR's color picker tool

 

// Get Color, Count Color

C := GetColor(100, 100); // Gets the color at coords

MoveWindMouse(100, 100, 2, 2);

WriteLn('C = Color at (100, 100) = ' + IntToStr©);

WriteLn('Counted color C: ' + IntToStr(CountColor(C, 0, 0, w - 1, h - 1)) + ' times'); // Counts the color

 

//Set Tolerance Algorithm/Find which algorithm we are using

WriteLn('Default Color Tolerance Speed: ' + IntToStr(GetColorToleranceSpeed));

ColorToleranceSpeed(1); // Changes the color tolerance speed

 

// GetTol between 2 colors using current algo, Are 2 colors in this range of tol, counting colors with tol

WriteLn('The tolerance between C and C + 28 = ' + IntToStr(GetTolerance(C, C + 28)));

WriteLn('The tolerance between C and C + 29 = ' + IntToStr(GetTolerance(C, C + 29)));

WriteLn('Set at Tol 28, C and C + 28 are they in the tol range = ' + BoolToStr(SimilarColors(C, C + 28, 28)));

WriteLn('Counting Color C at Tol 28: ' + IntToStr(CountColorTolerance(C, 0, 0, w - 1, h - 1, 28)));

 

//Get Closest color to 100 out of this array of colors and return it (Array is a TIntArray)

WriteLn('Closest Color to the 100 color out of this array using current tol algorithm = ' + IntToStr(GetClosestColor(100, [97, 98, 101])));

 

wait(5000);

FreeBitmap(bmp);

HideDebugImgWindow;

end.

[/sCAR]

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
  • Create New...