Debian Codegraph @

src/generator/partik0l/partik0l.cpp

raw symbols SCIP
1 /*
2 * Particle generator
3 * (c) Copyright 2004-2007 Denis Roio aka jaromil <[email protected]>
4 *
5 * blossom original algo is (c) 2003 by ragnar (waves 1.2)
6 * http://home.uninet.ee/~ragnar/waves
7 * further optimizations and changes followed
8 *
9 * This source code is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Public License as published
11 * by the Free Software Foundation; either version 2 of the License,
12 * or (at your option) any later version.
13 *
14 * This source code 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.
17 * Please refer to the GNU Public License for more details.
18 *
19 * You should have received a copy of the GNU Public License along with
20 * this source code; if not, write to:
21 * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 *
23 * "$Id: gen_layer.cpp 845 2007-04-03 07:04:47Z jaromil $"
24 *
25 */
26
27 #if defined(_MSC_VER)
28 #define _USE_MATH_DEFINES
29 #endif /* _MSC_VER */
30 #include <cmath>
31
32 #include "frei0r.hpp"cxx . . $ `<file>/include/frei0r.hpp`/
33
34 #include <stdlib.h>
35 #include <string.h>
36
37 #include <algorithm>
38
39 #include <time.h>
40 #include <inttypes.h>
41 #include <limits.h>
42
43 /* defines for blob size and roundness */
44 #define LIMcxx . . $ `src/generator/partik0l/partik0l.cpp:44:9`! 8 // 25
45 #define NB_BLOBcxx . . $ `src/generator/partik0l/partik0l.cpp:45:9`! 16 // 25
46
47 #define PRIMEScxx . . $ `src/generator/partik0l/partik0l.cpp:47:9`! 11
48
49 class Partik0lcxx . . $ Partik0l#: public frei0rcxx . . $ frei0r/::sourcecxx . . $ frei0r/source# {
50 public:
51
52 Partik0lcxx . . $ Partik0l#Partik0l(b4d55b1286ff73e8).(unsigned int width, unsigned int height);
53 ~cxx . . $ Partik0l#`~Partik0l`(49f6e7a06ebc5aa8).Partik0lcxx . . $ Partik0l#();
54
55 void updatecxx . . $ Partik0l#update(c707e0475ee5518c).(double time,
56 uint32_t* out);
57
58 int wcxx . . $ Partik0l#w., hcxx . . $ Partik0l#h.;
59
60 double upcxx . . $ Partik0l#up.;
61 double downcxx . . $ Partik0l#down.;
62
63 private:
64
65 uint32_t sizecxx . . $ Partik0l#size.;
66
67 /* blossom vars */
68 double blossom_countcxx . . $ Partik0l#blossom_count.;
69 double blossom_mcxx . . $ Partik0l#blossom_m.;
70 double blossom_ncxx . . $ Partik0l#blossom_n.;
71 double blossom_icxx . . $ Partik0l#blossom_i.;
72 double blossom_jcxx . . $ Partik0l#blossom_j.;
73 double blossom_kcxx . . $ Partik0l#blossom_k.;
74 double blossom_lcxx . . $ Partik0l#blossom_l.;
75 float blossom_rcxx . . $ Partik0l#blossom_r.;
76 float blossom_acxx . . $ Partik0l#blossom_a.;
77
78 /* primes */
79 int primecxx . . $ Partik0l#prime.[11];
80
81 float pi2cxx . . $ Partik0l#pi2.;
82 double wdcxx . . $ Partik0l#wd., hdcxx . . $ Partik0l#hd.;
83
84
85 void blobcxx . . $ Partik0l#blob(a1fdb26a292368b3).(uint32_t* out, int x, int y);
86 void blossomcxx . . $ Partik0l#blossom(218b13e5e7cbf689).(uint32_t* out);
87 void blob_initcxx . . $ Partik0l#blob_init(d4f767463ce0a6b3).(int ray);
88 void blossom_recalcxx . . $ Partik0l#blossom_recal(b45ddcbc8423892c).(bool r);
89
90 /* surface buffer */
91 // uint32_t *pixels;
92 uint32_t *blob_bufcxx . . $ Partik0l#blob_buf.;
93 int blob_sizecxx . . $ Partik0l#blob_size.;
94
95 void fastsrandcxx . . $ Partik0l#fastsrand(cb2f890c2fdad230).(uint32_t seed);
96 uint32_t fastrandcxx . . $ Partik0l#fastrand(db52760e79bf9054).();
97
98 uint32_t randvalcxx . . $ Partik0l#randval.;
99 };
100
101 Partik0lcxx . . $ Partik0l#::Partik0lcxx . . $ Partik0l#Partik0l(b4d55b1286ff73e8).(unsigned int width, unsigned int height) {
102
103 register_paramcxx . . $ frei0r/fx#register_param(acfd1d4411be0164).(upcxx . . $ Partik0l#up., "up"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)., "blossom on a higher prime number"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).);
104 register_paramcxx . . $ frei0r/fx#register_param(acfd1d4411be0164).(downcxx . . $ Partik0l#down., "down"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)., "blossom on a lower prime number"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).);
105
106 /* initialize prime numbers */
107 primecxx . . $ Partik0l#prime.[0] = 2;
108 primecxx . . $ Partik0l#prime.[1] = 3;
109 primecxx . . $ Partik0l#prime.[2] = 5;
110 primecxx . . $ Partik0l#prime.[3] = 7;
111 primecxx . . $ Partik0l#prime.[4] = 11;
112 primecxx . . $ Partik0l#prime.[5] = 13;
113 primecxx . . $ Partik0l#prime.[6] = 17;
114 primecxx . . $ Partik0l#prime.[7] = 19;
115 primecxx . . $ Partik0l#prime.[8] = 23;
116 primecxx . . $ Partik0l#prime.[9] = 29;
117 primecxx . . $ Partik0l#prime.[10] = 31;
118
119 /* blossom vars */
120 blossom_countcxx . . $ Partik0l#blossom_count. = 0;
121 blossom_mcxx . . $ Partik0l#blossom_m. = 0;
122 blossom_ncxx . . $ Partik0l#blossom_n. = 0;
123 blossom_icxx . . $ Partik0l#blossom_i. = 0;
124 blossom_jcxx . . $ Partik0l#blossom_j. = 0;
125 blossom_kcxx . . $ Partik0l#blossom_k. = 0;
126 blossom_lcxx . . $ Partik0l#blossom_l. = 0;
127 blossom_rcxx . . $ Partik0l#blossom_r. = 1;
128 blossom_acxx . . $ Partik0l#blossom_a. = 0;
129
130 upcxx . . $ Partik0l#up. = 0;
131 downcxx . . $ Partik0l#down. = 0;
132
133 pi2cxx . . $ Partik0l#pi2. = 2.0*M_PIcxx . . $ `<external>/11263917310783833665/math.h:1289:10`!;
134
135 fastsrandcxx . . $ Partik0l#fastsrand(cb2f890c2fdad230).( ::time(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:416:9`!) );
136
137 wcxx . . $ Partik0l#w. = width;
138 hcxx . . $ Partik0l#h. = height;
139 sizecxx . . $ Partik0l#size. = wcxx . . $ Partik0l#w. * hcxx . . $ Partik0l#h. * 4; // 32bit pixels
140 // pixels = (uint32_t*)malloc(size);
141
142
143 blob_bufcxx . . $ Partik0l#blob_buf. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:416:9`!;
144
145 blossom_recalcxx . . $ Partik0l#blossom_recal(b45ddcbc8423892c).(true);
146
147 /* blob initialization */
148 blob_initcxx . . $ Partik0l#blob_init(d4f767463ce0a6b3).(8);
149
150
151 }
152
153 Partik0lcxx . . $ Partik0l#::~cxx . . $ Partik0l#`~Partik0l`(49f6e7a06ebc5aa8).Partik0lcxx . . $ Partik0l#() {
154 // if(pixels) free(pixels);
155 if(blob_bufcxx . . $ Partik0l#blob_buf.) freecxx . . $ free(5d22bdacc48458e8).(blob_bufcxx . . $ Partik0l#blob_buf.);
156 }
157
158
159
160 void Partik0lcxx . . $ Partik0l#::updatecxx . . $ Partik0l#update(c707e0475ee5518c).(double time,
161 uint32_t* out) {
162 /* automatic random recalculation:
163 if( !blossom_count ) {
164 recalculate();
165 blossom_count = 100+(50.0)*rand()/RAND_MAX;
166 } else {
167 blossom_count--;
168 */
169
170 if(upcxx . . $ Partik0l#up.) {
171 blossom_recalcxx . . $ Partik0l#blossom_recal(b45ddcbc8423892c).(false);
172 upcxx . . $ Partik0l#up. = false;
173 } else if(downcxx . . $ Partik0l#down.) {
174 blossom_recalcxx . . $ Partik0l#blossom_recal(b45ddcbc8423892c).(true);
175 downcxx . . $ Partik0l#down. = false;
176 }
177
178 blossom_acxx . . $ Partik0l#blossom_a. += 0.01;
179 if( blossom_acxx . . $ Partik0l#blossom_a. > pi2cxx . . $ Partik0l#pi2. )
180 blossom_acxx . . $ Partik0l#blossom_a. -= pi2cxx . . $ Partik0l#pi2.;
181
182
183 memset(out,0,sizecxx . . $ Partik0l#size.);
184
185 blossomcxx . . $ Partik0l#blossom(218b13e5e7cbf689).(out);
186
187 }
188
189 void Partik0lcxx . . $ Partik0l#::blossom_recalcxx . . $ Partik0l#blossom_recal(b45ddcbc8423892c).(bool r) {
190
191 float z = ((PRIMEScxx . . $ `src/generator/partik0l/partik0l.cpp:47:9`!-2)*fastrandcxx . . $ Partik0l#fastrand(db52760e79bf9054).()/INT_MAXcxx . . $ `<external>/2419331716647297546/limits.h:120:9`!)+1;
192 blossom_mcxx . . $ Partik0l#blossom_m. = 1.0+(30.0)*fastrandcxx . . $ Partik0l#fastrand(db52760e79bf9054).()/INT_MAXcxx . . $ `<external>/2419331716647297546/limits.h:120:9`!;
193 blossom_ncxx . . $ Partik0l#blossom_n. = 1.0+(30.0)*fastrandcxx . . $ Partik0l#fastrand(db52760e79bf9054).()/INT_MAXcxx . . $ `<external>/2419331716647297546/limits.h:120:9`!;
194 blossom_icxx . . $ Partik0l#blossom_i. = primecxx . . $ Partik0l#prime.[ (int) (z*fastrandcxx . . $ Partik0l#fastrand(db52760e79bf9054).()/INT_MAXcxx . . $ `<external>/2419331716647297546/limits.h:120:9`!) ];
195 blossom_jcxx . . $ Partik0l#blossom_j. = primecxx . . $ Partik0l#prime.[ (int) (z*fastrandcxx . . $ Partik0l#fastrand(db52760e79bf9054).()/INT_MAXcxx . . $ `<external>/2419331716647297546/limits.h:120:9`!) ];
196 blossom_kcxx . . $ Partik0l#blossom_k. = primecxx . . $ Partik0l#prime.[ (int) (z*fastrandcxx . . $ Partik0l#fastrand(db52760e79bf9054).()/INT_MAXcxx . . $ `<external>/2419331716647297546/limits.h:120:9`!) ];
197 blossom_lcxx . . $ Partik0l#blossom_l. = primecxx . . $ Partik0l#prime.[ (int) (z*fastrandcxx . . $ Partik0l#fastrand(db52760e79bf9054).()/INT_MAXcxx . . $ `<external>/2419331716647297546/limits.h:120:9`!) ];
198 wdcxx . . $ Partik0l#wd. = (double)wcxx . . $ Partik0l#w.;
199 hdcxx . . $ Partik0l#hd. = (double)hcxx . . $ Partik0l#h.;
200 if(r)
201 blossom_rcxx . . $ Partik0l#blossom_r. = (blossom_rcxx . . $ Partik0l#blossom_r.>=1.0)?1.0:blossom_rcxx . . $ Partik0l#blossom_r.+0.1;
202 else
203 blossom_rcxx . . $ Partik0l#blossom_r. = (blossom_rcxx . . $ Partik0l#blossom_r.<=0.1)?0.1:blossom_rcxx . . $ Partik0l#blossom_r.-0.1;
204 }
205
206 void Partik0lcxx . . $ Partik0l#::blossomcxx . . $ Partik0l#blossom(218b13e5e7cbf689).(uint32_t* out) {
207
208 float a;
209 int x, y;
210 double zx, zy;
211
212 /* here place a formula that draws on the screen
213 the surface being drawn at this point is always blank */
214 for( a=0.0 ; a<pi2cxx . . $ Partik0l#pi2.; a+=0.005 ) {
215 zx = blossom_mcxx . . $ Partik0l#blossom_m.*a;
216 zy = blossom_ncxx . . $ Partik0l#blossom_n.*a;
217 x = (int)(wdcxx . . $ Partik0l#wd.*(0.47+ (blossom_rcxx . . $ Partik0l#blossom_r.*sin(blossom_icxx . . $ Partik0l#blossom_i.*zx+blossom_acxx . . $ Partik0l#blossom_a.)+
218 (1.0-blossom_rcxx . . $ Partik0l#blossom_r.)*sin(blossom_kcxx . . $ Partik0l#blossom_k.*zy+blossom_acxx . . $ Partik0l#blossom_a.)) /2.2 ));
219
220 y = (int)(hdcxx . . $ Partik0l#hd.*(0.47+ (blossom_rcxx . . $ Partik0l#blossom_r.*cos(blossom_jcxx . . $ Partik0l#blossom_j.*zx+blossom_acxx . . $ Partik0l#blossom_a.)+
221 (1.0-blossom_rcxx . . $ Partik0l#blossom_r.)*cos(blossom_lcxx . . $ Partik0l#blossom_l.*zy+blossom_acxx . . $ Partik0l#blossom_a.)) /2.2 ));
222
223 blobcxx . . $ Partik0l#blob(a1fdb26a292368b3).(out, x,y);
224
225 }
226
227 }
228
229 void Partik0lcxx . . $ Partik0l#::blob_initcxx . . $ Partik0l#blob_init(d4f767463ce0a6b3).(int ray) {
230 uint8_t col;
231
232 blob_sizecxx . . $ Partik0l#blob_size. = ray*2;
233
234 /* there is the blob gradient sphere here
235 Niels helps me with this: calculating a circle
236 while(theta <= 360) {
237 double radians = (theta / 180.0) * PI;
238 double dx = ( origin[0] + cos( radians ) * radius );
239 double dy = ( origin[1] + sin( radians ) * radius );
240
241 (there are always some basics you learn at school and then forget)
242 */
243 uint32_t dx,dy;
244 double rad, th;
245 int c;
246 srandcxx . . $ srand(cb2f890c2fdad230).(::time(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:416:9`!));
247 if(blob_bufcxx . . $ Partik0l#blob_buf.) freecxx . . $ free(5d22bdacc48458e8).(blob_bufcxx . . $ Partik0l#blob_buf.);
248
249 blob_bufcxx . . $ Partik0l#blob_buf. = (uint32_t*) calloccxx . . $ calloc(63a7bf2941bfcd7a).(ray*2*ray*2*2,sizeof(uint32_t));
250 // memset(blob_buf,0,ray*2*ray*2*sizeof(uint32_t));
251
252 for(th=1;th<=360;th++) {
253 rad = (th / 180.0) * M_PIcxx . . $ `<external>/11263917310783833665/math.h:1289:10`!;
254 for(c=ray;c>0;c--) {
255 dx = ( (ray) + cos( rad ) * c );
256 dy = ( (ray) + sin( rad ) * c );
257 // col = (int)(10.0*rand()/(RAND_MAX+1.0))/c;
258 // col += 0x99/c * 0.8;
259 col = 0x99/c * 0.8;
260 blob_bufcxx . . $ Partik0l#blob_buf.[ (dx+((ray*2)*dy)) ] =
261 col|(col<<8)|(col<<16)|(col<<24);
262 }
263 }
264
265 }
266
267
268 void Partik0lcxx . . $ Partik0l#::blobcxx . . $ Partik0l#blob(a1fdb26a292368b3).(uint32_t* out, int x, int y) {
269 // if(y>h-blob_size) return;
270 // if(x>w-blob_size) return;
271
272 int i, j;
273 int stride = (wcxx . . $ Partik0l#w.-blob_sizecxx . . $ Partik0l#blob_size.)>>1;
274
275 uint64_t *tmp_scr = (uint64_t*)out + ((x + y*wcxx . . $ Partik0l#w.)>>1);
276 uint64_t *tmp_blob = (uint64_t*)blob_bufcxx . . $ Partik0l#blob_buf.;
277
278 #ifdef HAVE_MMX
279 /* using mmx packed unsaturated addition on bytes
280 for cleaner and shiny result */
281 for(j=blob_size; j>0; j--) {
282 for(i=blob_size>>4; i>0; i--) {
283
284 asm volatile("movq (%1),%%mm0;"
285 "movq 8(%1),%%mm1;"
286 "movq 16(%1),%%mm2;"
287 "movq 24(%1),%%mm3;"
288 "movq 32(%1),%%mm4;"
289 "movq 40(%1),%%mm5;"
290 "movq 48(%1),%%mm6;"
291 "movq 56(%1),%%mm7;"
292
293 "paddusb (%0),%%mm0;" // packed add unsaturated on bytes
294 "paddusb 8(%0),%%mm1;" // addizione clippata
295 "paddusb 16(%0),%%mm2;"
296 "paddusb 24(%0),%%mm3;"
297 "paddusb 32(%0),%%mm4;"
298 "paddusb 40(%0),%%mm5;"
299 "paddusb 48(%0),%%mm6;"
300 "paddusb 56(%0),%%mm7;"
301
302 "movq %%mm0,(%0);"
303 "movq %%mm1,8(%0);"
304 "movq %%mm2,16(%0);"
305 "movq %%mm3,24(%0);"
306 "movq %%mm4,32(%0);"
307 "movq %%mm5,40(%0);"
308 "movq %%mm6,48(%0);"
309 "movq %%mm7,56(%0);"
310 // "paddsw %0, %%mm0;"// halo violetto?
311 :
312 :"r"(tmp_scr),"r"(tmp_blob)
313 :"memory");
314 tmp_scr+=8;
315 tmp_blob+=8;
316 }
317 tmp_scr += stride;
318 }
319 asm("emms;");
320
321
322 #else // ! HAVE_MMX
323 for(j=blob_sizecxx . . $ Partik0l#blob_size.; j>0; j--) {
324 for(i=blob_sizecxx . . $ Partik0l#blob_size.>>1; i>0; i--) {
325 *(tmp_scr++) += *(tmp_blob++);
326 }
327 tmp_scr += stride;
328 }
329 #endif
330
331 }
332
333 /*
334 * fastrand - fast fake random number generator
335 * by Fukuchi Kentarou
336 * Warning: The low-order bits of numbers generated by fastrand()
337 * are bad as random numbers. For example, fastrand()%4
338 * generates 1,2,3,0,1,2,3,0...
339 * You should use high-order bits.
340 *
341 */
342
343
344
345 uint32_t Partik0lcxx . . $ Partik0l#::fastrandcxx . . $ Partik0l#fastrand(db52760e79bf9054).()
346 {
347 // kentaro's original one:
348 // return (randval=randval*1103515245+12345);
349 //15:55 <salsaman2> mine uses two prime numbers and the cycling is much reduced
350 //15:55 <salsaman2> return (randval=randval*1073741789+32749);
351 return(randvalcxx . . $ Partik0l#randval. = randvalcxx . . $ Partik0l#randval. * 1073741789 + 32749 );
352 }
353
354 void Partik0lcxx . . $ Partik0l#::fastsrandcxx . . $ Partik0l#fastsrand(cb2f890c2fdad230).(uint32_t seed)
355 {
356 randvalcxx . . $ Partik0l#randval. = seed;
357 }
358
359 /*
360 bool Partik0l::keypress(int key) {
361 if(key=='p')
362 blossom_recal(true);
363 else if(key=='o')
364 blossom_recal(false);
365 else return(false);
366
367 return(true);
368 }
369 */
370 frei0rcxx . . $ frei0r/::constructcxx . . $ frei0r/construct#<Partik0lcxx . . $ Partik0l#> plugincxx . . $ plugin.("Partik0l"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).,
371 "Particles generated on prime number sinusoidal blossoming"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).,
372 "Jaromil"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).,
373 0,3);