Rev 1857 | Rev 2097 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
964 | jag | 1 | /* |
2 | * lissajous.cc |
||
2009 | jag | 3 | * DIN Is Noise is copyright (c) 2006-2023 Jagannathan Sampath |
1713 | jag | 4 | * DIN Is Noise is released under GNU Public License 2.0 |
1479 | jag | 5 | * For more information, please visit https://dinisnoise.org/ |
964 | jag | 6 | */ |
7 | |||
8 | |||
9 | #include "lissajous.h" |
||
10 | #include "vector2d.h" |
||
11 | #include "ui_list.h" |
||
12 | #include "mouse_slider.h" |
||
13 | #include <vector> |
||
14 | using namespace std; |
||
15 | |||
16 | extern ui_list uis; |
||
17 | |||
18 | extern const float PI_BY_180; |
||
19 | |||
1541 | jag | 20 | lissajous::lissajous () : center (0.5f, 0.0f) { |
964 | jag | 21 | name = "Lissajous"; |
22 | load_params (); |
||
23 | } |
||
24 | |||
25 | lissajous::~lissajous () { |
||
26 | widget_save ("d_lissajous", ctrls); |
||
27 | save_params (); |
||
28 | } |
||
29 | |||
30 | void lissajous::load_params () { |
||
31 | ifstream f (make_fname().c_str(), ios::in); |
||
32 | string ignore; |
||
1541 | jag | 33 | f >> ignore >> speed.x >> ignore >> speed.y >> ignore >> angle.start >> ignore >> angle.end >> ignore >> num_points; |
964 | jag | 34 | } |
35 | |||
36 | void lissajous::save_params () { |
||
37 | ofstream f (make_fname().c_str(), ios::out); |
||
38 | string ignore; |
||
1541 | jag | 39 | f << "speed.x " << speed.x << endl << "speed.y " << speed.y << endl << "angle.start " << angle.start << endl << "angle.end " << angle.end << endl << "num_points " << num_points << endl; |
964 | jag | 40 | } |
41 | |||
42 | |||
43 | void lissajous::setup () { |
||
44 | |||
45 | plugin::setup (); |
||
46 | |||
1541 | jag | 47 | widget* _ctrls [] = {&sp.speed.x, &sp.speed.y, &sp.angle.start, &sp.angle.end, &sp.num_points}; |
48 | for (int i = 0; i < 5; ++i) { |
||
49 | ctrls.push_back (_ctrls[i]); |
||
50 | } |
||
964 | jag | 51 | num_ctrls = ctrls.size (); |
1541 | jag | 52 | /*for (int i = 0; i < num_ctrls; ++i) { |
53 | ctrls[i]->set_moveable(1); |
||
54 | }*/ |
||
964 | jag | 55 | |
1541 | jag | 56 | |
57 | spinner<float>* spn [] = {&sp.speed.x, &sp.speed.y, &sp.angle.start, &sp.angle.end}; |
||
58 | const char* lbl [] = {"X Speed", "Y Speed", "Start angle", "End angle"}; |
||
59 | int ori [] = {mouse_slider_listener::X, mouse_slider_listener::Y, mouse_slider_listener::Y, mouse_slider_listener::Y}; |
||
60 | float val [] = {speed.x, speed.y, angle.start, angle.end}; |
||
61 | float dta [] = {0.01f, 0.01f, 1.0f, 1.0f}; |
||
62 | for (int i = 0; i < 4; ++i) { |
||
964 | jag | 63 | spinner<float>* spi = spn[i]; |
1543 | jag | 64 | spi->set (lbl[i], dta[i], -MILLION, MILLION, this, 0); |
1485 | jag | 65 | spi->set_value (val[i]); |
964 | jag | 66 | spi->orient = ori[i]; |
67 | } |
||
68 | |||
1541 | jag | 69 | sp.num_points.set ("Points", 1, 0, MILLION, this, 0); |
70 | sp.num_points.set_value (num_points); |
||
964 | jag | 71 | |
72 | widget_load ("d_lissajous", ctrls); |
||
73 | |||
74 | render (); |
||
75 | |||
76 | } |
||
77 | |||
78 | void lissajous::render () { |
||
79 | |||
1541 | jag | 80 | num_points = sp.num_points.f_value; |
964 | jag | 81 | if (num_points == 0) return; |
82 | |||
1541 | jag | 83 | speed.x = sp.speed.x.f_value; |
84 | speed.y = sp.speed.y.f_value; |
||
85 | angle.start = sp.angle.start.f_value; |
||
86 | angle.end = sp.angle.end.f_value; |
||
964 | jag | 87 | |
1541 | jag | 88 | theta = angle.start * PI_BY_180; |
89 | dtheta = (angle.end - angle.start) / num_points * PI_BY_180; |
||
90 | |||
975 | jag | 91 | int j = num_points + 1; |
92 | points.resize (j); |
||
93 | for (int i = 0; i < j; ++i) { |
||
1541 | jag | 94 | float rtheta = theta; |
95 | float rtheta1 = speed.x * rtheta; |
||
96 | float rtheta2 = speed.y * rtheta; |
||
975 | jag | 97 | point<float>& pi = points[i]; |
1541 | jag | 98 | pi.x = center.x + sin (rtheta1); |
99 | pi.y = center.y + sin (rtheta2); |
||
964 | jag | 100 | theta += dtheta; |
101 | } |
||
102 | |||
103 | ss.str(""); |
||
1541 | jag | 104 | ss << "lissajous_" << speed.x << '_' << speed.y; |
978 | jag | 105 | gen_pts (); |
964 | jag | 106 | |
107 | } |