cleaning demos graphics, cacsd, differential_equations
[scilab.git] / scilab / modules / graphics / demos / misc / misc.dem.sce
1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2 // Copyright (C) 2008 - INRIA - Pierre MARECHAL
3 //
4 // This file is released into the public domain
5
6 function demo_misc()
7
8     global margin_x;
9     global margin_y;
10
11     global padding_x;
12     global padding_y;
13
14     global frame_w;
15     global frame_h;
16
17     global plot_w;
18     global plot_h;
19
20     // Parameters
21     // =========================================================================
22
23     frame_w              = 200;     // Frame width
24     frame_h              = 330;     // Frame height
25
26     plot_w               = 600;     // Plot width
27     plot_h               = 550;     // Plot height
28
29     margin_x             = 15;      // Horizontal margin between each elements
30     margin_y             = 15;      // Vertical margin between each elements
31
32     padding_x            = 10;      // Horizontal padding between each elements
33     padding_y            = 10;      // Vertical padding between each elements
34
35     defaultfont          = "arial"; // Default Font
36     frametitle_font_size = 16;      // Title font size
37     text_font_size       = 13;      // Text font size
38
39     // Figure creation
40     // =========================================================================
41
42     axes_w       = 3*margin_x + frame_w + plot_w;    // axes width
43     axes_h       = 2*margin_y + max(frame_h,plot_h); // axes height
44
45     demo_plot3d = figure(100001);
46     clf(demo_plot3d,"reset");
47
48     demo_plot3d.background      = -2;
49     demo_plot3d.color_map       = jetcolormap(128);
50     demo_plot3d.axes_size       = [axes_w axes_h];
51     demo_plot3d.figure_name     = gettext("Misc");
52
53     my_frame_pos_x = margin_x;
54     my_frame_pos_y = (axes_h/2-frame_h/2);
55
56     // Frames creation [Control Panel]
57     // =========================================================================
58
59     my_frame = uicontrol( ...
60         "parent"              , demo_plot3d,...
61         "relief"              , "groove",...
62         "style"               , "frame",...
63         "units"               , "pixels",...
64         "position"            , [ my_frame_pos_x my_frame_pos_y frame_w frame_h],...
65         "horizontalalignment" , "center", ...
66         "background"          , [1 1 1], ...
67         "tag"                 , "frame_control" ...
68     );
69
70     // Frame title
71     my_frame_title = uicontrol( ...
72         "parent"              , demo_plot3d,...
73         "style"               , "text",...
74         "string"              , "Colormap",...
75         "units"               , "pixels",...
76         "position"            , [ 30+my_frame_pos_x my_frame_pos_y+frame_h-10 frame_w-60 20 ],...
77         "fontname"            , defaultfont,...
78         "fontunits"           , "points",...
79         "fontsize"            , frametitle_font_size,...
80         "horizontalalignment" , "center", ...
81         "background"          , [1 1 1], ...
82         "tag"                 , "title_frame_control" ...
83     );
84
85     // Colormap frame creation
86     // =========================================================================
87
88     my_cmap_frame_w     = frame_w;
89     my_cmap_frame_h     = frame_h;
90
91     // Colormap : Jetcolormap
92
93     jetcolormap_radio = uicontrol( ...
94         "parent"             , demo_plot3d,...
95         "style"              , "radiobutton",...
96         "string"             , gettext("Jet"),...
97         "position"           , [ my_frame_pos_x+10 my_frame_pos_y+my_cmap_frame_h-50 my_cmap_frame_w-25 15],...
98         "horizontalalignment", "left",...
99         "fontname"           , defaultfont,...
100         "fontunits"          , "points",...
101         "fontsize"           , text_font_size,...
102         "value"              , 1, ...
103         "background"          , [1 1 1], ...
104         "callback"           , "demo_update_misc",...
105         "tag"                , "jetcolormap_radio");
106
107     // Colormap : HSVcolormap
108
109     HSVcolormap_radio = uicontrol( ...
110         "parent"             , demo_plot3d,...
111         "style"              , "radiobutton",...
112         "string"             , gettext("HSV"),...
113         "position"           , [ my_frame_pos_x+10 my_frame_pos_y+my_cmap_frame_h-70 my_cmap_frame_w-25 15],...
114         "horizontalalignment", "left",...
115         "fontname"           , defaultfont,...
116         "fontunits"          , "points",...
117         "fontsize"           , text_font_size,...
118         "value"              , 0, ...
119         "background"          , [1 1 1], ...
120         "callback"           , "demo_update_misc",...
121         "tag"                , "HSVcolormap_radio");
122
123     // Colormap : Hotcolormap
124
125     hotcolormap_radio = uicontrol( ...
126         "parent"             , demo_plot3d,...
127         "style"              , "radiobutton",...
128         "string"             , gettext("Hot"),...
129         "position"           , [ my_frame_pos_x+10 my_frame_pos_y+my_cmap_frame_h-90 my_cmap_frame_w-25 15],...
130         "horizontalalignment", "left",...
131         "fontname"           , defaultfont,...
132         "fontunits"          , "points",...
133         "fontsize"           , text_font_size,...
134         "value"              , 0, ...
135         "background"          , [1 1 1], ...
136         "callback"           , "demo_update_misc",...
137         "tag"                , "hotcolormap_radio");
138
139     // Colormap : Graycolormap
140
141     graycolormap_radio = uicontrol( ...
142         "parent"             , demo_plot3d,...
143         "style"              , "radiobutton",...
144         "string"             , gettext("Gray"),...
145         "position"           , [ my_frame_pos_x+10 my_frame_pos_y+my_cmap_frame_h-110 my_cmap_frame_w-25 15],...
146         "horizontalalignment", "left",...
147         "fontname"           , defaultfont,...
148         "fontunits"          , "points",...
149         "fontsize"           , text_font_size,...
150         "value"              , 0, ...
151         "background"          , [1 1 1], ...
152         "callback"           , "demo_update_misc",...
153         "tag"                , "graycolormap_radio");
154
155     // Colormap : Wintercolormap
156
157     wintercolormap_radio = uicontrol( ...
158         "parent"             , demo_plot3d,...
159         "style"              , "radiobutton",...
160         "string"             , gettext("Winter"),...
161         "position"           , [ my_frame_pos_x+10 my_frame_pos_y+my_cmap_frame_h-130 my_cmap_frame_w-25 15],...
162         "horizontalalignment", "left",...
163         "fontname"           , defaultfont,...
164         "fontunits"          , "points",...
165         "fontsize"           , text_font_size,...
166         "value"              , 0, ...
167         "background"          , [1 1 1], ...
168         "callback"           , "demo_update_misc",...
169         "tag"                , "wintercolormap_radio");
170
171     // Colormap : Springcolormap
172
173     springcolormap_radio = uicontrol( ...
174         "parent"             , demo_plot3d,...
175         "style"              , "radiobutton",...
176         "string"             , gettext("Spring"),...
177         "position"           , [ my_frame_pos_x+10 my_frame_pos_y+my_cmap_frame_h-150 my_cmap_frame_w-25 15],...
178         "horizontalalignment", "left",...
179         "fontname"           , defaultfont,...
180         "fontunits"          , "points",...
181         "fontsize"           , text_font_size,...
182         "value"              , 0, ...
183         "background"          , [1 1 1], ...
184         "callback"           , "demo_update_misc",...
185         "tag"                , "springcolormap_radio");
186
187     // Colormap : Summercolormap
188
189     summercolormap_radio = uicontrol( ...
190         "parent"             , demo_plot3d,...
191         "style"              , "radiobutton",...
192         "string"             , gettext("Summer"),...
193         "position"           , [ my_frame_pos_x+10 my_frame_pos_y+my_cmap_frame_h-170 my_cmap_frame_w-25 15],...
194         "horizontalalignment", "left",...
195         "fontname"           , defaultfont,...
196         "fontunits"          , "points",...
197         "fontsize"           , text_font_size,...
198         "value"              , 0, ...
199         "background"          , [1 1 1], ...
200         "callback"           , "demo_update_misc",...
201         "tag"                , "summercolormap_radio");
202
203     // Colormap : Autumncolormap
204
205     autumncolormap_radio = uicontrol( ...
206         "parent"             , demo_plot3d,...
207         "style"              , "radiobutton",...
208         "string"             , gettext("Autumn"),...
209         "position"           , [ my_frame_pos_x+10 my_frame_pos_y+my_cmap_frame_h-190 my_cmap_frame_w-25 15],...
210         "horizontalalignment", "left",...
211         "fontname"           , defaultfont,...
212         "fontunits"          , "points",...
213         "fontsize"           , text_font_size,...
214         "value"              , 0, ...
215         "background"          , [1 1 1], ...
216         "callback"           , "demo_update_misc",...
217         "tag"                , "autumncolormap_radio");
218
219     // Colormap : Bonecolormap
220
221     bonecolormap_radio = uicontrol( ...
222         "parent"             , demo_plot3d,...
223         "style"              , "radiobutton",...
224         "string"             , gettext("Bone"),...
225         "position"           , [ my_frame_pos_x+10 my_frame_pos_y+my_cmap_frame_h-210 my_cmap_frame_w-25 15],...
226         "horizontalalignment", "left",...
227         "fontname"           , defaultfont,...
228         "fontunits"          , "points",...
229         "fontsize"           , text_font_size,...
230         "value"              , 0, ...
231         "background"          , [1 1 1], ...
232         "callback"           , "demo_update_misc",...
233         "tag"                , "bonecolormap_radio");
234
235     // Colormap : Coppercolormap
236
237     coppercolormap_radio = uicontrol( ...
238         "parent"             , demo_plot3d,...
239         "style"              , "radiobutton",...
240         "string"             , gettext("Copper"),...
241         "position"           , [ my_frame_pos_x+10 my_frame_pos_y+my_cmap_frame_h-230 my_cmap_frame_w-25 15],...
242         "horizontalalignment", "left",...
243         "fontname"           , defaultfont,...
244         "fontunits"          , "points",...
245         "fontsize"           , text_font_size,...
246         "value"              , 0, ...
247         "background"          , [1 1 1], ...
248         "callback"           , "demo_update_misc",...
249         "tag"                , "coppercolormap_radio");
250
251     // Colormap : Pinkcolormap
252
253     pinkcolormap_radio = uicontrol( ...
254         "parent"             , demo_plot3d,...
255         "style"              , "radiobutton",...
256         "string"             , gettext("Pink"),...
257         "position"           , [ my_frame_pos_x+10 my_frame_pos_y+my_cmap_frame_h-250 my_cmap_frame_w-25 15],...
258         "horizontalalignment", "left",...
259         "fontname"           , defaultfont,...
260         "fontunits"          , "points",...
261         "fontsize"           , text_font_size,...
262         "value"              , 0, ...
263         "background"          , [1 1 1], ...
264         "callback"           , "demo_update_misc",...
265         "tag"                , "pinkcolormap_radio");
266
267     // Colormap : Rainbowcolormap
268
269     rainbowcolormap_radio = uicontrol( ...
270         "parent"             , demo_plot3d,...
271         "style"              , "radiobutton",...
272         "string"             , gettext("Rainbow"),...
273         "position"           , [ my_frame_pos_x+10 my_frame_pos_y+my_cmap_frame_h-270 my_cmap_frame_w-25 15],...
274         "horizontalalignment", "left",...
275         "fontname"           , defaultfont,...
276         "fontunits"          , "points",...
277         "fontsize"           , text_font_size,...
278         "value"              , 0, ...
279         "background"          , [1 1 1], ...
280         "callback"           , "demo_update_misc",...
281         "tag"                , "rainbowcolormap_radio");
282
283     // Colormap : Oceancolormap
284
285     oceancolormap_radio = uicontrol( ...
286         "parent"             , demo_plot3d,...
287         "style"              , "radiobutton",...
288         "string"             , gettext("Ocean"),...
289         "position"           , [ my_frame_pos_x+10 my_frame_pos_y+my_cmap_frame_h-290 my_cmap_frame_w-25 15],...
290         "horizontalalignment", "left",...
291         "fontname"           , defaultfont,...
292         "fontunits"          , "points",...
293         "fontsize"           , text_font_size,...
294         "value"              , 0, ...
295         "background"          , [1 1 1], ...
296         "callback"           , "demo_update_misc",...
297         "tag"                , "oceancolormap_radio");
298
299     // Colormap : Whitecolormap
300
301     whitecolormap_radio = uicontrol( ...
302         "parent"             , demo_plot3d,...
303         "style"              , "radiobutton",...
304         "string"             , gettext("White"),...
305         "position"           , [ my_frame_pos_x+10 my_frame_pos_y+my_cmap_frame_h-310 my_cmap_frame_w-25 15],...
306         "horizontalalignment", "left",...
307         "fontname"           , defaultfont,...
308         "fontunits"          , "points",...
309         "fontsize"           , text_font_size,...
310         "value"              , 0, ...
311         "background"          , [1 1 1], ...
312         "callback"           , "demo_update_misc",...
313         "tag"                , "whitecolormap_radio");
314
315     // Plots creation
316     // =========================================================================
317
318     drawlater();
319
320     my_plot_region_pos_x = ((2*margin_x+frame_w)/axes_w);
321     my_plot_region_pos_y = 0;
322     my_plot_region_w     = 1-my_plot_region_pos_x;
323     my_plot_region_h     = 1;
324
325     // First plot : grayplot();  top - left
326
327     my_plot_1_axes  = newaxes();
328     my_plot_1_pos_x = ((2*margin_x+frame_w)/axes_w);
329     my_plot_1_pos_y = 0;
330     my_plot_1_w     = (1-my_plot_region_pos_x)/2;
331     my_plot_1_h     = 1/2;
332     my_plot_1_axes.axes_bounds = [ my_plot_1_pos_x my_plot_1_pos_y my_plot_1_w my_plot_1_h ];
333     grayplot();
334
335     // Second plot : plot3d1(); top right
336
337     my_plot_2_axes  = newaxes();
338     my_plot_2_pos_x = ((2*margin_x+frame_w)/axes_w) + my_plot_region_w/2;
339     my_plot_2_pos_y = 0;
340     my_plot_2_w     = (1-my_plot_region_pos_x)/2;
341     my_plot_2_h     = 1/2;
342     my_plot_2_axes.axes_bounds = [ my_plot_2_pos_x my_plot_2_pos_y my_plot_2_w my_plot_2_h ];
343     plot3d1();
344
345     // Third plot : grayplot();  bottom - left
346
347     my_plot_3_axes  = newaxes();
348     my_plot_3_pos_x = ((2*margin_x+frame_w)/axes_w);
349     my_plot_3_pos_y = 1/2;
350     my_plot_3_w     = (1-my_plot_region_pos_x)/2;
351     my_plot_3_h     = 1/2;
352     my_plot_3_axes.axes_bounds = [ my_plot_3_pos_x my_plot_3_pos_y my_plot_3_w my_plot_3_h ];
353     grayplot();
354
355     // Fourth plot : knot();  bottom - right
356
357     my_plot_4_axes  = newaxes();
358     my_plot_4_pos_x = ((2*margin_x+frame_w)/axes_w) + my_plot_region_w/2;
359     my_plot_4_pos_y = 1/2;
360     my_plot_4_w     = (1-my_plot_region_pos_x)/2;
361     my_plot_4_h     = 1/2;
362     my_plot_4_axes.axes_bounds = [ my_plot_4_pos_x my_plot_4_pos_y my_plot_4_w my_plot_4_h ];
363
364     deff("[x,y,z]=knot(u,v)",["vv=ones(v)";"uu=ones(u);";
365         "x=(5.*cos(u)+cos(u).*cos(v))";
366         "y=(5.*sin(u)+sin(u).*cos(v))";
367         "z=(uu.*sin(v))";])
368
369     nx=60;
370     Nx=(0:nx)/nx;
371     ny=20;
372     Ny=(0:ny)/ny;
373
374     [xx,yy,zz]=eval3dp(knot,2*%pi*Nx,2*%pi*Ny);
375     XXX=[-xx xx];
376     YYY=[-yy zz];
377     ZZZ=[-zz yy];
378     kk1=[1:size(zz,2)];
379
380     kk1=modulo(kk1,60);
381     kk2=kk1;
382     KKK=list(ZZZ,[kk1 kk2]);
383     plot3d(XXX,YYY,KKK,35,70," @ @ ",[2,1,4],[-6,6,-6,6,-6,6]);
384
385     // define colormap
386     colormapSize = 128;
387     f = gcf();
388     f.color_map = jetcolormap(128);
389
390     my_plot_2_axes.background = color(240,240,240);
391     my_plot_4_axes.background = color(240,240,240);
392
393     drawnow();
394     
395     demo_viewCode("misc.dem.sce");
396
397 endfunction
398
399
400 function demo_update_misc()
401
402     my_figure    = gcf();
403
404     my_figure.immediate_drawing = "off";
405
406     set(findobj("tag", "jetcolormap_radio")     , "value", 0);
407     set(findobj("tag", "hotcolormap_radio")     , "value", 0);
408     set(findobj("tag", "graycolormap_radio")    , "value", 0);
409     set(findobj("tag", "wintercolormap_radio")  , "value", 0);
410     set(findobj("tag", "springcolormap_radio")  , "value", 0);
411     set(findobj("tag", "summercolormap_radio")  , "value", 0);
412     set(findobj("tag", "autumncolormap_radio")  , "value", 0);
413     set(findobj("tag", "bonecolormap_radio")    , "value", 0);
414     set(findobj("tag", "coppercolormap_radio")  , "value", 0);
415     set(findobj("tag", "pinkcolormap_radio")    , "value", 0);
416     set(findobj("tag", "HSVcolormap_radio")     , "value", 0);
417     set(findobj("tag", "rainbowcolormap_radio") , "value", 0);
418     set(findobj("tag", "oceancolormap_radio")   , "value", 0);
419     set(findobj("tag", "whitecolormap_radio")   , "value", 0);
420
421     set(gcbo, "value", 1);
422
423     my_wanted_colormap = get(gcbo,"tag");
424
425     if get(gcbo, "tag") == "jetcolormap_radio" then
426         my_figure.color_map = jetcolormap(128);
427     elseif get(gcbo, "tag") == "hotcolormap_radio" then
428         my_figure.color_map = hotcolormap(128);
429     elseif get(gcbo, "tag") == "graycolormap_radio" then
430         my_figure.color_map = graycolormap(128);
431     elseif get(gcbo, "tag") == "wintercolormap_radio" then
432         my_figure.color_map = wintercolormap(128);
433     elseif get(gcbo, "tag") == "springcolormap_radio" then
434         my_figure.color_map = springcolormap(128);
435     elseif get(gcbo, "tag") == "summercolormap_radio" then
436         my_figure.color_map = summercolormap(128);
437     elseif get(gcbo, "tag") == "autumncolormap_radio" then
438         my_figure.color_map = autumncolormap(128);
439     elseif get(gcbo, "tag") == "bonecolormap_radio" then
440         my_figure.color_map = bonecolormap(128);
441     elseif get(gcbo, "tag") == "coppercolormap_radio" then
442         my_figure.color_map = coppercolormap(128);
443     elseif get(gcbo, "tag") == "pinkcolormap_radio" then
444         my_figure.color_map = pinkcolormap(128);
445     elseif get(gcbo, "tag") == "HSVcolormap_radio" then
446         my_figure.color_map = hsvcolormap(128);
447     elseif get(gcbo, "tag") == "rainbowcolormap_radio" then
448         my_figure.color_map = rainbowcolormap(128);
449     elseif get(gcbo, "tag") == "oceancolormap_radio" then
450         my_figure.color_map = oceancolormap(128);
451     elseif get(gcbo, "tag") == "whitecolormap_radio" then
452         my_figure.color_map = whitecolormap(128);
453     end
454
455     // Gray background for 3d axes
456
457     for i = 1:size(my_figure.children,"*"),
458         child = my_figure.children(i);
459         if child.type=="Axes" then
460             if child.view=="3d" then
461                 child.background = color(240,240,240);
462             end
463         end
464     end
465
466     // Plot
467
468     my_figure.immediate_drawing = "on";
469
470     
471
472 endfunction
473
474 demo_misc();
475 clear demo_misc;
476