Mercurial > audlegacy-plugins
changeset 186:49f532942eec trunk
[svn] - add floating particles.
author | nenolod |
---|---|
date | Thu, 02 Nov 2006 02:30:44 -0800 |
parents | 38526384bc79 |
children | 90e05196fe17 |
files | ChangeLog src/paranormal/Makefile src/paranormal/builtins.c src/paranormal/misc.c |
diffstat | 4 files changed, 142 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Wed Nov 01 22:32:33 2006 -0800 +++ b/ChangeLog Thu Nov 02 02:30:44 2006 -0800 @@ -1,3 +1,11 @@ +2006-11-02 06:32:33 +0000 William Pitcock <nenolod@nenolod.net> + revision [370] + - remove feedback from motion transform. + + trunk/src/paranormal/presets/nenolod_-_value_replace_fun.pnv | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + + 2006-11-02 06:28:54 +0000 William Pitcock <nenolod@nenolod.net> revision [368] - so like, when will somebody else make some presets for this thing?
--- a/src/paranormal/Makefile Wed Nov 01 22:32:33 2006 -0800 +++ b/src/paranormal/Makefile Thu Nov 02 02:30:44 2006 -0800 @@ -18,6 +18,7 @@ containers.c \ freq.c \ general.c \ + misc.c \ paranormal.c \ plugin.c \ presets.c \
--- a/src/paranormal/builtins.c Wed Nov 01 22:32:33 2006 -0800 +++ b/src/paranormal/builtins.c Thu Nov 02 02:30:44 2006 -0800 @@ -31,6 +31,9 @@ DECLARE_ACTUATOR (general_invert); DECLARE_ACTUATOR (general_replace); +/* **************** misc **************** */ +DECLARE_ACTUATOR (misc_floater); + /* **************** wave **************** */ DECLARE_ACTUATOR (wave_horizontal); DECLARE_ACTUATOR (wave_vertical); @@ -66,6 +69,8 @@ &builtin_general_noop, &builtin_general_invert, &builtin_general_replace, + /* **************** misc **************** */ + &builtin_misc_floater, /* **************** wave **************** */ &builtin_wave_horizontal, &builtin_wave_vertical,
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/paranormal/misc.c Thu Nov 02 02:30:44 2006 -0800 @@ -0,0 +1,128 @@ +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif + +#include <stdlib.h> +#include <stdio.h> + +#include <glib.h> + +#include "paranormal.h" +#include "actuators.h" +#include "pn_utils.h" + +/* ******************** misc_floater ******************** */ +static struct pn_actuator_option_desc misc_floater_opts[] = +{ + { "value", "The colour value for the floater.", + OPT_TYPE_INT, { ival: 255 } }, + { 0 } +}; + +typedef enum +{ + float_up = 0x1, + float_down = 0x2, + float_left = 0x4, + float_right = 0x8, +} FloaterDirection; + +struct floater_state_data +{ + FloaterDirection dir; + gint x; + gint y; +}; + +static void +misc_floater_init(gpointer *data) +{ + struct floater_state_data *opaque_data = g_new0(struct floater_state_data, 1); + *data = opaque_data; + opaque_data->x = rand() % pn_image_data->width; + opaque_data->y = rand() % pn_image_data->height; + opaque_data->dir = (FloaterDirection) rand() % 15; /* sum of all dir values */ +} + +static void +misc_floater_cleanup(gpointer data) +{ + g_free(data); +} + +/* + * This implementation isn't very great. + * Anyone want to improve it? :( + */ +static void +misc_floater_exec(const struct pn_actuator_option *opts, gpointer data) +{ + struct floater_state_data *opaque_data = (struct floater_state_data *) data; + guchar value = (opts[0].val.ival < 0 || opts[0].val.ival > 255) ? 255 : opts[0].val.ival; + + /* determine the root coordinate first */ + if (opaque_data->dir & float_up) + opaque_data->y -= 1; + if (opaque_data->dir & float_down) + opaque_data->y += 1; + + if (opaque_data->dir & float_left) + opaque_data->x -= 1; + if (opaque_data->dir & float_right) + opaque_data->x += 1; + + /* make sure we're within surface boundaries. segfaults suck, afterall. */ + if (opaque_data->x + 1 <= pn_image_data->width && + opaque_data->x - 1 >= 0 && + opaque_data->y + 1 <= pn_image_data->height && + opaque_data->y - 1 >= 0) + { + /* draw it. i could use a loop here, but i don't see much reason in it, + * so i don't think i will at this time. -nenolod + */ + pn_image_data->surface[0][PN_IMG_INDEX(opaque_data->x, opaque_data->y)] = value; + pn_image_data->surface[0][PN_IMG_INDEX(opaque_data->x + 1, opaque_data->y)] = value; + pn_image_data->surface[0][PN_IMG_INDEX(opaque_data->x - 1, opaque_data->y)] = value; + pn_image_data->surface[0][PN_IMG_INDEX(opaque_data->x, opaque_data->y + 1)] = value; + pn_image_data->surface[0][PN_IMG_INDEX(opaque_data->x, opaque_data->y - 1)] = value; + } + + /* check if we need to change direction yet, and if so, do so. */ + if (pn_is_new_beat() == TRUE) + opaque_data->dir = (FloaterDirection) rand() % 15; /* sum of all dir values */ + + /* now adjust the direction so we stay in boundary */ + if (opaque_data->x - 1 <= 0 && opaque_data->dir & float_left) + { + opaque_data->dir &= ~float_left; + opaque_data->dir |= float_right; + } + + if (opaque_data->x + 1 >= pn_image_data->width && opaque_data->dir & float_right) + { + opaque_data->dir &= ~float_right; + opaque_data->dir |= float_left; + } + + if (opaque_data->y - 1 <= 0 && opaque_data->dir & float_up) + { + opaque_data->dir &= ~float_up; + opaque_data->dir |= float_down; + } + + if (opaque_data->y + 1 >= pn_image_data->height && opaque_data->dir & float_down) + { + opaque_data->dir &= ~float_down; + opaque_data->dir |= float_up; + } +} + +struct pn_actuator_desc builtin_misc_floater = +{ + "misc_floater", + "Floating Particle", + "A floating particle.", + 0, misc_floater_opts, + misc_floater_init, misc_floater_cleanup, misc_floater_exec +}; +