]> git.donarmstrong.com Git - lilypond.git/blob - test/bow.cc
bb85ea3e6d5a1a5fa871ac6a2f939d85538031f4
[lilypond.git] / test / bow.cc
1 // vim:sw=2 makeprg=g++\ -g\ bow.cc\ -o\ bow
2 #include <iostream.h>
3 #define PT
4 // #define STAFFHEIGHT 16.0
5 #define STAFFHEIGHT 20.0
6
7 #define UP 1
8 #define DOWN (-1)
9
10 // mmm
11 #define STANDALONE
12
13 #include <math.h>
14
15 typedef void *Paper_def;
16
17 #include "bezier.hh"
18 #include "bezier.cc"
19 #include "offset.cc"
20
21 struct Point
22 {
23   Real x, y;
24 };
25
26 void
27 out (Bezier_bow& b)
28 {
29   cout << "save dx,dy,x,y;\n";
30   for (int i = 0; i < 4; i++)
31       cout << "z" << i + 1 << " = (" << b.control_[i].x ()
32         << ", " << b.control_[i].y () << ");\n";
33   for (int i = 1; i < 3; i++)
34       cout << "z" << i + 4 << " = (" << b.return_[i].x ()
35         << ", " << b.return_[i].y () << ");\n";
36 #if 0
37   cout << "pickup pencircle scaled 0.5pt#;\n";
38   cout << "draw z2--z3; draw (50,0)-- 0.5[z2,z3];\n";
39 #endif
40   cout << "pickup pencircle scaled 4pt#;\n";
41   for (int i = 0; i < 4; i++)
42     cout << "drawdot z" << i + 1 << ";\n";
43   cout << "path boogje;\n";
44 #if 0
45   cout << "pickup pencircle scaled 0.4pt#;\n";
46   cout << "boogje=z1..controls z2 and z3..z4..controls z5 and z6..cycle;\n";
47   cout << "filldraw boogje;\n";
48 #else
49   cout << "pickup pencircle scaled 1.6pt#;\n";
50   cout << "boogje=z1..controls z2 and z3..z4;\n";
51   cout << "draw boogje;\n";
52   cout << "pickup pencircle scaled 0.4pt#;\n";
53   cout << "boogje:=z4..controls z5 and z6..z1;\n";
54   cout << "draw boogje;\n";
55 #endif
56   cout << "showit; shipit;clearit;\n";
57 }
58
59 void
60 bow (Point* points, int n, int d)
61 {
62   Array<Offset> notes;
63   for (int i = 0; i < n; i++)
64     notes.push (Offset (points[i].x, points[i].y));
65 //  cout << "pickup pencircle scaled 8pt#;\n";
66   cout << "pickup pencircle scaled 2pt#;\n";
67   for (int i = 0; i < n; i++)
68     cout << "drawdot (" << notes[i].x () << ", " << notes[i].y () << ");\n";
69   Bezier_bow b (0);
70   b.set (notes, d);
71   b.calc ();
72   out (b);
73   return;
74 }
75
76 int
77 main ()
78 {
79   //cout.unsetf(ios::scientific);
80   cout.setf(ios::fixed);
81 #if 0
82   bow ((Point[6]){ 0,0, 20,0, 40,0, 60,0, 80,0, 100,1 }, 6, 1);
83   bow ((Point[6]){ 0,0, 20,0, 40,30, 60,30, 80,0, 100,1 }, 6, 1);
84   bow ((Point[6]){ 0,0, 20,0, 40,0, 60,0, 80,10, 100,1 }, 6, 1);
85   bow ((Point[6]){ 0,0, 20,0, 40,0, 60,0, 80,40, 100,1 }, 6, 1);
86   bow ((Point[6]){ 0,0, 20,0, 40,0, 60,40, 80,0, 100,1 }, 6, 1);
87   bow ((Point[6]){ 0,10, 20,20, 40,0, 60,40, 80,20, 100,50 }, 6, 1);
88   bow ((Point[6]){ 0,10, 20,20, 40,0, 60,40, 80,20, 100,50 }, 6, -1);
89   bow ((Point[6]){ 0,10, 20,20, 40,0, 60,40, 80,20, 100,100 }, 6, -1);
90   bow ((Point[9]){ 0,0, 20,0, 40,-80, 60,0, 80,0, 100,0, 120,0, 140,0, 160,-1 }, 9, -1);
91   bow ((Point[9]){ 0,0, 40,0, 80,180, 120,0, 160,0, 200,0, 240,0, 280,0, 320,1 }, 9, 1);
92   bow ((Point[9]){ 
93   {0, 0}, 
94   {19.10645980317711, 1}, 
95   {29.402919606354207, 28}, 
96   {55.389379409531308, 1}, 
97   {73.530839212708514, 1}, 
98   {91.672299015885727, 1}, 
99   {111.35901367452229, 1}, 
100   {131.04572833315891, 1}, 
101   {145.76744299179552, 0}
102   }, 
103   9, 1);
104   bow ((Point[6]){ 0,0, 20,0, 40,0, 60,0, 80,0, 100,40 }, 6, 1);
105   bow ((Point[2]){ 0,0, 20,0 }, 2, 1);
106   bow ((Point[2]){ 0,0, 20,-10 }, 2, 1);
107 #endif
108   bow ((Point[6]){ 0,0, 20,0, 40,0, 60,0, 80,0, 100,100 }, 6, 1);
109   cout << "\\end\n";
110   return 0;
111 }
112
113 // vim:sw=2 makeprg=g++\ -g\ bow.cc\ -o\ bow
114 #include <iostream.h>
115 #define PT
116
117 // mmm
118 #define STANDALONE
119
120 #include <math.h>
121
122 typedef void *Paper_def;
123
124 #include "bezier.hh"
125 #include "bezier.cc"
126 #include "mat.hh"
127
128 struct Point
129 {
130   Real x, y;
131 };
132
133 void
134 out (Bezier_bow& b)
135 {
136   cout << "save dx,dy,x,y;\n";
137   for (int i = 0; i < 4; i++)
138       cout << "z" << i + 1 << " = (" << b.control_[i].x ()
139         << ", " << b.control_[i].y () << ");\n";
140   for (int i = 1; i < 3; i++)
141       cout << "z" << i + 4 << " = (" << b.return_[i].x ()
142         << ", " << b.return_[i].y () << ");\n";
143 //  cout << "pickup pencircle scaled 0.5pt#;\n";
144 //  cout << "draw z2--z3; draw (50,0)-- 0.5[z2,z3];\n";
145   cout << "pickup pencircle scaled 4pt#;\n";
146   for (int i = 0; i < 4; i++)
147     cout << "drawdot z" << i + 1 << ";\n";
148 //  cout << "pickup pencircle scaled 0.4pt#;\n";
149   cout << "pickup pencircle scaled 1.6pt#;\n";
150   cout << "path boogje;\n";
151 //  cout << "boogje=z1..controls z2 and z3..z4..controls z5 and z6..cycle;\n";
152   cout << "boogje=z1..controls z2 and z3..z4;\n";
153   cout << "dx=x4-x1;\n";
154   cout << "dy=y4-y1;\n";
155   cout << "draw boogje;\n";
156   cout << "pickup pencircle scaled 0.4pt#;\n";
157   cout << "boogje:=z4..controls z5 and z6..z1;\n";
158   cout << "draw boogje;\n";
159 //  cout << "filldraw boogje;\n";
160   cout << "showit; shipit;clearit;\n";
161 }
162
163 void
164 bow (Point* points, int n, int d)
165 {
166   Array<Offset> notes;
167   for (int i = 0; i < n; i++)
168     notes.push (Offset (points[i].x, points[i].y));
169   cout << "pickup pencircle scaled 8pt#;\n";
170   for (int i = 0; i < n; i++)
171     cout << "drawdot (" << notes[i].x () << ", " << notes[i].y () << ");\n";
172   Bezier_bow b (0);
173   b.set (notes, d);
174   b.calc ();
175   out (b);
176   return;
177 }
178
179 int
180 main ()
181 {
182   //cout.unsetf(ios::scientific);
183   cout.setf(ios::fixed);
184 #if 1
185   bow ((Point[6]){ 0,0, 20,0, 40,0, 60,0, 80,0, 100,1 }, 6, 1);
186   bow ((Point[6]){ 0,0, 20,0, 40,30, 60,30, 80,0, 100,1 }, 6, 1);
187   bow ((Point[6]){ 0,0, 20,0, 40,0, 60,0, 80,10, 100,1 }, 6, 1);
188   bow ((Point[6]){ 0,0, 20,0, 40,0, 60,0, 80,40, 100,1 }, 6, 1);
189   bow ((Point[6]){ 0,0, 20,0, 40,0, 60,40, 80,0, 100,1 }, 6, 1);
190   bow ((Point[6]){ 0,10, 20,20, 40,0, 60,40, 80,20, 100,50 }, 6, 1);
191   bow ((Point[6]){ 0,10, 20,20, 40,0, 60,40, 80,20, 100,50 }, 6, -1);
192   bow ((Point[6]){ 0,10, 20,20, 40,0, 60,40, 80,20, 100,100 }, 6, -1);
193   bow ((Point[9]){ 0,0, 20,0, 40,-80, 60,0, 80,0, 100,0, 120,0, 140,0, 160,-1 }, 9, -1);
194   bow ((Point[9]){ 0,0, 40,0, 80,180, 120,0, 160,0, 200,0, 240,0, 280,0, 320,1 }, 9, 1);
195   bow ((Point[9]){ 
196   {0, 0}, 
197   {19.10645980317711, 1}, 
198   {29.402919606354207, 28}, 
199   {55.389379409531308, 1}, 
200   {73.530839212708514, 1}, 
201   {91.672299015885727, 1}, 
202   {111.35901367452229, 1}, 
203   {131.04572833315891, 1}, 
204   {145.76744299179552, 0}
205   }, 
206   9, 1);
207 #endif
208   bow ((Point[6]){ 0,0, 20,0, 40,0, 60,0, 80,0, 100,40 }, 6, 1);
209   cout << "\\end\n";
210   return 0;
211 }
212