Skip to content

Commit

Permalink
corrected graphic example
Browse files Browse the repository at this point in the history
  • Loading branch information
godardma committed Jan 20, 2025
1 parent a0f4ae0 commit ce16413
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 23 deletions.
37 changes: 19 additions & 18 deletions doc/manual/manual/visualization/figures.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,11 @@ DefaultView (see :ref:`subsec-graphics-figures-figure2d-defaultview`).

.. code-tab:: py

from codac import *

fig = Figure2D("My figure", GraphicOutput.VIBES | GraphicOutput.IPE)

.. code-tab:: c++

#include <codac>

using namespace codac;

int main()
{
Figure2D figure ("My Figure",GraphicOutput::VIBES|GraphicOutput::IPE);
}
Figure2D figure ("My Figure",GraphicOutput::VIBES|GraphicOutput::IPE);

.. _subsec-graphics-figures-figure2d-defaultview:

Expand Down Expand Up @@ -85,17 +76,27 @@ Equivalently, a Figure2D can be used as DefaultView by setting the flag `set_as_

.. code-tab:: py

from codac import *

fig = Figure2D("My figure", GraphicOutput.VIBES | GraphicOutput.IPE, True)

.. code-tab:: c++

#include <codac>
Figure2D figure ("My Figure",GraphicOutput::VIBES|GraphicOutput::IPE,true);

.. _subsec-graphics-figures-figure2d-figure-properties:

Figure properties
-----------------

Once created, the properties of a Figure2D object can be modified using the following methods:

.. tabs::

using namespace codac;
.. code-tab:: py

fig.set_window_properties([50,50],[500,500]) # set the window position and size
fig.set_axes(axis(0,[-10,10]), axis(1,[-10,10])) # set the range of values on each axis : 0 for x-axis, 1 for y-axis

.. code-tab:: c++

int main()
{
Figure2D figure ("My Figure",GraphicOutput::VIBES|GraphicOutput::IPE,true);
}
fig.set_window_properties({50,50},{500,500}); // set the window position and size
fig.set_axes(axis(0,{-10,10}), axis(1,{-10,10})); // set the range of values on each axis : 0 for x-axis, 1 for y-axis
53 changes: 53 additions & 0 deletions examples/00_graphics/graphic_examples.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,57 @@ int main(){

// The previously declared figure "fig2" can now be used as a DefaultView
DefaultView::set(fig2);
DefaultView::draw_box({{2.2,2.5},{2.2,2.5}},{Color::black(),Color::green(0.8)});

DefaultView::set(fig1);
DefaultView::draw_box({{2.2,2.5},{2.2,2.5}},{Color::blue(),Color::cyan(0.8)});

fig2->draw_AUV({1,1,3.14/2},2.,{Color::black(),Color::yellow()});
fig2->draw_tank({2,1,3.14/2},1.,{Color::black(),Color::yellow()});
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()});
fig2->draw_polyline({{2,-0.5},{4,0.5},{3,1.5},{4,2.5},{3,3}}, Color::red());
fig2->draw_polygone({{2,4.5},{4,4.5},{4.2,3.5},{3.5,3}}, {Color::none(),Color::green(0.5)});
fig2->draw_polyline({{-0.8,0},{0,1.5}}, 0.2, {Color::red(),Color::black(0.3)});
fig2->draw_ellipse({1,1},{0.5,2}, 0.2, {Color::blue(),Color::blue(0.3)});
fig2->draw_line({1,1},{3,3}, Color::blue());
fig2->draw_arrow({3,1},{2.2,2}, 0.2, {Color::red(),Color::black(0.3)});

// Colors
// predefined colors without and with opacity
fig2->draw_point({2,2}, {Color::red(),Color::yellow(0.5)});
// HTML color without and with opacity
fig2->draw_box({{2.4,2.9},{2.4,2.9}},{Color("#da3907"),Color("#da390755")});
// HSV color without and with opacity
fig2->draw_box({{2.6,3.1},{2.6,3.1}},{Color({108,90,78},Model::HSV),Color({108,90,78,20},Model::HSV)});

Figure2D fig3 ("My Figure 3",GraphicOutput::VIBES|GraphicOutput::IPE);
fig3.set_axes(axis(0,{-1,21}), axis(1,{-5.5,0.5}));
fig3.set_window_properties({800,250},{500,500});

ColorMap cmap_haxby = ColorMap::haxby();
ColorMap cmap_default = ColorMap::basic();
ColorMap cmap_blue_tube = ColorMap::blue_tube();
ColorMap cmap_red_tube = ColorMap::red_tube();
ColorMap cmap_rainbow = ColorMap::rainbow();

for (double i=0.; i<20; i++)
{
double ratio = i/20.;
fig3.draw_box({{i,i+1},{-1,0}},{Color::black(),cmap_haxby.color(ratio)});
fig3.draw_box({{i,i+1},{-2,-1}},{Color::black(),cmap_default.color(ratio)});
fig3.draw_box({{i,i+1},{-3,-2}},{Color::black(),cmap_blue_tube.color(ratio)});
fig3.draw_box({{i,i+1},{-4,-3}},{Color::black(),cmap_red_tube.color(ratio)});
fig3.draw_box({{i,i+1},{-5,-4}},{Color::black(),cmap_rainbow.color(ratio)});
}

Figure2D fig4 ("My Figure 4",GraphicOutput::VIBES);

fig4.set_axes(axis(0,{-10,10}), axis(1,{-10,10}));

double a=0.5;
ScalarVar t;
// Fermat's spiral
AnalyticFunction f1 ({t},{a*sqrt(t)*cos(t),a*sqrt(t)*sin(t)});
AnalyticTraj traj4 (f1,{0,100});
fig4.draw_trajectory(traj4,ColorMap::rainbow());
}
10 changes: 5 additions & 5 deletions examples/00_graphics/graphic_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@
fig3.draw_box([[i,i+1],[-4,-3]],[Color.black(),cmap_red_tube.color(ratio)])
fig3.draw_box([[i,i+1],[-5,-4]],[Color.black(),cmap_rainbow.color(ratio)])

fig3 = Figure2D("My figure 3", GraphicOutput.VIBES)
fig4 = Figure2D("My figure 4", GraphicOutput.VIBES)

fig3.set_window_properties([500,50],[500,500])
fig3.set_axes(axis(0,[-10,10]), axis(1,[-10,10]))
fig4.set_window_properties([500,50],[500,500])
fig4.set_axes(axis(0,[-10,10]), axis(1,[-10,10]))

a = 0.8
t=ScalarVar()
# Fermat's spiral
f1=AnalyticFunction([t], [a*sqrt(t)*cos(t),a*sqrt(t)*sin(t)])
traj3=AnalyticTrajectory(f1, [0,100])
fig3.draw_trajectory(traj3, ColorMap.rainbow())
traj4=AnalyticTraj(f1, [0,100])
fig4.draw_trajectory(traj4, ColorMap.rainbow())

0 comments on commit ce16413

Please sign in to comment.