|
| 1 | +#include <codac> |
| 2 | + |
| 3 | +using namespace std; |
| 4 | +using namespace codac2; |
| 5 | + |
| 6 | +int main(){ |
| 7 | + |
| 8 | + // Graphics can be directly called without a Figure2D instanciation, using "DefaultView" |
| 9 | + |
| 10 | + DefaultView::set_window_properties({600,600},{300,300}); |
| 11 | + DefaultView::draw_box({{2.2,2.5},{2.2,2.5}},{Color::black(),Color::yellow(0.5)}); |
| 12 | + DefaultView::draw_AUV({1,1,3.14/2},1.,{Color::black(),Color::yellow()}); |
| 13 | + DefaultView::draw_tank({2,1,3.14/2},1.,{Color::black(),Color::yellow()}); |
| 14 | + DefaultView::draw_pie({2,2},{1.5,2.5},{(3*3.14/4)-0.5,(3*3.14/4)+0.5},{Color::blue(),Color::cyan()}); |
| 15 | + DefaultView::draw_polyline({{2,-0.5},{4,0.5},{3,1.5},{4,2.5},{3,3}}, Color::red()); |
| 16 | + DefaultView::draw_polygone({{2,4.5},{4,4.5},{4.2,3.5},{3.5,3}}, {Color::none(),Color::green(0.5)}); |
| 17 | + DefaultView::draw_polyline({{-0.8,0},{0,1.5}}, 0.2, {Color::red(),Color::black(0.3)}); |
| 18 | + |
| 19 | + // Last argument corresponds to "StyleProperties" with one or two colors: edge color + (optional) fill color |
| 20 | + // Predefined Color objects can be configured with a float parameter for opacity (1=opaque, 0=transparent) |
| 21 | + |
| 22 | + // Custom figures can also be created: |
| 23 | + std::shared_ptr<codac2::Figure2D> fig1 = std::make_shared<Figure2D>("My Figure 1",GraphicOutput::VIBES|GraphicOutput::IPE); |
| 24 | + |
| 25 | + // Here, graphics will be rendered by two tools: both VIBES and IPE |
| 26 | + // For VIBES, it requires the VIBes viewer to be launched prior to the execution |
| 27 | + // For IPE, it generates a file named "My figure 1.xml" that can be edited with IPE, and converted to PDF |
| 28 | + |
| 29 | + fig1->set_window_properties({50,50},{500,500}); // position, window size |
| 30 | + fig1->set_axes(axis(0,{-10,10}), axis(1,{-10,10})); // (axis_id,{range_of_values_on_this_axis}) |
| 31 | + fig1->draw_box({{-1,1},{-1,1}},{Color::green(),Color::red(0.2)}); // drawing a green box with red opacity values inside |
| 32 | + fig1->draw_circle({1,1},0.5,Color({255,155,5})); // drawing a circle at (1,1) of radius 0.5 with a custom RGB color |
| 33 | + fig1->draw_ring({1,1},{4,6},Color::red()); // drawing a ring at (1,1) of radius {4,6} with a predefined red color |
| 34 | + |
| 35 | + std::shared_ptr<codac2::Figure2D> fig2 = std::make_shared<Figure2D>("My Figure 2",GraphicOutput::VIBES|GraphicOutput::IPE); |
| 36 | + fig2->set_axes(axis(0,{-1,5}), axis(1,{-1,5})); |
| 37 | + fig2->set_window_properties({250,250},{500,500}); |
| 38 | + |
| 39 | + // The previously declared figure "fig2" can now be used as a DefaultView |
| 40 | + DefaultView::set(fig2); |
| 41 | + DefaultView::draw_box({{2.2,2.5},{2.2,2.5}},{Color::black(),Color::green(0.8)}); |
| 42 | + |
| 43 | + DefaultView::set(fig1); |
| 44 | + DefaultView::draw_box({{2.2,2.5},{2.2,2.5}},{Color::blue(),Color::cyan(0.8)}); |
| 45 | + |
| 46 | + fig2->draw_AUV({1,1,3.14/2},2.,{Color::black(),Color::yellow()}); |
| 47 | + fig2->draw_tank({2,1,3.14/2},1.,{Color::black(),Color::yellow()}); |
| 48 | + fig2->draw_pie({2,2},{1.5,2.5},{(3*3.14/4)-0.5,(3*3.14/4)+0.5},{Color::blue(),Color::cyan()}); |
| 49 | + fig2->draw_polyline({{2,-0.5},{4,0.5},{3,1.5},{4,2.5},{3,3}}, Color::red()); |
| 50 | + fig2->draw_polygone({{2,4.5},{4,4.5},{4.2,3.5},{3.5,3}}, {Color::none(),Color::green(0.5)}); |
| 51 | + fig2->draw_polyline({{-0.8,0},{0,1.5}}, 0.2, {Color::red(),Color::black(0.3)}); |
| 52 | + fig2->draw_ellipse({1,1},{0.5,2}, 0.2, {Color::blue(),Color::blue(0.3)}); |
| 53 | + fig2->draw_line({1,1},{3,3}, Color::blue()); |
| 54 | + fig2->draw_arrow({3,1},{2.2,2}, 0.2, {Color::red(),Color::black(0.3)}); |
| 55 | + |
| 56 | + // Colors |
| 57 | + // predefined colors without and with opacity |
| 58 | + fig2->draw_point({2,2}, {Color::red(),Color::yellow(0.5)}); |
| 59 | + // HTML color without and with opacity |
| 60 | + fig2->draw_box({{2.4,2.9},{2.4,2.9}},{Color("#da3907"),Color("#da390755")}); |
| 61 | + // HSV color without and with opacity |
| 62 | + fig2->draw_box({{2.6,3.1},{2.6,3.1}},{Color({108,90,78},Model::HSV),Color({108,90,78,20},Model::HSV)}); |
| 63 | + |
| 64 | + Figure2D fig3 ("My Figure 3",GraphicOutput::VIBES|GraphicOutput::IPE); |
| 65 | + fig3.set_axes(axis(0,{-1,21}), axis(1,{-5.5,0.5})); |
| 66 | + fig3.set_window_properties({800,250},{500,500}); |
| 67 | + |
| 68 | + ColorMap cmap_haxby = ColorMap::haxby(); |
| 69 | + ColorMap cmap_default = ColorMap::basic(); |
| 70 | + ColorMap cmap_blue_tube = ColorMap::blue_tube(); |
| 71 | + ColorMap cmap_red_tube = ColorMap::red_tube(); |
| 72 | + ColorMap cmap_rainbow = ColorMap::rainbow(); |
| 73 | + |
| 74 | + for (double i=0.; i<20; i++) |
| 75 | + { |
| 76 | + double ratio = i/20.; |
| 77 | + fig3.draw_box({{i,i+1},{-1,0}},{Color::black(),cmap_haxby.color(ratio)}); |
| 78 | + fig3.draw_box({{i,i+1},{-2,-1}},{Color::black(),cmap_default.color(ratio)}); |
| 79 | + fig3.draw_box({{i,i+1},{-3,-2}},{Color::black(),cmap_blue_tube.color(ratio)}); |
| 80 | + fig3.draw_box({{i,i+1},{-4,-3}},{Color::black(),cmap_red_tube.color(ratio)}); |
| 81 | + fig3.draw_box({{i,i+1},{-5,-4}},{Color::black(),cmap_rainbow.color(ratio)}); |
| 82 | + } |
| 83 | + |
| 84 | + Figure2D fig4 ("My Figure 4",GraphicOutput::VIBES); |
| 85 | + |
| 86 | + fig4.set_axes(axis(0,{-10,10}), axis(1,{-10,10})); |
| 87 | + |
| 88 | + double a=0.5; |
| 89 | + ScalarVar t; |
| 90 | + // Fermat's spiral |
| 91 | + AnalyticFunction f1 ({t},{a*sqrt(t)*cos(t),a*sqrt(t)*sin(t)}); |
| 92 | + AnalyticTraj traj4 (f1,{0,100}); |
| 93 | + fig4.draw_trajectory(traj4,ColorMap::rainbow()); |
| 94 | +} |
0 commit comments