]> git.donarmstrong.com Git - lilypond.git/blob - test/bow.cc
release: 0.1.59
[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 bool experimental_features_global_b = true;
18
19 #include "bezier.hh"
20 #include "bezier.cc"
21 #include "offset.cc"
22
23
24 struct Point
25 {
26   Real x, y;
27 };
28
29 void
30 out (Bezier_bow& b)
31 {
32   cout << "save dx,dy,x,y;\n";
33   for (int i = 0; i < 4; i++)
34       cout << "z" << i + 1 << " = (" << b.control_[i].x ()
35         << ", " << b.control_[i].y () << ");\n";
36   for (int i = 1; i < 3; i++)
37       cout << "z" << i + 4 << " = (" << b.return_[i].x ()
38         << ", " << b.return_[i].y () << ");\n";
39 #if 0
40   cout << "pickup pencircle scaled 0.5pt#;\n";
41   cout << "draw z2--z3; draw (50,0)-- 0.5[z2,z3];\n";
42 #endif
43   cout << "pickup pencircle scaled 4pt#;\n";
44   for (int i = 0; i < 4; i++)
45     cout << "drawdot z" << i + 1 << ";\n";
46   cout << "path boogje;\n";
47 #if 0
48   cout << "pickup pencircle scaled 0.4pt#;\n";
49   cout << "boogje=z1..controls z2 and z3..z4..controls z5 and z6..cycle;\n";
50   cout << "filldraw boogje;\n";
51 #else
52   cout << "pickup pencircle scaled 1.6pt#;\n";
53   cout << "boogje=z1..controls z2 and z3..z4;\n";
54   cout << "draw boogje;\n";
55   cout << "pickup pencircle scaled 0.4pt#;\n";
56   cout << "boogje:=z4..controls z5 and z6..z1;\n";
57   cout << "draw boogje;\n";
58 #endif
59   cout << "showit; shipit;clearit;\n";
60 }
61
62 void
63 bow (Point* points, int n, int d)
64 {
65   Array<Offset> notes;
66   for (int i = 0; i < n; i++)
67     notes.push (Offset (points[i].x, points[i].y));
68 #if 1
69   cout << "pickup pencircle scaled 8pt#;\n";
70 #else
71   cout << "pickup pencircle scaled 2pt#;\n";
72 #endif
73   for (int i = 0; i < n; i++)
74     cout << "drawdot (" << notes[i].x () << ", " << notes[i].y () << ");\n";
75   Bezier_bow b (0);
76   b.set (notes, d);
77   b.calc ();
78   out (b);
79   return;
80 }
81
82 int
83 main ()
84 {
85   //cout.unsetf(ios::scientific);
86   cout.setf(ios::fixed);
87 #if 0
88   bow ((Point[6]){ 0,0, 20,0, 40,0, 60,0, 80,0, 100,1 }, 6, 1);
89   bow ((Point[6]){ 0,0, 20,0, 40,30, 60,30, 80,0, 100,1 }, 6, 1);
90   bow ((Point[6]){ 0,0, 20,0, 40,0, 60,0, 80,10, 100,1 }, 6, 1);
91   bow ((Point[6]){ 0,0, 20,0, 40,0, 60,0, 80,40, 100,1 }, 6, 1);
92   bow ((Point[6]){ 0,0, 20,0, 40,0, 60,40, 80,0, 100,1 }, 6, 1);
93   bow ((Point[6]){ 0,10, 20,20, 40,0, 60,40, 80,20, 100,50 }, 6, 1);
94   bow ((Point[6]){ 0,10, 20,20, 40,0, 60,40, 80,20, 100,50 }, 6, -1);
95   bow ((Point[6]){ 0,10, 20,20, 40,0, 60,40, 80,20, 100,100 }, 6, -1);
96   bow ((Point[9]){ 0,0, 20,0, 40,-80, 60,0, 80,0, 100,0, 120,0, 140,0, 160,-1 }, 9, -1);
97   bow ((Point[9]){ 0,0, 40,0, 80,180, 120,0, 160,0, 200,0, 240,0, 280,0, 320,1 }, 9, 1);
98   bow ((Point[9]){ 
99   {0, 0}, 
100   {19.10645980317711, 1}, 
101   {29.402919606354207, 28}, 
102   {55.389379409531308, 1}, 
103   {73.530839212708514, 1}, 
104   {91.672299015885727, 1}, 
105   {111.35901367452229, 1}, 
106   {131.04572833315891, 1}, 
107   {145.76744299179552, 0}
108   }, 
109   9, 1);
110   bow ((Point[6]){ 0,0, 20,0, 40,0, 60,0, 80,0, 100,40 }, 6, 1);
111   bow ((Point[2]){ 0,0, 20,0 }, 2, 1);
112   bow ((Point[2]){ 0,0, 20,-10 }, 2, 1);
113   bow ((Point[6]){ 0,0, 20,0, 40,0, 60,0, 80,0, 100,100 }, 6, 1);
114
115   bow ((Point[6]){ 0,0, 20,-10, 40,20, 60,-20, 80,20, 100,0 }, 6, 1);
116   bow ((Point[6]){ 0,0, 20,-10, 40,20, 60,-20, 80,20, 100,0 }, 6, -1);
117   bow ((Point[6]){ 0,0, 20,20, 40,0, 60,40, 80,20, 100,50 }, 6, 1);
118   bow ((Point[6]){ 0,0, 20,20, 40,0, 60,40, 80,20, 100,50 }, 6, -1);
119   bow ((Point[6]){ 0,0, 20,20, 40,0, 60,40, 80,20, 100,100 }, 6, -1);
120
121   bow ((Point[6]){ 0,-10, 20,-20, 40,0, 60,-40, 80,-20, 100,-50 }, 6, 1);
122
123   bow ((Point[6]){ 0,10, 20,20, 40,0, 60,40, 80,20, 100,50 }, 6, -1);
124 #endif
125
126   //clipping
127 #if 0
128   bow ((Point[6]){ 0,0, 20,60, 40,0, 60,0, 80,0, 100,1 }, 6, 1);
129
130   bow ((Point[6]){ 0,1, 20,0, 40,0, 60,0, 80,60, 100,0 }, 6, 1);
131   bow ((Point[6]){ 0,0, 20,20, 40,40, 60,60, 80,140, 100,100 }, 6, 1);
132   bow ((Point[6]){ 0,0, 20,20, 40,40, 60,60, 80,20, 100,100 }, 6, -1);
133   bow ((Point[6]){ 0,0, 20,-20, 40,-40, 60,-60, 80,-20, 100,-100 }, 6, 1);
134   bow ((Point[6]){ 0,0, 20,-20, 40,-40, 60,-60, 80,-140, 100,-100 }, 6, -1);
135 #endif
136
137    // bugs
138 //  bow ((Point[6]){ 0,0, 20,0, 40,0, 60,0, 80,40, 100,1 }, 6, 1);
139 //  bow ((Point[6]){ 0,0, 20,0, 40,0, 60,0, 80,-40, 100,1 }, 6, -1);
140 //  bow ((Point[6]){ 0,0, 20,40, 40,0, 60,0, 80,0, 100,1 }, 6, 1);
141 //  bow ((Point[6]){ 0,0, 20,-40, 40,0, 60,0, 80,0, 100,1 }, 6, -1);
142
143   bow ((Point[6]){ 0,0, 20,-40, 40,0, 60,20, 80,20, 100,40 }, 6, -1);
144   bow ((Point[6]){ 0,0, 20,-20, 40,-20, 60,-20, 80,-80, 100,-40 }, 6, -1);
145
146   bow ((Point[6]){ 0,0, 20,20, 40,40, 60,60, 80,140, 100,100 }, 6, 1);
147   cout << "\\end\n";
148   return 0;
149 }
150