New magic tools: Circles, and Rays

Convert the image into circular or ray brushstrokes.

Inspired by "Night Sky Scene [Pen Parallax]" Scratch Project
by -HexaScape- <https://scratch.mit.edu/users/-HexaScape->

Sound effects based on Richard Wagner's "Ride of the Valkyries"
licensed as Creative Commons Attribution 3.0 Unported (CC BY 3.0)
by https://pmmusic.pro/; conducted by Philip Milman.

h/t my son William for pointing out the Scratch project
This commit is contained in:
Bill Kendrick 2023-01-28 23:12:28 -08:00
parent 7f93f243c1
commit b9e5d59dad
37 changed files with 674 additions and 2 deletions

View file

@ -6,7 +6,7 @@ Copyright (c) 2002-2023
Various contributors (see below, and CHANGES.txt)
https://tuxpaint.org/
June 17, 2002 - January 26, 2023
June 17, 2002 - January 28, 2023
* Design and Coding:
@ -115,6 +115,17 @@ June 17, 2002 - January 26, 2023
(https://freesound.org/people/SpliceSound/sounds/369834/)
Creative Commons 0 by Julian Evans <https://www.julianevans.info/>
Circles and Rays magic tools and artwork
by Bill Kendrick <bill@newbreedsoftware.com>
Inspired by "Night Sky Scene [Pen Parallax]" Scratch Project
by -HexaScape- <https://scratch.mit.edu/users/-HexaScape->.
Sound effect based on Richard Wagner's "Ride of the Valkyries"
licensed as Creative Commons Attribution 3.0 Unported (CC BY 3.0)
(https://creativecommons.org/licenses/by/3.0/)
by https://pmmusic.pro/; conducted by Philip Milman.
(Why? Because Van Gogh liked Wagner:
https://yalebooks.yale.edu/book/9780300228335/van-gogh-and-music/)
Mouse accessibility code and keyboard access
Ankit Choudary <ankit.goaldecided@gmail.com>, as part of GSOC 2010,
with integration and fixes by Pere Pujal i Carabantes <pere@fornol.no-ip.org>

View file

@ -7,7 +7,7 @@ Various contributors (see below, and AUTHORS.txt)
https://tuxpaint.org/
2022.January.26 (0.9.29)
2022.January.28 (0.9.29)
* Improvements to "Stamp" tool:
-----------------------------
* Stamps may now be rotated.
@ -25,11 +25,22 @@ https://tuxpaint.org/
- needs better icon
- needs sound effect
- effect needs improvement
Bill Kendrick <bill@newbreedsoftware.com>
* "Maze"; draw a maze pattern over part or all of your drawing.
Bill Kendrick <bill@newbreedsoftware.com>
(Sound effect licensed as Creative Commons 0 by
Julian Evans, https://www.julianevans.info/)
* "Circles" and "Rays"; convert the image into circular or ray
brushstrokes.
Bill Kendrick <bill@newbreedsoftware.com>
(Inspired by "Night Sky Scene [Pen Parallax]" Scratch Project
by -HexaScape- <https://scratch.mit.edu/users/-HexaScape->)
(Sound effect based on Richard Wagner's "Ride of the Valkyries"
licensed as Creative Commons Attribution 3.0 Unported (CC BY 3.0)
by https://pmmusic.pro/; conducted by Philip Milman)
* Improvements to Magic Tools:
----------------------------
* Better performance from "Rush" (by using SDL_gfx rotozoom)

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

BIN
magic/icons/swirls_rays.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

View file

@ -0,0 +1,14 @@
Tux Paint "Magic" Tool: Circles
Group: Distorts
Author: Bill Kendrick <bill@newbreedsoftware.com>
This transforms the picture into circular brush strokes around where you
clicked.
See also: Rays.
----------------------------------------------------------------------
Tux Paint 0.9.29

View file

@ -0,0 +1,14 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<body><html><head><title>Tux Paint "Magic" Tool: Circles</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#FF0000" alink="#FF00FF">
<h1 align="center">Tux Paint "Magic" Tool: Circles</h1>
<h2 align="center">Group: Distorts</h2>
<h3 align="center">Author:
Bill Kendrick &lt;<a href="mailto:bill@newbreedsoftware.com">bill@newbreedsoftware.com</a>&gt;</h3>
<p>This transforms the picture into circular brush strokes around where you clicked.</p>
<p>See also: <a href="rays.html">Rays</a>.</p>
<hr size="1" noshade />
<p align="center">Tux Paint 0.9.29</p>
</body></html>

View file

@ -9,6 +9,7 @@
<li><a href="blocks.html">Blocks</a></li>
<li><a href="blur.html">Blur</a></li>
<li><a href="chalk.html">Chalk</a></li>
<li><a href="circles.html">Circles</a></li>
<li><a href="clone.html">Clone</a></li>
<li><a href="distortion.html">Distortion</a></li>
<li><a href="drip.html">Drip</a></li>
@ -22,6 +23,7 @@
<li><a href="mosaic.html">Mosaic</a></li>
<li><a href="noise.html">Noise</a></li>
<li><a href="puzzle.html">Puzzle</a></li>
<li><a href="rays.html">Rays</a></li>
<li><a href="ripples.html">Ripples</a></li>
<li><a href="sharpen.html">Sharpen</a></li>
<li><a href="silhouette.html">Silhouette</a></li>

View file

@ -0,0 +1,14 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<body><html><head><title>Tux Paint "Magic" Tool: Rays</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#FF0000" alink="#FF00FF">
<h1 align="center">Tux Paint "Magic" Tool: Rays</h1>
<h2 align="center">Group: Distorts</h2>
<h3 align="center">Author:
Bill Kendrick &lt;<a href="mailto:bill@newbreedsoftware.com">bill@newbreedsoftware.com</a>&gt;</h3>
<p>This transforms the picture into brush strokes that point towards where you clicked.</p>
<p>See also: <a href="circles.html">Circles</a>.</p>
<hr size="1" noshade />
<p align="center">Tux Paint 0.9.29</p>
</body></html>

View file

@ -5,6 +5,7 @@ Distorts
* Blocks
* Blur
* Chalk
* Circles
* Clone
* Distortion
* Drip
@ -18,6 +19,7 @@ Distorts
* Mosaic
* Noise
* Puzzle
* Rays
* Ripples
* Sharpen
* Silhouette

View file

@ -0,0 +1,14 @@
Tux Paint "Magic" Tool: Rays
Group: Distorts
Author: Bill Kendrick <bill@newbreedsoftware.com>
This transforms the picture into brush strokes that point towards where
you clicked.
See also: Circles.
----------------------------------------------------------------------
Tux Paint 0.9.29

View file

@ -0,0 +1,14 @@
Tux Paint "Magic" Tool: Circles
Group: Distorts
Author: Bill Kendrick <bill@newbreedsoftware.com>
This transforms the picture into circular brush strokes around where you
clicked.
See also: Rays.
----------------------------------------------------------------------
Tux Paint 0.9.29

View file

@ -0,0 +1,14 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<body><html><head><title>Tux Paint "Magic" Tool: Circles</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#FF0000" alink="#FF00FF">
<h1 align="center">Tux Paint "Magic" Tool: Circles</h1>
<h2 align="center">Group: Distorts</h2>
<h3 align="center">Author:
Bill Kendrick &lt;<a href="mailto:bill@newbreedsoftware.com">bill@newbreedsoftware.com</a>&gt;</h3>
<p>This transforms the picture into circular brush strokes around where you clicked.</p>
<p>See also: <a href="rays.html">Rays</a>.</p>
<hr size="1" noshade />
<p align="center">Tux Paint 0.9.29</p>
</body></html>

View file

@ -9,6 +9,7 @@
<li><a href="blocks.html">Blocks</a></li>
<li><a href="blur.html">Blur</a></li>
<li><a href="chalk.html">Chalk</a></li>
<li><a href="circles.html">Circles</a></li>
<li><a href="clone.html">Clone</a></li>
<li><a href="distortion.html">Distortion</a></li>
<li><a href="drip.html">Drip</a></li>
@ -22,6 +23,7 @@
<li><a href="mosaic.html">Mosaic</a></li>
<li><a href="noise.html">Noise</a></li>
<li><a href="puzzle.html">Puzzle</a></li>
<li><a href="rays.html">Rays</a></li>
<li><a href="ripples.html">Ripples</a></li>
<li><a href="sharpen.html">Sharpen</a></li>
<li><a href="silhouette.html">Silhouette</a></li>

View file

@ -0,0 +1,14 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<body><html><head><title>Tux Paint "Magic" Tool: Rays</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#FF0000" alink="#FF00FF">
<h1 align="center">Tux Paint "Magic" Tool: Rays</h1>
<h2 align="center">Group: Distorts</h2>
<h3 align="center">Author:
Bill Kendrick &lt;<a href="mailto:bill@newbreedsoftware.com">bill@newbreedsoftware.com</a>&gt;</h3>
<p>This transforms the picture into brush strokes that point towards where you clicked.</p>
<p>See also: <a href="circles.html">Circles</a>.</p>
<hr size="1" noshade />
<p align="center">Tux Paint 0.9.29</p>
</body></html>

View file

@ -5,6 +5,7 @@ Distorts
* Blocks
* Blur
* Chalk
* Circles
* Clone
* Distortion
* Drip
@ -18,6 +19,7 @@ Distorts
* Mosaic
* Noise
* Puzzle
* Rays
* Ripples
* Sharpen
* Silhouette

View file

@ -0,0 +1,14 @@
Tux Paint "Magic" Tool: Rays
Group: Distorts
Author: Bill Kendrick <bill@newbreedsoftware.com>
This transforms the picture into brush strokes that point towards where
you clicked.
See also: Circles.
----------------------------------------------------------------------
Tux Paint 0.9.29

View file

@ -0,0 +1,14 @@
Tux Paint "Magic" Tool: Circles
Group: Distorts
Author: Bill Kendrick <bill@newbreedsoftware.com>
This transforms the picture into circular brush strokes around where you
clicked.
See also: Rays.
----------------------------------------------------------------------
Tux Paint 0.9.29

View file

@ -0,0 +1,14 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<body><html><head><title>Tux Paint "Magic" Tool: Circles</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#FF0000" alink="#FF00FF">
<h1 align="center">Tux Paint "Magic" Tool: Circles</h1>
<h2 align="center">Group: Distorts</h2>
<h3 align="center">Author:
Bill Kendrick &lt;<a href="mailto:bill@newbreedsoftware.com">bill@newbreedsoftware.com</a>&gt;</h3>
<p>This transforms the picture into circular brush strokes around where you clicked.</p>
<p>See also: <a href="rays.html">Rays</a>.</p>
<hr size="1" noshade />
<p align="center">Tux Paint 0.9.29</p>
</body></html>

View file

@ -7,6 +7,7 @@
<h2>Distorts</h2>
<ul>
<li><a href="blocks.html">Blocks</a></li>
<li><a href="circles.html">Circles</a></li>
<li><a href="clone.html">Clone</a></li>
<li><a href="chalk.html">Craie</a></li>
<li><a href="distortion.html">Distorsion</a></li>
@ -21,6 +22,7 @@
<li><a href="noise.html">Noise</a></li>
<li><a href="fisheye.html">Oeil de poisson</a></li>
<li><a href="puzzle.html">Puzzle</a></li>
<li><a href="rays.html">Rays</a></li>
<li><a href="emboss.html">Relief</a></li>
<li><a href="ripples.html">Ripples</a></li>
<li><a href="sharpen.html">Sharpen</a></li>

View file

@ -0,0 +1,14 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<body><html><head><title>Tux Paint "Magic" Tool: Rays</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#FF0000" alink="#FF00FF">
<h1 align="center">Tux Paint "Magic" Tool: Rays</h1>
<h2 align="center">Group: Distorts</h2>
<h3 align="center">Author:
Bill Kendrick &lt;<a href="mailto:bill@newbreedsoftware.com">bill@newbreedsoftware.com</a>&gt;</h3>
<p>This transforms the picture into brush strokes that point towards where you clicked.</p>
<p>See also: <a href="circles.html">Circles</a>.</p>
<hr size="1" noshade />
<p align="center">Tux Paint 0.9.29</p>
</body></html>

View file

@ -3,6 +3,7 @@
Distorts
* Blocks
* Circles
* Clone
* Craie
* Distorsion
@ -17,6 +18,7 @@ Distorts
* Noise
* Oeil de poisson
* Puzzle
* Rays
* Relief
* Ripples
* Sharpen

View file

@ -0,0 +1,14 @@
Tux Paint "Magic" Tool: Rays
Group: Distorts
Author: Bill Kendrick <bill@newbreedsoftware.com>
This transforms the picture into brush strokes that point towards where
you clicked.
See also: Circles.
----------------------------------------------------------------------
Tux Paint 0.9.29

View file

@ -0,0 +1,14 @@
Tux Paint "Magic" Tool: Circles
Group: Distorts
Author: Bill Kendrick <bill@newbreedsoftware.com>
This transforms the picture into circular brush strokes around where you
clicked.
See also: Rays.
----------------------------------------------------------------------
Tux Paint 0.9.29

View file

@ -0,0 +1,14 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<body><html><head><title>Tux Paint "Magic" Tool: Circles</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#FF0000" alink="#FF00FF">
<h1 align="center">Tux Paint "Magic" Tool: Circles</h1>
<h2 align="center">Group: Distorts</h2>
<h3 align="center">Author:
Bill Kendrick &lt;<a href="mailto:bill@newbreedsoftware.com">bill@newbreedsoftware.com</a>&gt;</h3>
<p>This transforms the picture into circular brush strokes around where you clicked.</p>
<p>See also: <a href="rays.html">Rays</a>.</p>
<hr size="1" noshade />
<p align="center">Tux Paint 0.9.29</p>
</body></html>

View file

@ -9,6 +9,7 @@
<li><a href="blocks.html">Blocks</a></li>
<li><a href="blur.html">Blur</a></li>
<li><a href="chalk.html">Chalk</a></li>
<li><a href="circles.html">Circles</a></li>
<li><a href="clone.html">Clone</a></li>
<li><a href="distortion.html">Distortion</a></li>
<li><a href="drip.html">Drip</a></li>
@ -22,6 +23,7 @@
<li><a href="mosaic.html">Mosaic</a></li>
<li><a href="noise.html">Noise</a></li>
<li><a href="puzzle.html">Puzzle</a></li>
<li><a href="rays.html">Rays</a></li>
<li><a href="ripples.html">Ripples</a></li>
<li><a href="sharpen.html">Sharpen</a></li>
<li><a href="silhouette.html">Silhouette</a></li>

View file

@ -0,0 +1,14 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<body><html><head><title>Tux Paint "Magic" Tool: Rays</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#FF0000" alink="#FF00FF">
<h1 align="center">Tux Paint "Magic" Tool: Rays</h1>
<h2 align="center">Group: Distorts</h2>
<h3 align="center">Author:
Bill Kendrick &lt;<a href="mailto:bill@newbreedsoftware.com">bill@newbreedsoftware.com</a>&gt;</h3>
<p>This transforms the picture into brush strokes that point towards where you clicked.</p>
<p>See also: <a href="circles.html">Circles</a>.</p>
<hr size="1" noshade />
<p align="center">Tux Paint 0.9.29</p>
</body></html>

View file

@ -5,6 +5,7 @@ Distorts
* Blocks
* Blur
* Chalk
* Circles
* Clone
* Distortion
* Drip
@ -18,6 +19,7 @@ Distorts
* Mosaic
* Noise
* Puzzle
* Rays
* Ripples
* Sharpen
* Silhouette

View file

@ -0,0 +1,14 @@
Tux Paint "Magic" Tool: Rays
Group: Distorts
Author: Bill Kendrick <bill@newbreedsoftware.com>
This transforms the picture into brush strokes that point towards where
you clicked.
See also: Circles.
----------------------------------------------------------------------
Tux Paint 0.9.29

View file

@ -0,0 +1,14 @@
Tux Paint "Magic" Tool: Circles
Group: Distorts
Author: Bill Kendrick <bill@newbreedsoftware.com>
This transforms the picture into circular brush strokes around where you
clicked.
See also: Rays.
----------------------------------------------------------------------
Tux Paint 0.9.29

View file

@ -0,0 +1,14 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<body><html><head><title>Tux Paint "Magic" Tool: Circles</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#FF0000" alink="#FF00FF">
<h1 align="center">Tux Paint "Magic" Tool: Circles</h1>
<h2 align="center">Group: Distorts</h2>
<h3 align="center">Author:
Bill Kendrick &lt;<a href="mailto:bill@newbreedsoftware.com">bill@newbreedsoftware.com</a>&gt;</h3>
<p>This transforms the picture into circular brush strokes around where you clicked.</p>
<p>See also: <a href="rays.html">Rays</a>.</p>
<hr size="1" noshade />
<p align="center">Tux Paint 0.9.29</p>
</body></html>

View file

@ -9,6 +9,7 @@
<li><a href="blocks.html">Blocks</a></li>
<li><a href="blur.html">Blur</a></li>
<li><a href="chalk.html">Chalk</a></li>
<li><a href="circles.html">Circles</a></li>
<li><a href="clone.html">Clone</a></li>
<li><a href="distortion.html">Distortion</a></li>
<li><a href="drip.html">Drip</a></li>
@ -22,6 +23,7 @@
<li><a href="mosaic.html">Mosaic</a></li>
<li><a href="noise.html">Noise</a></li>
<li><a href="puzzle.html">Puzzle</a></li>
<li><a href="rays.html">Rays</a></li>
<li><a href="ripples.html">Ripples</a></li>
<li><a href="sharpen.html">Sharpen</a></li>
<li><a href="silhouette.html">Silhouette</a></li>

View file

@ -0,0 +1,14 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<body><html><head><title>Tux Paint "Magic" Tool: Rays</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#FF0000" alink="#FF00FF">
<h1 align="center">Tux Paint "Magic" Tool: Rays</h1>
<h2 align="center">Group: Distorts</h2>
<h3 align="center">Author:
Bill Kendrick &lt;<a href="mailto:bill@newbreedsoftware.com">bill@newbreedsoftware.com</a>&gt;</h3>
<p>This transforms the picture into brush strokes that point towards where you clicked.</p>
<p>See also: <a href="circles.html">Circles</a>.</p>
<hr size="1" noshade />
<p align="center">Tux Paint 0.9.29</p>
</body></html>

View file

@ -5,6 +5,7 @@ Distorts
* Blocks
* Blur
* Chalk
* Circles
* Clone
* Distortion
* Drip
@ -18,6 +19,7 @@ Distorts
* Mosaic
* Noise
* Puzzle
* Rays
* Ripples
* Sharpen
* Silhouette

View file

@ -0,0 +1,14 @@
Tux Paint "Magic" Tool: Rays
Group: Distorts
Author: Bill Kendrick <bill@newbreedsoftware.com>
This transforms the picture into brush strokes that point towards where
you clicked.
See also: Circles.
----------------------------------------------------------------------
Tux Paint 0.9.29

Binary file not shown.

Binary file not shown.

350
magic/src/swirls.c Normal file
View file

@ -0,0 +1,350 @@
/* swirls.c
Transforms parts of the image into brush strokes that
swirl around where you click.
Inspired by "Night Sky Scene [Pen Parallax]" Scratch Project
by -HexaScape- <https://scratch.mit.edu/users/-HexaScape->
Last updated: January 28, 2023
*/
#include <stdio.h>
#include <string.h>
#include <libintl.h>
#include <math.h>
#include "tp_magic_api.h"
#include "SDL_image.h"
#include "SDL_mixer.h"
enum {
SWIRL_TOOL_CIRCLES,
SWIRL_TOOL_RAYS,
NUM_SWIRL_TOOLS
};
char * swirl_names[NUM_SWIRL_TOOLS] = {
gettext_noop("Circles"),
gettext_noop("Rays")
};
char * swirl_descriptions[NUM_SWIRL_TOOLS][2] = {
{
gettext_noop("Click to turn your entire picture into circular brushstrokes."),
gettext_noop("Click and drag to transform parts of your picture to circular brushstrokes.")
},
{
gettext_noop("Click to turn your entire picture into brushstroke rays."),
gettext_noop("Click and drag to transform parts of your picture to brushstroke rays.")
}
};
char * swirl_icon_filenames[NUM_SWIRL_TOOLS] = {
"swirls_circles.png",
"swirls_rays.png"
};
char * swirl_sfx_filenames[NUM_SWIRL_TOOLS] = {
"swirls_circles.ogg",
"swirls_rays.ogg"
};
#define SWIRLS_NUM_STROKES_PER_DRAG_LINE 5
#define SWIRLS_DRAG_LINE_STROKE_RADIUS 64
#define SWIRLS_STROKE_LENGTH 10
Mix_Chunk *snd_effects[NUM_SWIRL_TOOLS];
SDL_Surface * swirls_snapshot = NULL;
int swirls_start_x, swirls_start_y;
Uint32 swirl_stroke_color;
Uint32 swirls_api_version(void);
int swirls_init(magic_api * api);
int swirls_get_tool_count(magic_api * api);
SDL_Surface *swirls_get_icon(magic_api * api, int which);
char *swirls_get_name(magic_api * api, int which);
int swirls_get_group(magic_api * api, int which);
char *swirls_get_description(magic_api * api, int which, int mode);
int swirls_requires_colors(magic_api * api, int which);
int swirls_modes(magic_api * api, int which);
void swirls_shutdown(magic_api * api);
void swirls_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * snapshot, int x,
int y, SDL_Rect * update_rect);
void swirls_set_color(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect);
void swirls_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int ox, int oy, int x, int y,
SDL_Rect * update_rect);
void swirls_line_callback_drag(void *ptr, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int x, int y);
void swirls_draw_stroke(magic_api * api, int which, SDL_Surface * canvas, int x, int y);
void swirls_line_callback_draw_stroke(void *ptr, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas,
SDL_Surface * snapshot ATTRIBUTE_UNUSED,
int x, int y);
void swirls_release(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int x, int y,
SDL_Rect * update_rect);
void swirls_switchin(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void swirls_switchout(magic_api * api, int which, int mode,
SDL_Surface * canvas);
double get_angle(int x, int y, int target_x, int target_y);
Uint32 swirls_api_version(void)
{
return (TP_MAGIC_API_VERSION);
}
int swirls_init(magic_api * api)
{
int i;
char fname[1024];
for (i = 0; i < NUM_SWIRL_TOOLS; i++) {
snprintf(fname, sizeof(fname), "%ssounds/magic/%s",
api->data_directory, swirl_sfx_filenames[i]);
snd_effects[i] = Mix_LoadWAV(fname);
}
return (1);
}
int swirls_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
{
return (NUM_SWIRL_TOOLS);
}
SDL_Surface *swirls_get_icon(magic_api * api, int which)
{
char fname[1024];
snprintf(fname, sizeof(fname), "%simages/magic/%s",
api->data_directory, swirl_icon_filenames[which]);
return (IMG_Load(fname));
}
char *swirls_get_name(magic_api * api ATTRIBUTE_UNUSED,
int which)
{
return strdup(gettext(swirl_names[which]));
}
int swirls_get_group(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
{
return MAGIC_TYPE_DISTORTS;
}
char *swirls_get_description(magic_api * api ATTRIBUTE_UNUSED,
int which, int mode)
{
return strdup(gettext(swirl_descriptions[which][mode]));
}
int swirls_requires_colors(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
{
return 0;
}
int swirls_modes(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
{
return MODE_PAINT | MODE_FULLSCREEN;
}
void swirls_shutdown(magic_api * api ATTRIBUTE_UNUSED)
{
int i;
for (i = 0; i < NUM_SWIRL_TOOLS; i++) {
if (snd_effects[i] != NULL)
Mix_FreeChunk(snd_effects[i]);
}
}
void
swirls_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y,
SDL_Rect * update_rect)
{
if (snd_effects[which] != NULL)
api->stopsound();
swirls_start_x = x;
swirls_start_y = y;
if (mode == MODE_PAINT) {
swirls_drag(api, which, canvas, snapshot, x, y, x, y, update_rect);
} else {
if (snd_effects[which] != NULL) {
api->playsound(snd_effects[which], (x * 255) / canvas->w, 255);
}
for (x = 0; x < canvas->w; x++) {
for (y = 0; y < canvas->h; y++) {
if (rand() % 100 == 0) {
swirls_draw_stroke(api, which, canvas, x, y);
}
}
}
update_rect->x = 0;
update_rect->y = 0;
update_rect->w = canvas->w;
update_rect->h = canvas->h;
}
}
void
swirls_drag(magic_api * api ATTRIBUTE_UNUSED, int which, SDL_Surface * canvas,
SDL_Surface * snapshot, int ox, int oy, int x, int y, SDL_Rect * update_rect)
{
api->line((void *) api, which, canvas, snapshot, ox, oy, x, y, 1 /* FIXME: Consider fewer iterations? */,
swirls_line_callback_drag);
/* FIXME: Would be good to only update the area around the line (ox,oy)->(x,y) (+/- the maxium radius of the effect) */
update_rect->x = 0;
update_rect->y = 0;
update_rect->w = canvas->w;
update_rect->h = canvas->h;
}
void swirls_release(magic_api * api, int which,
SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * snapshot ATTRIBUTE_UNUSED,
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED,
SDL_Rect * update_rect ATTRIBUTE_UNUSED) {
if (snd_effects[which] != NULL)
api->stopsound();
}
void swirls_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED,
SDL_Surface * last ATTRIBUTE_UNUSED,
Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED,
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
{
}
void swirls_line_callback_drag(void *ptr, int which,
SDL_Surface * canvas,
SDL_Surface * snapshot ATTRIBUTE_UNUSED,
int x, int y)
{
int i, ang_deg, radius, nx, ny;
double ang_rad;
magic_api *api = (magic_api *) ptr;
if (snd_effects[which] != NULL)
api->playsound(snd_effects[which], (x * 255) / canvas->w, 255);
for (i = 0; i < SWIRLS_NUM_STROKES_PER_DRAG_LINE; i++) {
ang_deg = (rand() % 360);
ang_rad = (ang_deg * M_PI) / 180.0;
radius = (rand() % (SWIRLS_DRAG_LINE_STROKE_RADIUS * 2)) - SWIRLS_DRAG_LINE_STROKE_RADIUS;
nx = x + (int) (cos(ang_rad) * radius);
ny = y + (int) (sin(ang_rad) * radius);
swirls_draw_stroke(api, which, canvas, nx, ny);
}
}
void swirls_draw_stroke(magic_api * api, int which, SDL_Surface * canvas, int x, int y) {
int x1, y1, x2, y2;
double a;
Uint8 r, g, b;
float h, s, v;
a = get_angle(x, y, swirls_start_x, swirls_start_y);
if (which == SWIRL_TOOL_CIRCLES) {
a = a + (M_PI / 2.0);
}
x1 = x - cos(a) * SWIRLS_STROKE_LENGTH;
y1 = y - sin(a) * SWIRLS_STROKE_LENGTH;
x2 = x + cos(a) * SWIRLS_STROKE_LENGTH;
y2 = y + sin(a) * SWIRLS_STROKE_LENGTH;
swirl_stroke_color = api->getpixel(swirls_snapshot, x, y);
SDL_GetRGB(swirl_stroke_color, canvas->format, &r, &g, &b);
api->rgbtohsv(r, g, b, &h, &s, &v);
h = h + (((rand() % 7) - 3) / 10.0);
if (s > 0.00) {
s = s + (((rand() % 3) - 1) / 10.0);
}
v = v + (((rand() % 3) - 1) / 10.0);
if (h < 0.0) {
h = h - 360.0;
} else if (h >= 360.0) {
h = h - 360.0;
}
if (s < 0.0) {
s = 0.0;
} else if (s > 1.0) {
s = 1.0;
}
if (v < 0.0) {
v = 0.0;
} else if (v > 1.0) {
v = 1.0;
}
api->hsvtorgb(h, s, v, &r, &g, &b);
swirl_stroke_color = SDL_MapRGB(canvas->format, r, g, b);
api->line((void *) api, 0 /* N/A */, canvas, NULL /* N/A */,
x1, y1, x2, y2, 1, swirls_line_callback_draw_stroke);
}
void swirls_line_callback_draw_stroke(void *ptr, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas,
SDL_Surface * snapshot ATTRIBUTE_UNUSED,
int x, int y) {
magic_api *api = (magic_api *) ptr;
int xx, yy;
for (yy = -1; yy <= 1; yy++) {
for (xx = -1; xx <= 1; xx++) {
api->putpixel(canvas, x + xx, y + yy, swirl_stroke_color);
}
}
}
void swirls_switchin(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas)
{
if (swirls_snapshot == NULL)
swirls_snapshot = SDL_CreateRGBSurface(SDL_SWSURFACE, canvas->w, canvas->h,
canvas->format->BitsPerPixel, canvas->format->Rmask,
canvas->format->Gmask, canvas->format->Bmask,
canvas->format->Amask);
if (swirls_snapshot != NULL)
SDL_BlitSurface(canvas, NULL, swirls_snapshot, NULL);
}
void swirls_switchout(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED,
int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{
}
double get_angle(int x, int y, int target_x, int target_y) {
return atan2((double) (y - target_y), (double) (x - target_x));
}