Debian Codegraph @

plugins/actor/JESS/distorsion.c

raw
1 /* Libvisual-plugins - Standard plugins for libvisual
2 *
3 * Copyright (C) 2000, 2001 Remi Arquier <[email protected]>
4 *
5 * Authors: Remi Arquier <[email protected]>
6 * Dennis Smit <[email protected]>
7 *
8 * $Id: distorsion.c,v 1.5 2005/12/20 18:49:12 synap Exp $
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24
25 #include <math.h>
26 #include <stdlib.h>
27 #include <stdio.h>
28 #include <unistd.h>
29
30 #include "distorsion.h"
31 #include "def.h"
32 #include "jess.h"
33
34 void create_tables(JessPrivate *priv)
35 {
36 int i, j, k, x, y;
37 float n_fx, n_fy;
38 int resy, resx;
39
40 resy = priv->resy;
41 resx = priv->resx;
42
43 for (k=1; k<5; k++)
44 {
45 for (i = 0; i < priv->resy; i++)
46 {
47 for (j = 0; j < priv->resx; j++)
48 {
49 n_fx = (float) j - priv->xres2;
50 n_fy = (float) i - priv->yres2;
51
52 switch(k)
53 {
54 case 1:
55 rot_hyperbolic_radial (&n_fx, &n_fy, -PI / 5, 0.001, 0,
56 RESFACTY (50)) ;
57 rot_hyperbolic_radial (&n_fx, &n_fy, PI / 2, 0.004,
58 RESFACTX (200), RESFACTY (-30)) ;
59 rot_hyperbolic_radial (&n_fx, &n_fy, PI / 5, 0.001,
60 RESFACTX (-150), RESFACTY (-30)) ;
61 rot_hyperbolic_radial (&n_fx, &n_fy, PI / 30, 0.0001, 0, 0) ;
62 break;
63 case 2:
64 rot_cos_radial(&n_fx,&n_fy, 2*PI/75, 0.01,000,000) ;
65 break;
66 case 3:
67 homothetie_hyperbolic(&n_fx, &n_fy, 0.0005,0,0) ;
68 break;
69 case 4:
70 noize(priv, &n_fx, &n_fy, 0*5.0);
71 /* rot_hyperbolic_radial (&n_fx, &n_fy, PI / 30, 0.00010, 0, 0) ; */
72 /* homothetie_hyperbolic(&n_fx, &n_fy, -0.0002,0,0) ; */
73 /* homothetie_cos_radial(&n_fx, &n_fy, 0.01,-10,10) ; */
74 break;
75 }
76
77 x = (int) (n_fx + priv->xres2);
78 y = (int) (n_fy + priv->yres2);
79
80 if (x < 0 || x >= priv->resx || y < 0 || y >= priv->resy )
81 {
82 x = 0;
83 y = 0;
84 }
85
86 switch(k)
87 {
88 case 1:
89 priv->table1[i * resx + j] = x + y * resx;
90 break;
91 case 2:
92 priv->table2[i * resx + j] = x + y * resx;
93 break;
94 case 3:
95 priv->table3[i * resx + j] = x + y * resx;
96 break;
97 case 4:
98 priv->table4[i * resx + j] = x + y * resx;
99 break;
100 }
101 }
102 }
103 }
104 }
105
106 void rot_hyperbolic_radial(float *n_fx,float *n_fy,float d_alpha, float rad_factor, float cx, float cy)
107 {
108 float r2,dx = *n_fx-cx, dy = *n_fy-cy,cosal, sinal;
109
110 r2 = (dx)*(dx)+(dy)*(dy);
111
112 d_alpha*=1/(1+r2*rad_factor);
113
114 cosal = cos(d_alpha) ;
115 sinal = sin(d_alpha) ;
116
117 *n_fx = cx + dx * cosal - dy * sinal;
118 *n_fy = cy + dx * sinal + dy * cosal;
119 }
120
121 void rot_cos_radial( float *n_fx,float *n_fy,float d_alpha, float rad_factor, float cx, float cy)
122 {
123 float r,dx = *n_fx-cx, dy = *n_fy-cy,cosal, sinal;
124 r = sqrt(dx*dx+dy*dy);
125
126 d_alpha=d_alpha*cos(r*rad_factor);
127
128 cosal = cos(d_alpha) ;
129 sinal = sin(d_alpha) ;
130
131 *n_fx = cx + dx * cosal - dy * sinal;
132 *n_fy = cy + dx * sinal + dy * cosal;
133 }
134
135 void homothetie_hyperbolic(float *n_fx,float *n_fy, float rad_factor, float cx, float cy)
136 {
137 float r,dx = *n_fx-cx, dy = *n_fy-cy;
138 r = sqrt(dx*dx+dy*dy);
139
140 *n_fx = cx + dx/(1+rad_factor*r);
141 *n_fy = cy + dy/(1+rad_factor*r);
142 }
143
144
145 void homothetie_cos_radial(float *n_fx,float *n_fy, float rad_factor, float cx, float cy)
146 {
147 float r,cosrad, dx = *n_fx-cx, dy = *n_fy-cy;
148 r = sqrt(dx*dx+dy*dy);
149
150 cosrad = cos(r*rad_factor);
151
152 *n_fx = cx + dx*cosrad;
153 *n_fy = cy + dy*cosrad;
154 }
155
156 void noize(JessPrivate *priv, float *n_fx,float *n_fy, float intensity)
157 {
158 *n_fx +=2*((float)visual_random_context_int(priv->rcontext)/VISUAL_RANDOM_MAX-0.5)*intensity;
159 *n_fy +=2*((float)visual_random_context_int(priv->rcontext)/VISUAL_RANDOM_MAX-0.5)*intensity-5;
160 }
161