"Smooth Rainbow" magic tool (variant of "Rainbow")

Numerous people commented on Twitter that a piece of artwork
("Chromie Squiggle #7583", created in "ArtBlocks") looked like it
was made in Tux Paint.

However, the classic (2002-era) "Rainbow" tool cycled coarsely
through solid colors.  This adds a gradient.
This commit is contained in:
Bill Kendrick 2021-09-22 23:01:26 -07:00
parent 1d5dd8eb9f
commit 8b30a278c2
9 changed files with 73 additions and 10 deletions

View file

@ -23,7 +23,7 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
(See COPYING.txt)
Last updated: September 21, 2021
Last updated: September 22, 2021
$Id$
*/
@ -63,7 +63,9 @@ static const int rainbow_hexes[NUM_RAINBOW_COLORS][3] = {
{255, 0, 64}
};
static int rainbow_color;
#define MIX_MAX 32
static int rainbow_color, rainbow_mix;
static Uint32 rainbow_rgb;
static Mix_Chunk *rainbow_snd;
@ -105,6 +107,7 @@ int rainbow_init(magic_api * api)
rainbow_color = 0;
rainbow_mix = 0;
snprintf(fname, sizeof(fname), "%s/sounds/magic/rainbow.wav", api->data_directory);
rainbow_snd = Mix_LoadWAV(fname);
@ -115,7 +118,7 @@ int rainbow_init(magic_api * api)
// We have multiple tools:
int rainbow_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
{
return (1);
return (2);
}
// Load our icons:
@ -131,7 +134,11 @@ SDL_Surface *rainbow_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
// Return our names, localized:
char *rainbow_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
{
return (strdup(gettext_noop("Rainbow")));
if (which == 0) {
return (strdup(gettext_noop("Rainbow")));
} else {
return (strdup(gettext_noop("Smooth Rainbow")));
}
}
// Return our group:
@ -170,10 +177,33 @@ static void rainbow_linecb(void *ptr, int which ATTRIBUTE_UNUSED,
void rainbow_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect)
{
rainbow_color = (rainbow_color + 1) % NUM_RAINBOW_COLORS;
Uint8 r1, g1, b1, r2, g2, b2;
int rc_tmp;
if (which == 1) {
rainbow_mix += 1;
if (rainbow_mix > MIX_MAX) {
rainbow_mix = 0;
rainbow_color = (rainbow_color + 1) % NUM_RAINBOW_COLORS;
}
} else {
rainbow_mix = 0;
rainbow_color = (rainbow_color + 1) % NUM_RAINBOW_COLORS;
}
r1 = rainbow_hexes[rainbow_color][0];
g1 = rainbow_hexes[rainbow_color][1];
b1 = rainbow_hexes[rainbow_color][2];
rc_tmp = (rainbow_color + 1) % NUM_RAINBOW_COLORS;
r2 = rainbow_hexes[rc_tmp][0];
g2 = rainbow_hexes[rc_tmp][1];
b2 = rainbow_hexes[rc_tmp][2];
rainbow_rgb = SDL_MapRGB(canvas->format,
rainbow_hexes[rainbow_color][0],
rainbow_hexes[rainbow_color][1], rainbow_hexes[rainbow_color][2]);
((r1 * (MIX_MAX - rainbow_mix)) + (r2 * rainbow_mix)) / MIX_MAX,
((g1 * (MIX_MAX - rainbow_mix)) + (g2 * rainbow_mix)) / MIX_MAX,
((b1 * (MIX_MAX - rainbow_mix)) + (b2 * rainbow_mix)) / MIX_MAX);
api->line((void *)api, which, canvas, last, ox, oy, x, y, 1, rainbow_linecb);