Debian Codegraph @

src/generator/lissajous0r/lissajous0r.cpp

raw symbols SCIP
1 /*
2 This frei0r plugin generates white noise images
3
4 Copyright (C) 2004, 2005 Martin Bayer <[email protected]>
5 Copyright (C) 2005 Georg Seidel <[email protected]>
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
22 #include "frei0r.hpp"
23
24 #include <algorithm>
25 #include <cmath>
26
27
28 #ifndef M_PI
29 #define M_PI 3.14159265358979323846
30 #endif
31
32 class lissajous0r: public frei0r::source
33 {
34 public:
35 lissajous0r(unsigned int width, unsigned int height)
36 {
37 r_x = r_y = 0.0;
38 register_param(r_x,"ratiox","x-ratio");
39 register_param(r_y,"ratioy","y-ratio");
40 }
41
42
43 virtual void update(double time,
44 uint32_t* out)
45 {
46 std::fill(out, out+width*height, 0x00000000);
47
48 double rx=1.0/(0.999999-r_x);
49 double ry=1.0/(0.999999-r_y);
50
51 double w = 0.5*(width-1);
52 double h = 0.5*(height-1);
53
54 const unsigned int samples = 15*(width+height);
55
56 double deltax = (rx*2*M_PI) / (double) samples;
57 double deltay = (ry*2*M_PI) / (double) samples;
58 double tx = 0;
59 double ty = 0;
60 for (unsigned int i=samples; i != 0; --i, tx+=deltax, ty+=deltay)
61 {
62 unsigned int x = static_cast<unsigned int>(w*(1.0+sin(tx)));
63 unsigned int y = static_cast<unsigned int>(h*(1.0+cos(ty)));
64
65 out[width*y + x]=0xffffffff;
66 }
67 }
68 private:
69 double r_x;
70 double r_y;
71 };
72
73
74 frei0r::construct<lissajous0r> plugin("Lissajous0r",
75 "Generates Lissajous0r images",
76 "Martin Bayer",
77 0,3);
78