File: infinity.c

package info (click to toggle)
lebiniou 3.18-1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 5,396 kB
  • sloc: ansic: 20,369; sh: 4,169; makefile: 834; awk: 194
file content (193 lines) | stat: -rw-r--r-- 4,371 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
/*
 *  Copyright 1994-2012 Olivier Girondel
 *
 *  This file is part of lebiniou.
 *
 *  lebiniou is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  lebiniou is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with lebiniou. If not, see <http://www.gnu.org/licenses/>.
 */

#include "context.h"
#include "../include/infinity.h"


u_long id = 1188927899;
u_long options = BE_DISPLACE;
char dname[] = "Infinity";
char desc[] = "Infinity effect";


/* Infinity plugin port.
 * Original source code has been heavily modified, to take only
 * the vector fields. So modified it's nearly a rewrite.
 * Changes have also been made to reflect style(9).
 * See the original infinity plugin source code for exact details
 */
#define NB_FCT 6


static t_complex
fct(t_complex a, guint32 n, gint32 p1, gint32 p2)   /* p1 et p2:0-4 */
{
  t_complex b;
  gfloat fact;
  gfloat an;
  gfloat circle_size;
  gfloat speed;
  gfloat co,si;
    
  a.x -= HWIDTH;
  a.y -= HHEIGHT;
    
  switch (n) {
  case 0:
    an = 0.025*(p1-2)+0.002;
    co = cosf(an);
    si = sinf(an);
    circle_size = HEIGHT*0.25;
    speed = (gfloat)2000+p2*500;
    b.x = (co*a.x-si*a.y);
    b.y = (si*a.x+co*a.y);
    fact = -(sqrtf(b.x*b.x+b.y*b.y)-circle_size)/speed+1;
    b.x = (b.x*fact);
    b.y = (b.y*fact);
    break;

  case 1:
    an = 0.015*(p1-2)+0.002;
    co = cosf(an);
    si = sinf(an);
    circle_size = HEIGHT*0.45;
    speed = (gfloat)4000+p2*1000;
    b.x = (co*a.x-si*a.y);
    b.y = (si*a.x+co*a.y);
    fact = (sqrtf(b.x*b.x+b.y*b.y)-circle_size)/speed+1;
    b.x = (b.x*fact);
    b.y = (b.y*fact);
    break;

  case 2:
    an = 0.002;
    co = cosf(an);
    si = sinf(an);
    circle_size = HEIGHT*0.25;
    speed = (gfloat)400+p2*100;
    b.x = (co*a.x-si*a.y);
    b.y = (si*a.x+co*a.y);  
    fact = -(sqrtf(b.x*b.x+b.y*b.y)-circle_size)/speed+1;
    b.x = (b.x*fact);
    b.y = (b.y*fact);
    break;		

  case 3:
    an = (sinf(sqrtf(a.x*a.x+a.y*a.y)/20)/20)+0.002;
    co = cosf(an);
    si = sinf(an);
    circle_size = HEIGHT*0.25;
    speed = (gfloat)4000;
    b.x = (co*a.x-si*a.y);
    b.y = (si*a.x+co*a.y);
    fact = -(sqrtf(b.x*b.x+b.y*b.y)-circle_size)/speed+1;
    b.x = (b.x*fact);
    b.y = (b.y*fact);
    break;

  case 4:
    an = 0.002;
    co = cosf(an);
    si = sinf(an); 
    circle_size = HEIGHT*0.25;
    speed = sinf(sqrtf(a.x*a.x+a.y*a.y)/5)*3000+4000;
    b.x = (co*a.x-si*a.y);
    b.y = (si*a.x+co*a.y);
    fact = -(sqrtf(b.x*b.x+b.y*b.y)-circle_size)/speed+1;
    b.x = (b.x*fact);
    b.y = (b.y*fact);    
    break;

  case 5:
    an = 0.002;
    co = cosf(an);
    si = sinf(an); 
    circle_size = HEIGHT*0.25;
    fact = 1+cosf(atanf(a.x/(a.y+0.00001))*6)*0.02;
    b.x = (co*a.x-si*a.y);
    b.y = (si*a.x+co*a.y);
    b.x = (b.x*fact);
    b.y = (b.y*fact);    
    break;

  default:
    b.x = 0.0;
    b.y = 0.0;
  }      

  b.x += HWIDTH;
  b.y += HHEIGHT;

  if (b.x < 0.0 )
    b.x = 0.0;
  if (b.y < 0.0)
    b.y = 0.0;
  if (b.x > (gfloat)MAXX)
    b.x = (gfloat)MAXX;
  if (b.y > (gfloat)MAXY)
    b.y = (gfloat)MAXY;

  return b;
}


/* Biniou plugin callbacks */
static u_char num_effect = 0;
static BTimer_t *timer = NULL;
static Shuffler_t *shuffler = NULL;
static VectorField_t *vf = NULL;


void
create(__attribute__ ((unused)) Context_t *ctx)
{
  vf = VectorField_new(NB_FCT, &fct);
  timer = b_timer_new();
  shuffler = Shuffler_new(NB_FCT);
}


void
destroy(__attribute__ ((unused)) Context_t *ctx)
{
  VectorField_delete(vf);
  b_timer_delete(timer);
  Shuffler_delete(shuffler);
}


void
on_switch_on(__attribute__ ((unused)) Context_t *ctx)
{
  num_effect = Shuffler_get(shuffler);
  b_timer_start(timer);
}


void
run(Context_t *ctx)
{
  /* printf("oOo %s:%d: effect= %d\n", __FILE__, __LINE__, num_effect); */
  VectorField_run(vf, ctx, num_effect);

  /* TODO remove hardcoded 5 seconds delay */
  if (b_timer_elapsed(timer) > 5)
    on_switch_on(ctx);
}