Massive indent of all codes:
[scilab.git] / scilab / modules / graphics / demos / colormap / colormap.dem.sce
1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2 // Copyright (C) 2008 - INRIA - Pierre MARECHAL
3 // Copyright (C) 2010 - DIGITEO - Allan CORNET
4 //
5 // This file is released under the 3-clause BSD license. See COPYING-BSD.
6
7 function demo_colormap()
8
9     global margin_x;
10     global margin_y;
11
12     global padding_x;
13     global padding_y;
14
15     global frame_w;
16     global frame_h;
17
18     global plot_w;
19     global plot_h;
20
21     // Parameters
22     // =========================================================================
23
24     frame_w              = 200;     // Frame width
25     frame_h              = 330;     // Frame height
26
27     plot_w               = 600;     // Plot width
28     plot_h               = 550;     // Plot height
29
30     margin_x             = 15;      // Horizontal margin between each elements
31     margin_y             = 15;      // Vertical margin between each elements
32
33     padding_x            = 10;      // Horizontal padding between each elements
34     padding_y            = 10;      // Vertical padding between each elements
35
36     defaultfont          = "arial"; // Default Font
37     frametitle_font_size = 16;      // Title font size
38     text_font_size       = 12;      // Text font size
39
40     // Figure creation
41     // =========================================================================
42
43     axes_w       = 3*margin_x + frame_w + plot_w;    // axes width
44     axes_h       = 2*margin_y + max(frame_h,plot_h); // axes height
45
46     demo_plot3d = figure(100001);
47
48     demo_plot3d.background      = -2;
49     demo_plot3d.color_map       = jetcolormap(128);
50     demo_plot3d.figure_position = [0 0];
51     demo_plot3d.axes_size       = [axes_w axes_h];
52     demo_plot3d.figure_name     = "Colormap";
53
54     my_frame_pos_x = margin_x;
55     my_frame_pos_y = (axes_h/2-frame_h/2);
56
57     // Frames creation [Control Panel]
58     // =========================================================================
59
60     my_frame = uicontrol( ...
61     "parent"              , demo_plot3d,...
62     "relief"              , "groove",...
63     "style"               , "frame",...
64     "units"               , "pixels",...
65     "position"            , [ my_frame_pos_x my_frame_pos_y frame_w frame_h],...
66     "fontname"            , "arial",...
67     "fontunits"           , "points",...
68     "fontsize"            , 13,...
69     "fontweight"          , "bold", ...
70     "horizontalalignment" , "center", ...
71     "background"          , [1 1 1], ...
72     "tag"                 , "frame_control" ...
73     );
74
75     // Frame title
76     my_frame_title = uicontrol( ...
77     "parent"              , demo_plot3d,...
78     "style"               , "text",...
79     "string"              , "Colormap",...
80     "units"               , "pixels",...
81     "position"            , [ 30+my_frame_pos_x my_frame_pos_y+frame_h-10 frame_w-60 20 ],...
82     "fontname"            , defaultfont,...
83     "fontunits"           , "points",...
84     "fontsize"            , frametitle_font_size,...
85     "horizontalalignment" , "center", ...
86     "background"          , [1 1 1], ...
87     "tag"                 , "title_frame_control" ...
88     );
89
90     // Colormap frame creation
91     // =========================================================================
92
93     my_cmap_frame_w     = frame_w;
94     my_cmap_frame_h     = frame_h;
95
96     // Colormap : Jetcolormap
97
98     jetcolormap_radio = uicontrol( ...
99     "parent"             , demo_plot3d,...
100     "style"              , "radiobutton",...
101     "string"             , "Jet",...
102     "position"           , [ my_frame_pos_x+10 my_frame_pos_y+my_cmap_frame_h-50 my_cmap_frame_w-25 15],...
103     "horizontalalignment", "left",...
104     "fontname"           , defaultfont,...
105     "fontunits"          , "points",...
106     "fontsize"           , text_font_size,...
107     "value"              , 1, ...
108     "background"          , [1 1 1], ...
109     "callback"           , "demo_update_colormap",...
110     "tag"                , "jetcolormap_radio");
111
112     // Colormap : HSVcolormap
113
114     HSVcolormap_radio = uicontrol( ...
115     "parent"             , demo_plot3d,...
116     "style"              , "radiobutton",...
117     "string"             , "HSV",...
118     "position"           , [ my_frame_pos_x+10 my_frame_pos_y+my_cmap_frame_h-70 my_cmap_frame_w-25 15],...
119     "horizontalalignment", "left",...
120     "fontname"           , defaultfont,...
121     "fontunits"          , "points",...
122     "fontsize"           , text_font_size,...
123     "value"              , 0, ...
124     "background"          , [1 1 1], ...
125     "callback"           , "demo_update_colormap",...
126     "tag"                , "HSVcolormap_radio");
127
128     // Colormap : Hotcolormap
129
130     hotcolormap_radio = uicontrol( ...
131     "parent"             , demo_plot3d,...
132     "style"              , "radiobutton",...
133     "string"             , "Hot",...
134     "position"           , [ my_frame_pos_x+10 my_frame_pos_y+my_cmap_frame_h-90 my_cmap_frame_w-25 15],...
135     "horizontalalignment", "left",...
136     "fontname"           , defaultfont,...
137     "fontunits"          , "points",...
138     "fontsize"           , text_font_size,...
139     "value"              , 0, ...
140     "background"          , [1 1 1], ...
141     "callback"           , "demo_update_colormap",...
142     "tag"                , "hotcolormap_radio");
143
144     // Colormap : Graycolormap
145
146     graycolormap_radio = uicontrol( ...
147     "parent"             , demo_plot3d,...
148     "style"              , "radiobutton",...
149     "string"             , "Gray",...
150     "position"           , [ my_frame_pos_x+10 my_frame_pos_y+my_cmap_frame_h-110 my_cmap_frame_w-25 15],...
151     "horizontalalignment", "left",...
152     "fontname"           , defaultfont,...
153     "fontunits"          , "points",...
154     "fontsize"           , text_font_size,...
155     "value"              , 0, ...
156     "background"          , [1 1 1], ...
157     "callback"           , "demo_update_colormap",...
158     "tag"                , "graycolormap_radio");
159
160     // Colormap : Wintercolormap
161
162     wintercolormap_radio = uicontrol( ...
163     "parent"             , demo_plot3d,...
164     "style"              , "radiobutton",...
165     "string"             , "Winter",...
166     "position"           , [ my_frame_pos_x+10 my_frame_pos_y+my_cmap_frame_h-130 my_cmap_frame_w-25 15],...
167     "horizontalalignment", "left",...
168     "fontname"           , defaultfont,...
169     "fontunits"          , "points",...
170     "fontsize"           , text_font_size,...
171     "value"              , 0, ...
172     "background"          , [1 1 1], ...
173     "callback"           , "demo_update_colormap",...
174     "tag"                , "wintercolormap_radio");
175
176     // Colormap : Springcolormap
177
178     springcolormap_radio = uicontrol( ...
179     "parent"             , demo_plot3d,...
180     "style"              , "radiobutton",...
181     "string"             , "Spring",...
182     "position"           , [ my_frame_pos_x+10 my_frame_pos_y+my_cmap_frame_h-150 my_cmap_frame_w-25 15],...
183     "horizontalalignment", "left",...
184     "fontname"           , defaultfont,...
185     "fontunits"          , "points",...
186     "fontsize"           , text_font_size,...
187     "value"              , 0, ...
188     "background"          , [1 1 1], ...
189     "callback"           , "demo_update_colormap",...
190     "tag"                , "springcolormap_radio");
191
192     // Colormap : Summercolormap
193
194     summercolormap_radio = uicontrol( ...
195     "parent"             , demo_plot3d,...
196     "style"              , "radiobutton",...
197     "string"             , "Summer",...
198     "position"           , [ my_frame_pos_x+10 my_frame_pos_y+my_cmap_frame_h-170 my_cmap_frame_w-25 15],...
199     "horizontalalignment", "left",...
200     "fontname"           , defaultfont,...
201     "fontunits"          , "points",...
202     "fontsize"           , text_font_size,...
203     "value"              , 0, ...
204     "background"          , [1 1 1], ...
205     "callback"           , "demo_update_colormap",...
206     "tag"                , "summercolormap_radio");
207
208     // Colormap : Autumncolormap
209
210     autumncolormap_radio = uicontrol( ...
211     "parent"             , demo_plot3d,...
212     "style"              , "radiobutton",...
213     "string"             , "Autumn",...
214     "position"           , [ my_frame_pos_x+10 my_frame_pos_y+my_cmap_frame_h-190 my_cmap_frame_w-25 15],...
215     "horizontalalignment", "left",...
216     "fontname"           , defaultfont,...
217     "fontunits"          , "points",...
218     "fontsize"           , text_font_size,...
219     "value"              , 0, ...
220     "background"          , [1 1 1], ...
221     "callback"           , "demo_update_colormap",...
222     "tag"                , "autumncolormap_radio");
223
224     // Colormap : Bonecolormap
225
226     bonecolormap_radio = uicontrol( ...
227     "parent"             , demo_plot3d,...
228     "style"              , "radiobutton",...
229     "string"             , "Bone",...
230     "position"           , [ my_frame_pos_x+10 my_frame_pos_y+my_cmap_frame_h-210 my_cmap_frame_w-25 15],...
231     "horizontalalignment", "left",...
232     "fontname"           , defaultfont,...
233     "fontunits"          , "points",...
234     "fontsize"           , text_font_size,...
235     "value"              , 0, ...
236     "background"          , [1 1 1], ...
237     "callback"           , "demo_update_colormap",...
238     "tag"                , "bonecolormap_radio");
239
240     // Colormap : Coppercolormap
241
242     coppercolormap_radio = uicontrol( ...
243     "parent"             , demo_plot3d,...
244     "style"              , "radiobutton",...
245     "string"             , "Copper",...
246     "position"           , [ my_frame_pos_x+10 my_frame_pos_y+my_cmap_frame_h-230 my_cmap_frame_w-25 15],...
247     "horizontalalignment", "left",...
248     "fontname"           , defaultfont,...
249     "fontunits"          , "points",...
250     "fontsize"           , text_font_size,...
251     "value"              , 0, ...
252     "background"          , [1 1 1], ...
253     "callback"           , "demo_update_colormap",...
254     "tag"                , "coppercolormap_radio");
255
256     // Colormap : Pinkcolormap
257
258     pinkcolormap_radio = uicontrol( ...
259     "parent"             , demo_plot3d,...
260     "style"              , "radiobutton",...
261     "string"             , "Pink",...
262     "position"           , [ my_frame_pos_x+10 my_frame_pos_y+my_cmap_frame_h-250 my_cmap_frame_w-25 15],...
263     "horizontalalignment", "left",...
264     "fontname"           , defaultfont,...
265     "fontunits"          , "points",...
266     "fontsize"           , text_font_size,...
267     "value"              , 0, ...
268     "background"          , [1 1 1], ...
269     "callback"           , "demo_update_colormap",...
270     "tag"                , "pinkcolormap_radio");
271
272     // Colormap : Rainbowcolormap
273
274     rainbowcolormap_radio = uicontrol( ...
275     "parent"             , demo_plot3d,...
276     "style"              , "radiobutton",...
277     "string"             , "Rainbow",...
278     "position"           , [ my_frame_pos_x+10 my_frame_pos_y+my_cmap_frame_h-270 my_cmap_frame_w-25 15],...
279     "horizontalalignment", "left",...
280     "fontname"           , defaultfont,...
281     "fontunits"          , "points",...
282     "fontsize"           , text_font_size,...
283     "value"              , 0, ...
284     "background"          , [1 1 1], ...
285     "callback"           , "demo_update_colormap",...
286     "tag"                , "rainbowcolormap_radio");
287
288     // Colormap : Oceancolormap
289
290     oceancolormap_radio = uicontrol( ...
291     "parent"             , demo_plot3d,...
292     "style"              , "radiobutton",...
293     "string"             , "Ocean",...
294     "position"           , [ my_frame_pos_x+10 my_frame_pos_y+my_cmap_frame_h-290 my_cmap_frame_w-25 15],...
295     "horizontalalignment", "left",...
296     "fontname"           , defaultfont,...
297     "fontunits"          , "points",...
298     "fontsize"           , text_font_size,...
299     "value"              , 0, ...
300     "background"          , [1 1 1], ...
301     "callback"           , "demo_update_colormap",...
302     "tag"                , "oceancolormap_radio");
303
304     // Colormap : Whitecolormap
305
306     whitecolormap_radio = uicontrol( ...
307     "parent"             , demo_plot3d,...
308     "style"              , "radiobutton",...
309     "string"             , "White",...
310     "position"           , [ my_frame_pos_x+10 my_frame_pos_y+my_cmap_frame_h-310 my_cmap_frame_w-25 15],...
311     "horizontalalignment", "left",...
312     "fontname"           , defaultfont,...
313     "fontunits"          , "points",...
314     "fontsize"           , text_font_size,...
315     "value"              , 0, ...
316     "background"          , [1 1 1], ...
317     "callback"           , "demo_update_colormap",...
318     "tag"                , "whitecolormap_radio");
319
320     // Plot3d creation
321     // =========================================================================
322
323     drawlater();
324     my_plot_axes = gca();
325
326     my_plot_axes.x_label.text       = "";
327     my_plot_axes.y_label.text       = "";
328     my_plot_axes.z_label.text       = "";
329     my_plot_axes.title.text         = "";
330     my_plot_axes.title.font_size    = 5;
331     my_plot_axes.rotation_angles(1) = 80;
332     my_plot_axes.axes_bounds        = [ ((2*margin_x+frame_w)/axes_w)  0  1-((2*margin_x+frame_w)/axes_w)  1];
333
334     // define colormap
335     colormapSize = 128;
336     f = gcf();
337     f.color_map = jetcolormap(128);
338
339     // generate facet coordinates
340     x = %pi * [-1:0.05:1]';z = sin(x)*cos(x)';
341     [x,y,z] = genfac3d(x,x,z);
342
343     // generate colors
344     // colors depending on z, between 1 and colormap size
345     facetsColors = (z + 1) * (colormapSize - 1) / 2 + 1;
346
347     // plot
348     plot3d(x,y,list(z, facetsColors));
349
350     // Colorbar
351     z_min = min(z);
352     z_max = max(z);
353     colorbar(z_min,z_max);
354
355     // Background
356     my_plot_axes.background = color(240,240,240);
357
358     my_plot3d = gce();
359
360     my_plot_axes.rotation_angles(1) = 80;
361
362     drawnow();
363
364     demo_viewCode("colormap.dem.sce");
365
366 endfunction
367
368
369 function demo_update_colormap()
370
371     my_figure    = gcf();
372     my_plot_axes = gca();
373
374     my_figure.immediate_drawing = "off";
375
376     set(findobj("tag", "jetcolormap_radio")     , "value", 0);
377     set(findobj("tag", "hotcolormap_radio")     , "value", 0);
378     set(findobj("tag", "graycolormap_radio")    , "value", 0);
379     set(findobj("tag", "wintercolormap_radio")  , "value", 0);
380     set(findobj("tag", "springcolormap_radio")  , "value", 0);
381     set(findobj("tag", "summercolormap_radio")  , "value", 0);
382     set(findobj("tag", "autumncolormap_radio")  , "value", 0);
383     set(findobj("tag", "bonecolormap_radio")    , "value", 0);
384     set(findobj("tag", "coppercolormap_radio")  , "value", 0);
385     set(findobj("tag", "pinkcolormap_radio")    , "value", 0);
386     set(findobj("tag", "HSVcolormap_radio")     , "value", 0);
387     set(findobj("tag", "rainbowcolormap_radio") , "value", 0);
388     set(findobj("tag", "oceancolormap_radio")   , "value", 0);
389     set(findobj("tag", "whitecolormap_radio")   , "value", 0);
390
391     set(gcbo, "value", 1);
392
393     my_wanted_colormap = get(gcbo,"tag");
394
395     if get(gcbo, "tag") == "jetcolormap_radio" then
396         my_figure.color_map = jetcolormap(128);
397     elseif get(gcbo, "tag") == "hotcolormap_radio" then
398         my_figure.color_map = hotcolormap(128);
399     elseif get(gcbo, "tag") == "graycolormap_radio" then
400         my_figure.color_map = graycolormap(128);
401     elseif get(gcbo, "tag") == "wintercolormap_radio" then
402         my_figure.color_map = wintercolormap(128);
403     elseif get(gcbo, "tag") == "springcolormap_radio" then
404         my_figure.color_map = springcolormap(128);
405     elseif get(gcbo, "tag") == "summercolormap_radio" then
406         my_figure.color_map = summercolormap(128);
407     elseif get(gcbo, "tag") == "autumncolormap_radio" then
408         my_figure.color_map = autumncolormap(128);
409     elseif get(gcbo, "tag") == "bonecolormap_radio" then
410         my_figure.color_map = bonecolormap(128);
411     elseif get(gcbo, "tag") == "coppercolormap_radio" then
412         my_figure.color_map = coppercolormap(128);
413     elseif get(gcbo, "tag") == "pinkcolormap_radio" then
414         my_figure.color_map = pinkcolormap(128);
415     elseif get(gcbo, "tag") == "HSVcolormap_radio" then
416         my_figure.color_map = hsvcolormap(128);
417     elseif get(gcbo, "tag") == "rainbowcolormap_radio" then
418         my_figure.color_map = rainbowcolormap(128);
419     elseif get(gcbo, "tag") == "oceancolormap_radio" then
420         my_figure.color_map = oceancolormap(128);
421     elseif get(gcbo, "tag") == "whitecolormap_radio" then
422         my_figure.color_map = whitecolormap(128);
423     end
424
425     // Background
426     my_plot_axes.background = color(240,240,240);
427
428     my_figure.immediate_drawing = "on";
429
430 endfunction
431
432
433 demo_colormap();
434 clear demo_colormap;