Skip to content

Commit ce16413

Browse files
committed
corrected graphic example
1 parent a0f4ae0 commit ce16413

File tree

3 files changed

+77
-23
lines changed

3 files changed

+77
-23
lines changed

doc/manual/manual/visualization/figures.rst

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,11 @@ DefaultView (see :ref:`subsec-graphics-figures-figure2d-defaultview`).
4242

4343
.. code-tab:: py
4444

45-
from codac import *
46-
4745
fig = Figure2D("My figure", GraphicOutput.VIBES | GraphicOutput.IPE)
4846

4947
.. code-tab:: c++
5048

51-
#include <codac>
52-
53-
using namespace codac;
54-
55-
int main()
56-
{
57-
Figure2D figure ("My Figure",GraphicOutput::VIBES|GraphicOutput::IPE);
58-
}
49+
Figure2D figure ("My Figure",GraphicOutput::VIBES|GraphicOutput::IPE);
5950

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

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

8677
.. code-tab:: py
8778

88-
from codac import *
89-
9079
fig = Figure2D("My figure", GraphicOutput.VIBES | GraphicOutput.IPE, True)
9180

9281
.. code-tab:: c++
9382

94-
#include <codac>
83+
Figure2D figure ("My Figure",GraphicOutput::VIBES|GraphicOutput::IPE,true);
84+
85+
.. _subsec-graphics-figures-figure2d-figure-properties:
86+
87+
Figure properties
88+
-----------------
89+
90+
Once created, the properties of a Figure2D object can be modified using the following methods:
91+
92+
.. tabs::
9593

96-
using namespace codac;
94+
.. code-tab:: py
95+
96+
fig.set_window_properties([50,50],[500,500]) # set the window position and size
97+
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
98+
99+
.. code-tab:: c++
97100

98-
int main()
99-
{
100-
Figure2D figure ("My Figure",GraphicOutput::VIBES|GraphicOutput::IPE,true);
101-
}
101+
fig.set_window_properties({50,50},{500,500}); // set the window position and size
102+
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

examples/00_graphics/graphic_examples.cpp

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,57 @@ int main(){
3838

3939
// The previously declared figure "fig2" can now be used as a DefaultView
4040
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());
4194
}

examples/00_graphics/graphic_examples.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,14 @@
7575
fig3.draw_box([[i,i+1],[-4,-3]],[Color.black(),cmap_red_tube.color(ratio)])
7676
fig3.draw_box([[i,i+1],[-5,-4]],[Color.black(),cmap_rainbow.color(ratio)])
7777

78-
fig3 = Figure2D("My figure 3", GraphicOutput.VIBES)
78+
fig4 = Figure2D("My figure 4", GraphicOutput.VIBES)
7979

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

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

0 commit comments

Comments
 (0)