stock ColorBetween(ColorA, ColorB, Float:Percent)
{
new R1, G1, B1, A1, R2, G2, B2, A2;
HexToInt(ColorA, R1, G1, B1, A1);
HexToInt(ColorB, R2, G2, B2, A2);
return IntToHex(
floatround(Percent * (R2-R1)) + R1,
floatround(Percent * (G2-G1)) + G1,
floatround(Percent * (B2-B1)) + B1,
floatround(Percent * (A2-A1)) + A1
);
}
stock HexToInt(hexcolor, &r, &g, &b, &a)
{
r = ( hexcolor >> 32 ) & 0xFF;
g = ( hexcolor >> 16 ) & 0xFF;
b = ( hexcolor >> 8 ) & 0xFF;
a = hexcolor & 0xFF;
}
stock IntToHex(r, g, b, a = 255, &hexcolor = -1)
{
hexcolor = (r*16777216)+(g*65536)+(b*256)+a;
return hexcolor;
}
stock ColorBetween(ColorA, ColorB) {
new str[11];
valstr(str,ColorA);
new x = strval(str);
valstr(str,ColorB);
new y = strval(str);
return x-y;
}
printf("0x%x",ColorBetween(0xF, 0xA));
//-> Gives u 0x5
|
Just make sth like this:
Код:
stock ColorBetween(ColorA, ColorB) {
new str[11];
valstr(str,ColorA);
new x = strval(str);
valstr(str,ColorB);
new y = strval(str);
return x-y;
}
printf("0x%x",ColorBetween(0xF, 0xA));
//-> Gives u 0x5
![]() |
|
At the very least, the right shift in your HexToInt function for red is wrong. This should be 24. Also you should use the logical right shift (>>>, three shevrons) instead of the arithmetic right shift (>>). With the arithmetic right shift the number will be padded with the value of the MSB, so if you try to shift anything with a red value greater than 7F the number will be padded with 1 in the front and you will end up with very weird results.
|
|
I always have sucked with shifts. Could you show me what you mean?
|
stock HexToInt(hexcolor, &r, &g, &b, &a)
{
r = ( hexcolor >> 24) & 0xFF;
g = ( hexcolor >> 16 ) & 0xFF;
b = ( hexcolor >> 8 ) & 0xFF;
a = hexcolor & 0xFF;
}
stock HexToInt(hexcolor, &r, &g, &b, &a)
{
r = ( hexcolor >>> 24) & 0xFF;
g = ( hexcolor >>> 16 ) & 0xFF;
b = ( hexcolor >>> 8 ) & 0xFF;
a = hexcolor & 0xFF;
}
|
Not an option at the moment.
I always have sucked with shifts. Could you show me what you mean? |
FF7F3F1F // hex 11111111 01111111 00111111 00011111 ^ Most significant bit (MSB) Arithmetic right shift by 24: 11111111 11111111 11111111 11111111 ^^^^^^^^ ^^^^^^^^ ^^^^^^^^ padding is the value of the MSB (1) Logical right shift by 24: 00000000 00000000 00000000 11111111 ^^^^^^^^ ^^^^^^^^ ^^^^^^^^ padding is just 0
|
Edit: I didn't pay attention to the "& 0xFF". In any case that should only select the lower 8 bits, no matter what kind of shift is used.
![]() |
stock GenerateGradient(...)
{
new Colors[263], Steps = (263/numargs()), Color[263];
for(new i; i<numargs()-1; i++)
{
ColorsBetween(getarg(i), getarg(i+1), Steps, Color);
for(new j; j<Steps; j++) Colors[(i*Steps)+j] = Color[j];
}
return Colors;
}