20.03.2015, 15:26
pawn Код:
enum E_COLOUR_STOPS
{
CS_COLOUR,
CS_PERCENT
}
CreateMultiGradient(const colour_stops[][E_COLOUR_STOPS], colours[], stops = sizeof colour_stops, size = sizeof colours)
{
if (size < stops) {
return printf("You need at least %d slots in your resulting array", stops);
}
new
offset = 1,
total
;
CreateGradient(colours, colour_stops[0][CS_COLOUR], colour_stops[0][CS_COLOUR], 1);
for (new i = 1; i != stops; ++i) {
total = floatround(size * (colour_stops[i][CS_PERCENT] * 0.01));
CreateGradient(colours, colour_stops[i - 1][CS_COLOUR], colour_stops[i][CS_COLOUR], total, offset);
offset += total;
}
return 1;
}
#define RGBA(%0,%1,%2,%3) ((((%0) & 0xFF) << 24) | (((%1) & 0xFF) << 16) | (((%2) & 0xFF) << 8) | (((%3) & 0xFF) << 0))
CreateGradient(colors[], start_color, end_color, total = sizeof colors, offset = 0)
{
new red, green, blue, Float:start_r, Float:start_g, Float:start_b, Float:end_r, Float:end_g, Float:end_b;
start_r = float(((start_color >> 16) & 0xFF));
start_g = float(((start_color >> 8) & 0xFF));
start_b = float(((start_color) & 0xFF));
end_r = float(((end_color >> 16) & 0xFF));
end_g = float(((end_color >> 8) & 0xFF));
end_b = float(((end_color) & 0xFF));
for(new i = 0; i < total - offset; i++)
{
red = floatround(start_r - (start_r-end_r) * (float(i) / (float(total-1))));
green = floatround(start_g - (start_g-end_g) * (float(i) / (float(total-1))));
blue = floatround(start_b - (start_b-end_b) * (float(i) / (float(total-1))));
colors[offset + i] = RGBA(red, green, blue, 0xFF);
}
return 1;
}
public OnGameModeInit()
{
new
arr[26],
stops[3][E_COLOUR_STOPS] = {
{ 0xBADA55, 0 },
{ 0x000000, 75 },
{ 0xBADA55, 100 }
}
;
CreateMultiGradient(stops, arr);
for (new i = 0; i != sizeof arr - 1; ++i) {
printf("%x", arr[i]);
}
return 1;
}