Mercurial > audlegacy-plugins
annotate src/paranormal/misc.c @ 1892:3b034150d31e
Add GPL2 boilerplate text.
author | William Pitcock <nenolod@atheme.org> |
---|---|
date | Wed, 26 Sep 2007 11:51:08 -0500 |
parents | b185ed2f8fa2 |
children | 56bb18dd3fdd |
rev | line source |
---|---|
1892
3b034150d31e
Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents:
302
diff
changeset
|
1 /* |
3b034150d31e
Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents:
302
diff
changeset
|
2 * paranormal: iterated pipeline-driven visualization plugin |
3b034150d31e
Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents:
302
diff
changeset
|
3 * Copyright (c) 2006, 2007 William Pitcock <nenolod@dereferenced.org> |
3b034150d31e
Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents:
302
diff
changeset
|
4 * Portions copyright (c) 2001 Jamie Gennis <jgennis@mindspring.com> |
3b034150d31e
Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents:
302
diff
changeset
|
5 * |
3b034150d31e
Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents:
302
diff
changeset
|
6 * This program is free software; you can redistribute it and/or modify |
3b034150d31e
Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents:
302
diff
changeset
|
7 * it under the terms of the GNU General Public License as published by |
3b034150d31e
Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents:
302
diff
changeset
|
8 * the Free Software Foundation; under version 2 of the License. |
3b034150d31e
Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents:
302
diff
changeset
|
9 * |
3b034150d31e
Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents:
302
diff
changeset
|
10 * This program is distributed in the hope that it will be useful, |
3b034150d31e
Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents:
302
diff
changeset
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
3b034150d31e
Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents:
302
diff
changeset
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3b034150d31e
Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents:
302
diff
changeset
|
13 * GNU General Public License for more details. |
3b034150d31e
Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents:
302
diff
changeset
|
14 * |
3b034150d31e
Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents:
302
diff
changeset
|
15 * You should have received a copy of the GNU General Public License |
3b034150d31e
Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents:
302
diff
changeset
|
16 * along with this program; if not, write to the Free Software |
3b034150d31e
Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents:
302
diff
changeset
|
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
3b034150d31e
Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents:
302
diff
changeset
|
18 */ |
3b034150d31e
Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents:
302
diff
changeset
|
19 |
186 | 20 #ifdef HAVE_CONFIG_H |
21 # include <config.h> | |
22 #endif | |
23 | |
24 #include <stdlib.h> | |
25 #include <stdio.h> | |
26 | |
27 #include <glib.h> | |
28 | |
29 #include "paranormal.h" | |
30 #include "actuators.h" | |
31 #include "pn_utils.h" | |
32 | |
33 /* ******************** misc_floater ******************** */ | |
34 static struct pn_actuator_option_desc misc_floater_opts[] = | |
35 { | |
36 { "value", "The colour value for the floater.", | |
37 OPT_TYPE_INT, { ival: 255 } }, | |
188 | 38 { NULL } |
186 | 39 }; |
40 | |
41 typedef enum | |
42 { | |
43 float_up = 0x1, | |
44 float_down = 0x2, | |
45 float_left = 0x4, | |
46 float_right = 0x8, | |
47 } FloaterDirection; | |
48 | |
49 struct floater_state_data | |
50 { | |
51 FloaterDirection dir; | |
52 gint x; | |
53 gint y; | |
54 }; | |
55 | |
56 static void | |
57 misc_floater_init(gpointer *data) | |
58 { | |
59 struct floater_state_data *opaque_data = g_new0(struct floater_state_data, 1); | |
60 *data = opaque_data; | |
61 opaque_data->x = rand() % pn_image_data->width; | |
62 opaque_data->y = rand() % pn_image_data->height; | |
63 opaque_data->dir = (FloaterDirection) rand() % 15; /* sum of all dir values */ | |
64 } | |
65 | |
66 static void | |
67 misc_floater_cleanup(gpointer data) | |
68 { | |
69 g_free(data); | |
70 } | |
71 | |
72 /* | |
73 * This implementation isn't very great. | |
74 * Anyone want to improve it? :( | |
75 */ | |
76 static void | |
77 misc_floater_exec(const struct pn_actuator_option *opts, gpointer data) | |
78 { | |
79 struct floater_state_data *opaque_data = (struct floater_state_data *) data; | |
80 guchar value = (opts[0].val.ival < 0 || opts[0].val.ival > 255) ? 255 : opts[0].val.ival; | |
81 | |
82 /* determine the root coordinate first */ | |
83 if (opaque_data->dir & float_up) | |
84 opaque_data->y -= 1; | |
85 if (opaque_data->dir & float_down) | |
86 opaque_data->y += 1; | |
87 | |
88 if (opaque_data->dir & float_left) | |
89 opaque_data->x -= 1; | |
90 if (opaque_data->dir & float_right) | |
91 opaque_data->x += 1; | |
92 | |
93 /* make sure we're within surface boundaries. segfaults suck, afterall. */ | |
94 if (opaque_data->x + 1 <= pn_image_data->width && | |
95 opaque_data->x - 1 >= 0 && | |
96 opaque_data->y + 1 <= pn_image_data->height && | |
97 opaque_data->y - 1 >= 0) | |
98 { | |
99 /* draw it. i could use a loop here, but i don't see much reason in it, | |
100 * so i don't think i will at this time. -nenolod | |
101 */ | |
102 pn_image_data->surface[0][PN_IMG_INDEX(opaque_data->x, opaque_data->y)] = value; | |
103 pn_image_data->surface[0][PN_IMG_INDEX(opaque_data->x + 1, opaque_data->y)] = value; | |
104 pn_image_data->surface[0][PN_IMG_INDEX(opaque_data->x - 1, opaque_data->y)] = value; | |
105 pn_image_data->surface[0][PN_IMG_INDEX(opaque_data->x, opaque_data->y + 1)] = value; | |
106 pn_image_data->surface[0][PN_IMG_INDEX(opaque_data->x, opaque_data->y - 1)] = value; | |
107 } | |
108 | |
109 /* check if we need to change direction yet, and if so, do so. */ | |
302 | 110 if (pn_new_beat == TRUE) |
186 | 111 opaque_data->dir = (FloaterDirection) rand() % 15; /* sum of all dir values */ |
112 | |
113 /* now adjust the direction so we stay in boundary */ | |
114 if (opaque_data->x - 1 <= 0 && opaque_data->dir & float_left) | |
115 { | |
116 opaque_data->dir &= ~float_left; | |
117 opaque_data->dir |= float_right; | |
118 } | |
119 | |
120 if (opaque_data->x + 1 >= pn_image_data->width && opaque_data->dir & float_right) | |
121 { | |
122 opaque_data->dir &= ~float_right; | |
123 opaque_data->dir |= float_left; | |
124 } | |
125 | |
126 if (opaque_data->y - 1 <= 0 && opaque_data->dir & float_up) | |
127 { | |
128 opaque_data->dir &= ~float_up; | |
129 opaque_data->dir |= float_down; | |
130 } | |
131 | |
132 if (opaque_data->y + 1 >= pn_image_data->height && opaque_data->dir & float_down) | |
133 { | |
134 opaque_data->dir &= ~float_down; | |
135 opaque_data->dir |= float_up; | |
136 } | |
137 } | |
138 | |
139 struct pn_actuator_desc builtin_misc_floater = | |
140 { | |
141 "misc_floater", | |
142 "Floating Particle", | |
143 "A floating particle.", | |
144 0, misc_floater_opts, | |
145 misc_floater_init, misc_floater_cleanup, misc_floater_exec | |
146 }; | |
147 |