|
| 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 | +} |
0 commit comments