[Library] Similar hexes - Printable Version + open.mp forum (https://forum.open.mp) -- Forum: SA-MP (https://forum.open.mp/forumdisplay.php?fid=3) --- Forum: Releases (https://forum.open.mp/forumdisplay.php?fid=13) ---- Forum: Libraries (https://forum.open.mp/forumdisplay.php?fid=31) ---- Thread: [Library] Similar hexes (/showthread.php?tid=1200) |
Similar hexes - Kwarde - 2020-10-02 This is more of a snippet than a library. However, it holds these functions (they all depend on each other): has_alpha(color) Checks if HEX (read: integer) input is RRGGBBAA. Does not work properly for other formats (except RRGGBB). For example, AARRGG would return 0/false. PHP Code: if (has_alpha(0xFF0990AA)) strip_alpha(color) Strips alpha from HEX if it has any (relies on has_alpha()). Like with has_alpha, inputting AARRGGBB would output AARRGG. PHP Code: new const colors[] = { similar_hexes(hex_a, hex_b, difference = 150) This checks if two hexes are alike color-wise. Difference parameter can be used to increase or decrease the difference check in both colors. Some colors might return false while they are pretty similar and some might return true while they aren't quite similar. Most of the tests I did turned out pretty okay, though. PHP Code: #define COLOR_RED 0xFF0000FF The functions: PHP Code: bool:has_alpha(color) |