Debian Codegraph @

plugins/actor/oinksie/gfx-background.c

raw
1 /* Libvisual-plugins - Standard plugins for libvisual
2 *
3 * Copyright (C) 2002, 2003, 2004, 2005, 2006 Dennis Smit <[email protected]>
4 *
5 * Authors: Dennis Smit <[email protected]>
6 *
7 * $Id: gfx-background.c,v 1.7 2006/01/22 13:25:26 synap Exp $
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23
24 #include <string.h>
25
26 #include "common.h"
27 #include "screen.h"
28 #include "audio.h"
29 #include "table.h"
30 #include "gfx-misc.h"
31 #include "misc.h"
32 #include "gfx-background.h"
33
34 void _oink_gfx_background_circles_sine (OinksiePrivate *priv,
35 uint8_t *buf, int color, int rotate, int scroll, int stretch, int size)
36 {
37 int i;
38 int y;
39 int y1;
40 int x;
41 int x1;
42 int tab;
43 int sadd = priv->screen_xysmallest / 2;
44 float sden;
45
46 rotate = abs (rotate);
47 scroll = abs (scroll);
48 stretch = abs (stretch);
49
50 tab = scroll;
51
52 for (i = 0; i < priv->screen_width; i+= 20)
53 {
54 sden = _oink_table_sin[abs (tab % OINK_TABLE_NORMAL_SIZE)];
55 y = (sden * size) + sadd;
56
57 sden = _oink_table_sin[abs ((tab + OINK_TABLE_NORMAL_SIZE / 2) % OINK_TABLE_NORMAL_SIZE)];
58 y1 = (sden * size) + sadd;
59
60 x = i - priv->screen_halfwidth;
61 x1 = x;
62
63 y = y - priv->screen_halfheight;
64 y1 = y1 - priv->screen_halfheight;
65
66 _oink_pixel_rotate (&x, &y, rotate);
67 _oink_pixel_rotate (&x1, &y1, rotate);
68
69 _oink_gfx_circle_filled (priv, buf, color - abs (sden * 20), 15 - abs (sden * 10),
70 x + priv->screen_halfwidth, y + priv->screen_halfheight);
71 _oink_gfx_circle_filled (priv, buf, color - abs (sden * 20), 15 - abs (sden * 10),
72 x1 + priv->screen_halfwidth, y1 + priv->screen_halfheight);
73
74 tab += stretch;
75 }
76 }
77
78 void _oink_gfx_background_circles_filled (OinksiePrivate *priv,
79 uint8_t *buf, int color, int size, int number, int distance, int turn, int x, int y)
80 {
81 int i;
82 int xi;
83 int yi;
84 int adder = OINK_TABLE_NORMAL_SIZE / number;
85 int tab = turn % OINK_TABLE_NORMAL_SIZE;
86
87 if (tab < 0)
88 {
89 tab = OINK_TABLE_NORMAL_SIZE - +tab;
90 tab = tab % OINK_TABLE_NORMAL_SIZE;
91 }
92
93 for (i = 0; i < number; i++)
94 {
95 xi = (_oink_table_sin[tab % OINK_TABLE_NORMAL_SIZE] * distance) + x;
96 yi = (_oink_table_cos[tab % OINK_TABLE_NORMAL_SIZE] * distance) + y;
97
98 tab += adder;
99
100 _oink_gfx_circle_filled (priv, buf, color, size, xi, yi);
101 }
102 }
103
104 // In C, `-8 % 5` yields -3 (and `-8 % 5u` yields +3) rather than 2. This wrapper corrects for it.
105 static int mod(int a, int n) {
106 const int original = a % n;
107 return (original >= 0) ? original : (original + n);
108 }
109
110 void _oink_gfx_background_floaters (OinksiePrivate *priv,
111 uint8_t *buf, int color, int size, int number, int xturn, int yturn, int x, int badd1, int badd2)
112 {
113 int i;
114 int xi;
115 int yi;
116 int xb;
117 int yb;
118 int add1 = 0;
119 int add2 = 0;
120
121 int mul = ((priv->screen_width - 20) / number);
122
123 for (i = 0; i < number; i++)
124 {
125 xi = (_oink_table_sin[mod(xturn + add1, OINK_TABLE_NORMAL_SIZE)] * (float) (priv->screen_width / (number + 1)));
126 yi = (_oink_table_cos[mod(yturn + add2, OINK_TABLE_NORMAL_SIZE)] * (float) (priv->screen_height / 5));
127
128 xb = xi + (i * mul) + 20;
129 yb = yi + x;
130
131 if (xb > 0 + size || xb < priv->screen_width - size || yb > 0 + size || yb < priv->screen_height - size)
132 _oink_gfx_circle_filled (priv, buf, color, size, xb, yb);
133
134 add1 += badd1;
135 add2 += badd2;
136 }
137 }
138
139 void _oink_gfx_background_ball_shooting (OinksiePrivate *priv,
140 uint8_t *buf, int color, int distance, int xb, int yb, int x, int y)
141 {
142 int xi = _oink_line_xory_next_xy (0, distance, x, y, xb, yb);
143 int yi = _oink_line_xory_next_xy (1, distance, x, y, xb, yb);
144
145 _oink_gfx_circle_filled (priv, buf, color, distance >> 1, xi, yi);
146 }
147
148 void _oink_gfx_background_ball_whirling (OinksiePrivate *priv,
149 uint8_t *buf, int color, int size, int dia, int rot, int x, int y)
150 {
151 int xd;
152 int yd;
153
154 xd = (_oink_table_sin[rot % OINK_TABLE_NORMAL_SIZE] * dia) + x;
155 yd = (_oink_table_cos[rot % OINK_TABLE_NORMAL_SIZE] * dia) + y;
156
157 _oink_gfx_circle_filled (priv, buf, color, size, xd, yd);
158 }
159
160 void _oink_gfx_background_fill (OinksiePrivate *priv,
161 uint8_t *buf, int color)
162 {
163 visual_mem_set (buf, color, priv->screen_size);
164 }
165
166 void _oink_gfx_background_circles_star (OinksiePrivate *priv,
167 uint8_t *buf, int color, int size, int tentnr, int ballnr, int badd, int turn, int x, int y)
168 {
169 int i;
170 int i2;
171 int sizedef = 0;
172 int sizedefadd = size / ballnr;
173 int sinadd = OINK_TABLE_NORMAL_SIZE / tentnr;
174 int sindef = turn;
175 int bdef = 0;
176 int xd;
177 int yd;
178
179 for (i = 0; i < tentnr; i++)
180 {
181 sizedef = 0;
182
183 bdef = 0;
184 for (i2 = 0; i2 < ballnr; i2++)
185 {
186 xd = (_oink_table_sin[sindef % OINK_TABLE_NORMAL_SIZE] * bdef) + x;
187 yd = (_oink_table_cos[sindef % OINK_TABLE_NORMAL_SIZE] * bdef) + y;
188
189 _oink_gfx_circle_filled (priv, buf, color, size - sizedef, xd, yd);
190
191 bdef += badd;
192 sizedef += sizedefadd;
193 }
194 sindef += sinadd;
195 }
196 }
197