Added parulacolormap
[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     jetcolormap_radio = uicontrol( ...
113     "parent"             , demo_plot3d,...
114     "style"              , "radiobutton",...
115     "string"             , "Parula",...
116     "position"           , [ my_frame_pos_x+10 my_frame_pos_y+my_cmap_frame_h-70 my_cmap_frame_w-25 15],...
117     "horizontalalignment", "left",...
118     "fontname"           , defaultfont,...
119     "fontunits"          , "points",...
120     "fontsize"           , text_font_size,...
121     "value"              , 0, ...
122     "background"          , [1 1 1], ...
123     "callback"           , "demo_update_colormap",...
124     "tag"                , "parulacolormap_radio");
125
126     // Colormap : HSVcolormap
127
128     HSVcolormap_radio = uicontrol( ...
129     "parent"             , demo_plot3d,...
130     "style"              , "radiobutton",...
131     "string"             , "HSV",...
132     "position"           , [ my_frame_pos_x+10 my_frame_pos_y+my_cmap_frame_h-90 my_cmap_frame_w-25 15],...
133     "horizontalalignment", "left",...
134     "fontname"           , defaultfont,...
135     "fontunits"          , "points",...
136     "fontsize"           , text_font_size,...
137     "value"              , 0, ...
138     "background"          , [1 1 1], ...
139     "callback"           , "demo_update_colormap",...
140     "tag"                , "HSVcolormap_radio");
141
142     // Colormap : Hotcolormap
143
144     hotcolormap_radio = uicontrol( ...
145     "parent"             , demo_plot3d,...
146     "style"              , "radiobutton",...
147     "string"             , "Hot",...
148     "position"           , [ my_frame_pos_x+10 my_frame_pos_y+my_cmap_frame_h-110 my_cmap_frame_w-25 15],...
149     "horizontalalignment", "left",...
150     "fontname"           , defaultfont,...
151     "fontunits"          , "points",...
152     "fontsize"           , text_font_size,...
153     "value"              , 0, ...
154     "background"          , [1 1 1], ...
155     "callback"           , "demo_update_colormap",...
156     "tag"                , "hotcolormap_radio");
157
158     // Colormap : Graycolormap
159
160     graycolormap_radio = uicontrol( ...
161     "parent"             , demo_plot3d,...
162     "style"              , "radiobutton",...
163     "string"             , "Gray",...
164     "position"           , [ my_frame_pos_x+10 my_frame_pos_y+my_cmap_frame_h-130 my_cmap_frame_w-25 15],...
165     "horizontalalignment", "left",...
166     "fontname"           , defaultfont,...
167     "fontunits"          , "points",...
168     "fontsize"           , text_font_size,...
169     "value"              , 0, ...
170     "background"          , [1 1 1], ...
171     "callback"           , "demo_update_colormap",...
172     "tag"                , "graycolormap_radio");
173
174     // Colormap : Wintercolormap
175
176     wintercolormap_radio = uicontrol( ...
177     "parent"             , demo_plot3d,...
178     "style"              , "radiobutton",...
179     "string"             , "Winter",...
180     "position"           , [ my_frame_pos_x+10 my_frame_pos_y+my_cmap_frame_h-150 my_cmap_frame_w-25 15],...
181     "horizontalalignment", "left",...
182     "fontname"           , defaultfont,...
183     "fontunits"          , "points",...
184     "fontsize"           , text_font_size,...
185     "value"              , 0, ...
186     "background"          , [1 1 1], ...
187     "callback"           , "demo_update_colormap",...
188     "tag"                , "wintercolormap_radio");
189
190     // Colormap : Springcolormap
191
192     springcolormap_radio = uicontrol( ...
193     "parent"             , demo_plot3d,...
194     "style"              , "radiobutton",...
195     "string"             , "Spring",...
196     "position"           , [ my_frame_pos_x+10 my_frame_pos_y+my_cmap_frame_h-170 my_cmap_frame_w-25 15],...
197     "horizontalalignment", "left",...
198     "fontname"           , defaultfont,...
199     "fontunits"          , "points",...
200     "fontsize"           , text_font_size,...
201     "value"              , 0, ...
202     "background"          , [1 1 1], ...
203     "callback"           , "demo_update_colormap",...
204     "tag"                , "springcolormap_radio");
205
206     // Colormap : Summercolormap
207
208     summercolormap_radio = uicontrol( ...
209     "parent"             , demo_plot3d,...
210     "style"              , "radiobutton",...
211     "string"             , "Summer",...
212     "position"           , [ my_frame_pos_x+10 my_frame_pos_y+my_cmap_frame_h-190 my_cmap_frame_w-25 15],...
213     "horizontalalignment", "left",...
214     "fontname"           , defaultfont,...
215     "fontunits"          , "points",...
216     "fontsize"           , text_font_size,...
217     "value"              , 0, ...
218     "background"          , [1 1 1], ...
219     "callback"           , "demo_update_colormap",...
220     "tag"                , "summercolormap_radio");
221
222     // Colormap : Autumncolormap
223
224     autumncolormap_radio = uicontrol( ...
225     "parent"             , demo_plot3d,...
226     "style"              , "radiobutton",...
227     "string"             , "Autumn",...
228     "position"           , [ my_frame_pos_x+10 my_frame_pos_y+my_cmap_frame_h-210 my_cmap_frame_w-25 15],...
229     "horizontalalignment", "left",...
230     "fontname"           , defaultfont,...
231     "fontunits"          , "points",...
232     "fontsize"           , text_font_size,...
233     "value"              , 0, ...
234     "background"          , [1 1 1], ...
235     "callback"           , "demo_update_colormap",...
236     "tag"                , "autumncolormap_radio");
237
238     // Colormap : Bonecolormap
239
240     bonecolormap_radio = uicontrol( ...
241     "parent"             , demo_plot3d,...
242     "style"              , "radiobutton",...
243     "string"             , "Bone",...
244     "position"           , [ my_frame_pos_x+10 my_frame_pos_y+my_cmap_frame_h-230 my_cmap_frame_w-25 15],...
245     "horizontalalignment", "left",...
246     "fontname"           , defaultfont,...
247     "fontunits"          , "points",...
248     "fontsize"           , text_font_size,...
249     "value"              , 0, ...
250     "background"          , [1 1 1], ...
251     "callback"           , "demo_update_colormap",...
252     "tag"                , "bonecolormap_radio");
253
254     // Colormap : Coppercolormap
255
256     coppercolormap_radio = uicontrol( ...
257     "parent"             , demo_plot3d,...
258     "style"              , "radiobutton",...
259     "string"             , "Copper",...
260     "position"           , [ my_frame_pos_x+10 my_frame_pos_y+my_cmap_frame_h-250 my_cmap_frame_w-25 15],...
261     "horizontalalignment", "left",...
262     "fontname"           , defaultfont,...
263     "fontunits"          , "points",...
264     "fontsize"           , text_font_size,...
265     "value"              , 0, ...
266     "background"          , [1 1 1], ...
267     "callback"           , "demo_update_colormap",...
268     "tag"                , "coppercolormap_radio");
269
270     // Colormap : Pinkcolormap
271
272     pinkcolormap_radio = uicontrol( ...
273     "parent"             , demo_plot3d,...
274     "style"              , "radiobutton",...
275     "string"             , "Pink",...
276     "position"           , [ my_frame_pos_x+10 my_frame_pos_y+my_cmap_frame_h-270 my_cmap_frame_w-25 15],...
277     "horizontalalignment", "left",...
278     "fontname"           , defaultfont,...
279     "fontunits"          , "points",...
280     "fontsize"           , text_font_size,...
281     "value"              , 0, ...
282     "background"          , [1 1 1], ...
283     "callback"           , "demo_update_colormap",...
284     "tag"                , "pinkcolormap_radio");
285
286     // Colormap : Rainbowcolormap
287
288     rainbowcolormap_radio = uicontrol( ...
289     "parent"             , demo_plot3d,...
290     "style"              , "radiobutton",...
291     "string"             , "Rainbow",...
292     "position"           , [ my_frame_pos_x+10 my_frame_pos_y+my_cmap_frame_h-290 my_cmap_frame_w-25 15],...
293     "horizontalalignment", "left",...
294     "fontname"           , defaultfont,...
295     "fontunits"          , "points",...
296     "fontsize"           , text_font_size,...
297     "value"              , 0, ...
298     "background"          , [1 1 1], ...
299     "callback"           , "demo_update_colormap",...
300     "tag"                , "rainbowcolormap_radio");
301
302     // Colormap : Oceancolormap
303
304     oceancolormap_radio = uicontrol( ...
305     "parent"             , demo_plot3d,...
306     "style"              , "radiobutton",...
307     "string"             , "Ocean",...
308     "position"           , [ my_frame_pos_x+10 my_frame_pos_y+my_cmap_frame_h-310 my_cmap_frame_w-25 15],...
309     "horizontalalignment", "left",...
310     "fontname"           , defaultfont,...
311     "fontunits"          , "points",...
312     "fontsize"           , text_font_size,...
313     "value"              , 0, ...
314     "background"          , [1 1 1], ...
315     "callback"           , "demo_update_colormap",...
316     "tag"                , "oceancolormap_radio");
317
318     // Colormap : Whitecolormap
319
320     whitecolormap_radio = uicontrol( ...
321     "parent"             , demo_plot3d,...
322     "style"              , "radiobutton",...
323     "string"             , "White",...
324     "position"           , [ my_frame_pos_x+10 my_frame_pos_y+my_cmap_frame_h-330 my_cmap_frame_w-25 15],...
325     "horizontalalignment", "left",...
326     "fontname"           , defaultfont,...
327     "fontunits"          , "points",...
328     "fontsize"           , text_font_size,...
329     "value"              , 0, ...
330     "background"          , [1 1 1], ...
331     "callback"           , "demo_update_colormap",...
332     "tag"                , "whitecolormap_radio");
333
334     // Plot3d creation
335     // =========================================================================
336
337     drawlater();
338     my_plot_axes = gca();
339
340     my_plot_axes.x_label.text       = "";
341     my_plot_axes.y_label.text       = "";
342     my_plot_axes.z_label.text       = "";
343     my_plot_axes.title.text         = "";
344     my_plot_axes.title.font_size    = 5;
345     my_plot_axes.rotation_angles(1) = 80;
346     my_plot_axes.axes_bounds        = [ ((2*margin_x+frame_w)/axes_w)  0  1-((2*margin_x+frame_w)/axes_w)  1];
347
348     // define colormap
349     colormapSize = 128;
350     f = gcf();
351     f.color_map = jetcolormap(128);
352
353     // generate facet coordinates
354     x = %pi * [-1:0.05:1]';z = sin(x)*cos(x)';
355     [x,y,z] = genfac3d(x,x,z);
356
357     // generate colors
358     // colors depending on z, between 1 and colormap size
359     facetsColors = (z + 1) * (colormapSize - 1) / 2 + 1;
360
361     // plot
362     plot3d(x,y,list(z, facetsColors));
363
364     // Colorbar
365     z_min = min(z);
366     z_max = max(z);
367     colorbar(z_min,z_max);
368
369     // Background
370     my_plot_axes.background = color(240,240,240);
371
372     my_plot3d = gce();
373
374     my_plot_axes.rotation_angles(1) = 80;
375
376     drawnow();
377
378     demo_viewCode("colormap.dem.sce");
379
380 endfunction
381
382
383 function demo_update_colormap()
384
385     my_figure    = gcf();
386     my_plot_axes = gca();
387
388     my_figure.immediate_drawing = "off";
389
390     set(findobj("tag", "jetcolormap_radio")     , "value", 0);
391     set(findobj("tag", "parulacolormap_radio")     , "value", 0);
392     set(findobj("tag", "hotcolormap_radio")     , "value", 0);
393     set(findobj("tag", "graycolormap_radio")    , "value", 0);
394     set(findobj("tag", "wintercolormap_radio")  , "value", 0);
395     set(findobj("tag", "springcolormap_radio")  , "value", 0);
396     set(findobj("tag", "summercolormap_radio")  , "value", 0);
397     set(findobj("tag", "autumncolormap_radio")  , "value", 0);
398     set(findobj("tag", "bonecolormap_radio")    , "value", 0);
399     set(findobj("tag", "coppercolormap_radio")  , "value", 0);
400     set(findobj("tag", "pinkcolormap_radio")    , "value", 0);
401     set(findobj("tag", "HSVcolormap_radio")     , "value", 0);
402     set(findobj("tag", "rainbowcolormap_radio") , "value", 0);
403     set(findobj("tag", "oceancolormap_radio")   , "value", 0);
404     set(findobj("tag", "whitecolormap_radio")   , "value", 0);
405
406     set(gcbo, "value", 1);
407
408     my_wanted_colormap = get(gcbo,"tag");
409
410     if get(gcbo, "tag") == "jetcolormap_radio" then
411         my_figure.color_map = jetcolormap(128);
412     elseif get(gcbo, "tag") == "parulacolormap_radio" then
413         my_figure.color_map = parulacolormap(128);
414     elseif get(gcbo, "tag") == "hotcolormap_radio" then
415         my_figure.color_map = hotcolormap(128);
416     elseif get(gcbo, "tag") == "graycolormap_radio" then
417         my_figure.color_map = graycolormap(128);
418     elseif get(gcbo, "tag") == "wintercolormap_radio" then
419         my_figure.color_map = wintercolormap(128);
420     elseif get(gcbo, "tag") == "springcolormap_radio" then
421         my_figure.color_map = springcolormap(128);
422     elseif get(gcbo, "tag") == "summercolormap_radio" then
423         my_figure.color_map = summercolormap(128);
424     elseif get(gcbo, "tag") == "autumncolormap_radio" then
425         my_figure.color_map = autumncolormap(128);
426     elseif get(gcbo, "tag") == "bonecolormap_radio" then
427         my_figure.color_map = bonecolormap(128);
428     elseif get(gcbo, "tag") == "coppercolormap_radio" then
429         my_figure.color_map = coppercolormap(128);
430     elseif get(gcbo, "tag") == "pinkcolormap_radio" then
431         my_figure.color_map = pinkcolormap(128);
432     elseif get(gcbo, "tag") == "HSVcolormap_radio" then
433         my_figure.color_map = hsvcolormap(128);
434     elseif get(gcbo, "tag") == "rainbowcolormap_radio" then
435         my_figure.color_map = rainbowcolormap(128);
436     elseif get(gcbo, "tag") == "oceancolormap_radio" then
437         my_figure.color_map = oceancolormap(128);
438     elseif get(gcbo, "tag") == "whitecolormap_radio" then
439         my_figure.color_map = whitecolormap(128);
440     end
441
442     // Background
443     my_plot_axes.background = color(240,240,240);
444
445     my_figure.immediate_drawing = "on";
446
447 endfunction
448
449
450 demo_colormap();
451 clear demo_colormap;