Mercurial > octave
changeset 22151:283d8dfcad37
Make demos Matlab compatible for comparison with dump_demos script.
* brighten.m, colorcube.m: Replace 'tic' option to axis with setting properties on gca.
* axis.m: Use 'origin', rather than 'zero', for xaxislocation, yaxislocation
demos.
* datetick.m: Fix typo '2' -> 'ax'.
* legend.m: Use labels with call to legend() rather than embedding labels
in call to plot.
* text.m, xlim.m, ylim.m, zlim.m: Remove asserts from demo blocks.
* isonormals.m: Use Matlab syntax in string definitions.
* light.m: Use space between function name and opening parenthesis in demos.
Add missing semicolon at end of lines.
* dump_demos.m: Add helper functions sombrero() and rgbplot() to script so that
demos will run cleanly in Matlab.
author | Rik <rik@octave.org> |
---|---|
date | Wed, 20 Jul 2016 08:54:51 -0700 |
parents | c4901d7a2d7d |
children | 19d54df7d719 |
files | scripts/image/brighten.m scripts/image/colorcube.m scripts/plot/appearance/axis.m scripts/plot/appearance/datetick.m scripts/plot/appearance/legend.m scripts/plot/appearance/text.m scripts/plot/appearance/xlim.m scripts/plot/appearance/ylim.m scripts/plot/appearance/zlim.m scripts/plot/draw/isonormals.m scripts/plot/draw/light.m scripts/testfun/private/dump_demos.m |
diffstat | 12 files changed, 194 insertions(+), 146 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/image/brighten.m Wed Jul 20 15:32:53 2016 +0100 +++ b/scripts/image/brighten.m Wed Jul 20 08:54:51 2016 -0700 @@ -87,7 +87,8 @@ %! clf; %! colormap (gray (64)); %! image (1:64, linspace (0, 1, 64), repmat ((1:64)', 1, 64)); -%! axis ([1, 64, 0, 1], "ticy", "xy"); +%! axis ([1, 64, 0, 1], "xy"); +%! set (gca, "xtick", []); %! title ("default grayscale colormap"); %! pos = get (gcf, "position"); %! pos(1) += pos(3) + 25; @@ -95,7 +96,8 @@ %! figure ("position", pos); %! colormap (gray (64)); %! image (1:64, linspace (0, 1, 64), repmat ((1:64)', 1, 64)); -%! axis ([1, 64, 0, 1], "ticy", "xy"); +%! axis ([1, 64, 0, 1], "xy"); +%! set (gca, "xtick", []); %! brighten (0.5); %! title ("grayscale colormap brightened by 0.5");
--- a/scripts/image/colorcube.m Wed Jul 20 15:32:53 2016 +0100 +++ b/scripts/image/colorcube.m Wed Jul 20 08:54:51 2016 -0700 @@ -93,6 +93,7 @@ %!demo %! ## Show the 'colorcube' colormap as an image %! image (1:64, linspace (0, 1, 64), repmat ((1:64)', 1, 64)); -%! axis ([1, 64, 0, 1], "ticy", "xy"); +%! axis ([1, 64, 0, 1], "xy"); +%! set (gca, "xtick", []); %! colormap (colorcube (64));
--- a/scripts/plot/appearance/axis.m Wed Jul 20 15:32:53 2016 +0100 +++ b/scripts/plot/appearance/axis.m Wed Jul 20 08:54:51 2016 -0700 @@ -555,20 +555,20 @@ %! x = -10:0.1:10; %! y = sin (x)./(1 + abs (x)) + 0.1*x - 0.4; %! plot (x, y); -%! set (gca, 'xaxislocation', 'zero'); -%! set (gca, 'yaxislocation', 'zero'); +%! set (gca, 'xaxislocation', 'origin'); +%! set (gca, 'yaxislocation', 'origin'); %! box off; -%! title ({'no plot box', 'xaxislocation = zero, yaxislocation = zero'}); +%! title ({'no plot box', 'xaxislocation = origin, yaxislocation = origin'}); %!demo %! clf; %! x = -10:0.1:10; %! y = sin (x)./(1+abs (x)) + 0.1*x - 0.4; %! plot (x, y); -%! set (gca, 'xaxislocation', 'zero'); +%! set (gca, 'xaxislocation', 'origin'); %! set (gca, 'yaxislocation', 'left'); %! box off; -%! title ({'no plot box', 'xaxislocation = zero, yaxislocation = left'}); +%! title ({'no plot box', 'xaxislocation = origin, yaxislocation = left'}); %!demo %! clf; @@ -576,10 +576,10 @@ %! y = sin (x)./(1+abs (x)) + 0.1*x - 0.4; %! plot (x, y); %! title ('no plot box'); -%! set (gca, 'xaxislocation', 'zero'); +%! set (gca, 'xaxislocation', 'origin'); %! set (gca, 'yaxislocation', 'right'); %! box off; -%! title ({'no plot box', 'xaxislocation = zero, yaxislocation = right'}); +%! title ({'no plot box', 'xaxislocation = origin, yaxislocation = right'}); %!demo %! clf; @@ -587,9 +587,9 @@ %! y = sin (x)./(1+abs (x)) + 0.1*x - 0.4; %! plot (x, y); %! set (gca, 'xaxislocation', 'bottom'); -%! set (gca, 'yaxislocation', 'zero'); +%! set (gca, 'yaxislocation', 'origin'); %! box off; -%! title ({'no plot box', 'xaxislocation = bottom, yaxislocation = zero'}); +%! title ({'no plot box', 'xaxislocation = bottom, yaxislocation = origin'}); %!demo %! clf; @@ -597,9 +597,9 @@ %! y = sin (x)./(1+abs (x)) + 0.1*x - 0.4; %! plot (x, y); %! set (gca, 'xaxislocation', 'top'); -%! set (gca, 'yaxislocation', 'zero'); +%! set (gca, 'yaxislocation', 'origin'); %! box off; -%! title ({'no plot box', 'xaxislocation = top, yaxislocation = zero'}); +%! title ({'no plot box', 'xaxislocation = top, yaxislocation = origin'}); %!test %! hf = figure ("visible", "off");
--- a/scripts/plot/appearance/datetick.m Wed Jul 20 15:32:53 2016 +0100 +++ b/scripts/plot/appearance/datetick.m Wed Jul 20 08:54:51 2016 -0700 @@ -81,7 +81,7 @@ %! ylabel ('average price'); %! ax = gca; %! set (ax, 'xtick', datenum (1990:5:2005,1,1)); -%! datetick (2, 'x', 'keepticks'); +%! datetick (ax, 'x', 'keepticks'); %! set (ax, 'ytick', 12:16); ## Remove from test statistics. No real tests possible.
--- a/scripts/plot/appearance/legend.m Wed Jul 20 15:32:53 2016 +0100 +++ b/scripts/plot/appearance/legend.m Wed Jul 20 08:54:51 2016 -0700 @@ -1311,12 +1311,10 @@ %!demo %! clf; %! x = 0:1; -%! plot (x, x, ';\alpha;', ... -%! x, 2*x, ';\beta=2\alpha;', ... -%! x, 3*x, ';\gamma=3\alpha;'); -%! h = legend (); +%! plot (x,x, x,2*x, x,3*x); +%! title ('Labels with interpreted Greek text'); +%! h = legend ('\alpha', '\beta=2\alpha', '\gamma=3\alpha'); %! set (h, 'interpreter', 'tex'); -%! title ('Labels with interpreted Greek text'); %!demo %! clf; @@ -1384,7 +1382,7 @@ %! rand_2x3_data2 = [0.44804, 0.84368, 0.23012; 0.72311, 0.58335, 0.90531]; %! bar (rand_2x3_data2); %! ylim ([0 1.2]); -%! title ('"left" option places text label west of colors'); +%! title ('"left" option places colors to the left of text label'); %! legend ('1st Bar', '2nd Bar', '3rd Bar'); %! legend left;
--- a/scripts/plot/appearance/text.m Wed Jul 20 15:32:53 2016 +0100 +++ b/scripts/plot/appearance/text.m Wed Jul 20 08:54:51 2016 -0700 @@ -241,29 +241,16 @@ %!demo %! clf; %! h = text (0.5, 0.3, 'char'); -%! assert ('char', class (get (h, 'string'))); %! h = text (0.5, 0.4, ['char row 1'; 'char row 2']); -%! assert ('char', class (get (h, 'string'))); %! h = text (0.5, 0.6, {'cell2str (1,1)', 'cell2str (1,2)'; 'cell2str (2,1)', 'cell2str (2,2)'}); -%! assert ('cell', class (get (h, 'string'))); %! h = text (0.5, 0.8, 'foobar'); %! set (h, 'string', 1:3); %! h = text ([0.1, 0.1], [0.3, 0.4], 'one string & two objects'); -%! assert ('char', class (get (h(1), 'string'))); -%! assert ('char', class (get (h(2), 'string'))); %! h = text ([0.1, 0.1], [0.5, 0.6], {'one cellstr & two objects'}); -%! assert ('cell', class (get (h(1), 'string'))); -%! assert ('cell', class (get (h(2), 'string'))); %! h = text ([0.1, 0.1], [0.7, 0.8], {'cellstr 1 object 1', 'cellstr 2 object 2'}); -%! assert ('char', class (get (h(1), 'string'))); -%! assert ('char', class (get (h(2), 'string'))); %! h = text ([0.1, 0.1], [0.1, 0.2], ['1st string & 1st object'; '2nd string & 2nd object']); -%! assert ('char', class (get (h(1), 'string'))); -%! assert ('char', class (get (h(2), 'string'))); %! h = text (0.7, 0.6, 'single string'); -%! assert ('char', class (get (h, 'string'))); %! h = text (0.7, 0.5, {'single cell-string'}); -%! assert ('cell', class (get (h, 'string'))); %! xlabel (1:2); %! ylabel (1:2); %! title (1:2);
--- a/scripts/plot/appearance/xlim.m Wed Jul 20 15:32:53 2016 +0100 +++ b/scripts/plot/appearance/xlim.m Wed Jul 20 08:54:51 2016 -0700 @@ -58,28 +58,24 @@ %! line (); %! xlim ([0.2, 0.8]); %! title ('xlim is [0.2, 0.8]'); -%! assert (xlim (), [0.2, 0.8]); %!demo %! clf; %! line (); %! xlim ('auto'); %! title ('xlim is auto'); -%! assert (xlim ('mode'), 'auto'); %!demo %! clf; %! plot3 ([0,1], [0,1], [0,1]); %! xlim ([0.2, 0.8]); %! title ('xlim is [0.2, 0.8]'); -%! assert (xlim (), [0.2, 0.8]); %!demo %! clf; %! plot3 ([0,1], [0,1], [0,1]); %! xlim ('auto'); %! title ('xlim is auto'); -%! assert (xlim ('mode'), 'auto'); %!test %! hf = figure ("visible", "off");
--- a/scripts/plot/appearance/ylim.m Wed Jul 20 15:32:53 2016 +0100 +++ b/scripts/plot/appearance/ylim.m Wed Jul 20 08:54:51 2016 -0700 @@ -58,28 +58,24 @@ %! line (); %! ylim ([0.2, 0.8]); %! title ('ylim is [0.2, 0.8]'); -%! assert (ylim (), [0.2, 0.8]); %!demo %! clf; %! line (); %! ylim ('auto'); %! title ('ylim is auto'); -%! assert (ylim ('mode'), 'auto'); %!demo %! clf; %! plot3 ([0,1], [0,1], [0,1]); %! ylim ([0.2, 0.8]); %! title ('ylim is [0.2, 0.8]'); -%! assert (ylim (), [0.2, 0.8]); %!demo %! clf; %! plot3 ([0,1], [0,1], [0,1]); %! ylim ('auto'); %! title ('ylim is auto'); -%! assert (ylim ('mode'), 'auto'); %!test %! hf = figure ("visible", "off");
--- a/scripts/plot/appearance/zlim.m Wed Jul 20 15:32:53 2016 +0100 +++ b/scripts/plot/appearance/zlim.m Wed Jul 20 08:54:51 2016 -0700 @@ -58,28 +58,24 @@ %! line (); %! zlim ([0.2, 0.8]); %! title ('zlim is [0.2, 0.8]'); -%! assert (zlim (), [0.2, 0.8]); %!demo %! clf; %! line (); %! zlim ('auto'); %! title ('zlim is auto'); -%! assert (zlim ('mode'), 'auto'); %!demo %! clf; %! plot3 ([0,1], [0,1], [0,1]); %! zlim ([0.2, 0.8]); %! title ('zlim is [0.2, 0.8]'); -%! assert (zlim (), [0.2, 0.8]); %!demo %! clf; %! plot3 ([0,1], [0,1], [0,1]); %! zlim ('auto'); %! title ('zlim is auto'); -%! assert (zlim ('mode'), 'auto'); %!test %! hf = figure ("visible", "off");
--- a/scripts/plot/draw/isonormals.m Wed Jul 20 15:32:53 2016 +0100 +++ b/scripts/plot/draw/isonormals.m Wed Jul 20 08:54:51 2016 -0700 @@ -155,13 +155,13 @@ %! hp = patch ("Faces", fac, "Vertices", vert, "FaceVertexCData", cdat); %! vn = isonormals (x, y, z, val, vert); # Compute normals of isosurface %! set (hp, "VertexNormals", vn); # Manually set vertex normals -%! title ("'VertexNormals' from isonormals manually set") +%! title ('''VertexNormals'' from isonormals manually set') %! isofinish (hp); %! %! subplot (2,2,4); view (-38, 20); %! hp = patch ("Faces", fac, "Vertices", vert, "FaceVertexCData", cdat); %! isonormals (x, y, z, val, hp, "negate"); # Use reverse directly -%! title ("patch modified by isonormals (..., 'negate')") +%! title ('patch modified by isonormals (..., ''negate'')') %! isofinish (hp); %!shared x,y,z,val,vert
--- a/scripts/plot/draw/light.m Wed Jul 20 15:32:53 2016 +0100 +++ b/scripts/plot/draw/light.m Wed Jul 20 08:54:51 2016 -0700 @@ -92,34 +92,37 @@ %! [x,y,z] = meshgrid (-2:0.2:2, -2:0.2:2, -2:0.2:2); %! val = x.^2 + y.^2 + z.^2; %! fv1 = isosurface (x, y, z, val, 1); -%! h_patch1 = patch (fv1, "FaceColor", "c", "EdgeColor", "none", "FaceLighting", "Gouraud"); -%! isonormals (x, y, z, val, h_patch1) +%! h_patch1 = patch (fv1, "FaceColor", "c", "EdgeColor", "none", ... +%! "FaceLighting", "Gouraud"); +%! isonormals (x, y, z, val, h_patch1); %! fv2 = isosurface (x, y+3, z, val, 1); -%! h_patch2 = patch (fv2, "FaceColor", "r", "EdgeColor", "none", "FaceLighting", "Gouraud"); -%! isonormals (x, y+3, z, val, h_patch2) +%! h_patch2 = patch (fv2, "FaceColor", "r", "EdgeColor", "none", ... +%! "FaceLighting", "Gouraud"); +%! isonormals (x, y+3, z, val, h_patch2); %! axis equal; axis tight %! title ("Patch with lighting"); -%! view (3) +%! view (3); %! h_light1 = light (); %! -%! h_axes2 = subplot(2, 2, 2); +%! h_axes2 = subplot (2, 2, 2); %! patch (fv1, "FaceColor", "c", "EdgeColor", "none"); %! patch (fv2, "FaceColor", "r", "EdgeColor", "none"); %! axis equal; axis tight %! title ("Patch without lighting"); -%! view (3) +%! view (3); %! %! %% surfaces -%! h_axes3 = subplot(2, 2, 3); -%! h_surf1 = surf (h_axes3, peaks, "LineStyle", "none", "FaceLighting", "Gouraud"); +%! h_axes3 = subplot (2, 2, 3); +%! h_surf1 = surf (h_axes3, peaks, "LineStyle", "none", ... +%! "FaceLighting", "Gouraud"); %! title ("Surface with lighting"); -%! view (3) +%! view (3); %! h_light2 = light (); %! -%! h_axes3 = subplot(2, 2, 4); +%! h_axes3 = subplot (2, 2, 4); %! h_surf2 = surf (h_axes3, peaks, "LineStyle", "none"); %! title ("Surface without lighting"); -%! view (3) +%! view (3); %!demo %! %% Lighting modes @@ -129,21 +132,23 @@ %! %! h_axes1 = axes (); %! fv = isosurface (x, y, z, val, .039); -%! h_patch = patch (fv, "FaceColor", "r", "EdgeColor", "none", "FaceLighting", "none"); -%! isonormals (x, y, z, val, h_patch) +%! h_patch = patch (fv, "FaceColor", "r", "EdgeColor", "none", ... +%! "FaceLighting", "none"); +%! isonormals (x, y, z, val, h_patch); %! fv = isosurface (x+.5, y, z, val, .039); -%! h_patch = patch (fv, "FaceColor", "r", "EdgeColor", "none", "FaceLighting", "flat"); +%! h_patch = patch (fv, "FaceColor", "r", "EdgeColor", "none", ... +%! "FaceLighting", "flat"); %! isonormals (x+.5, y, z, val, h_patch) %! fv = isosurface (x+1, y, z, val, .039); -%! h_patch = patch (fv, "FaceColor", "r", "EdgeColor", "none", "FaceLighting", "Gouraud"); -%! isonormals (x+1, y, z, val, h_patch) +%! h_patch = patch (fv, "FaceColor", "r", "EdgeColor", "none", ... +%! "FaceLighting", "Gouraud"); +%! isonormals (x+1, y, z, val, h_patch); %! axis tight %! axis equal -%! view(2); +%! view (2); %! light ("Position", [-1 1 1]); %! title ("FaceLighting: none - flat - gouraud"); - %!demo %! %% multiple lights %! clf; @@ -152,18 +157,18 @@ %! val = x.^2 + y.^2 + z.^2; %! fv = isosurface (x, y, z, val, 1); %! h_patch = patch (fv, "FaceColor", "w", "EdgeColor", "none", "FaceLighting", "Gouraud"); -%! isonormals (x, y, z, val, h_patch) +%! isonormals (x, y, z, val, h_patch); %! axis equal; axis tight %! title ("Patch with one light"); -%! view (3) +%! view (3); %! h_light = light ("Color", "g"); %! %! h_axes2 = subplot (1, 2, 2); %! h_patch2 = patch (fv, "FaceColor", "w", "EdgeColor", "none", "FaceLighting", "Gouraud"); -%! isonormals (x, y, z, val, h_patch2) +%! isonormals (x, y, z, val, h_patch2); %! axis equal; axis tight %! title ("Patch with three lights"); -%! view (3) +%! view (3); %! h_light1 = light ("Color", "r"); %! h_light2 = light ("Position", [0 1 1], "Color", "b"); %! h_light3 = light ("Position", [-1 -1 2], "Color", "g"); @@ -177,49 +182,49 @@ %! %! fv = isosurface (x, y, z, val, .039); %! h_patch = patch (fv, "FaceColor", "r", "EdgeColor", "none", "FaceLighting", "Gouraud"); -%! set (h_patch, "DiffuseStrength", 0, "SpecularStrength", 0) -%! isonormals (x, y, z, val, h_patch) +%! set (h_patch, "DiffuseStrength", 0, "SpecularStrength", 0); +%! isonormals (x, y, z, val, h_patch); %! fv = isosurface (x+.5, y, z, val, .039); %! h_patch = patch (fv, "FaceColor", "r", "EdgeColor", "none", "FaceLighting", "Gouraud"); -%! set (h_patch, "DiffuseStrength", 0, "SpecularStrength", .5) -%! isonormals (x+.5, y, z, val, h_patch) +%! set (h_patch, "DiffuseStrength", 0, "SpecularStrength", .5); +%! isonormals (x+.5, y, z, val, h_patch); %! fv = isosurface (x+1, y, z, val, .039); %! h_patch = patch (fv, "FaceColor", "r", "EdgeColor", "none", "FaceLighting", "Gouraud"); -%! set (h_patch, "DiffuseStrength", 0, "SpecularStrength", 1) -%! isonormals (x+1, y, z, val, h_patch) +%! set (h_patch, "DiffuseStrength", 0, "SpecularStrength", 1); +%! isonormals (x+1, y, z, val, h_patch); %! %! fv = isosurface (x, y+.5, z, val, .039); %! h_patch = patch (fv, "FaceColor", "r", "EdgeColor", "none", "FaceLighting", "Gouraud"); -%! set (h_patch, "DiffuseStrength", 0.5, "SpecularStrength", 0) -%! isonormals (x, y+.5, z, val, h_patch) +%! set (h_patch, "DiffuseStrength", 0.5, "SpecularStrength", 0); +%! isonormals (x, y+.5, z, val, h_patch); %! fv = isosurface (x+.5, y+.5, z, val, .039); %! h_patch = patch (fv, "FaceColor", "r", "EdgeColor", "none", "FaceLighting", "Gouraud"); -%! set (h_patch, "DiffuseStrength", 0.5, "SpecularStrength", .5) -%! isonormals (x+.5, y+.5, z, val, h_patch) +%! set (h_patch, "DiffuseStrength", 0.5, "SpecularStrength", .5); +%! isonormals (x+.5, y+.5, z, val, h_patch); %! fv = isosurface (x+1, y+.5, z, val, .039); %! h_patch = patch (fv, "FaceColor", "r", "EdgeColor", "none", "FaceLighting", "Gouraud"); -%! set (h_patch, "DiffuseStrength", 0.5, "SpecularStrength", 1) -%! isonormals (x+1, y+.5, z, val, h_patch) +%! set (h_patch, "DiffuseStrength", 0.5, "SpecularStrength", 1); +%! isonormals (x+1, y+.5, z, val, h_patch); %! %! fv = isosurface (x, y+1, z, val, .039); %! h_patch = patch (fv, "FaceColor", "r", "EdgeColor", "none", "FaceLighting", "Gouraud"); -%! set (h_patch, "DiffuseStrength", 1, "SpecularStrength", 0) -%! isonormals (x, y+1, z, val, h_patch) +%! set (h_patch, "DiffuseStrength", 1, "SpecularStrength", 0); +%! isonormals (x, y+1, z, val, h_patch); %! fv = isosurface (x+.5, y+1, z, val, .039); %! h_patch = patch (fv, "FaceColor", "r", "EdgeColor", "none", "FaceLighting", "Gouraud"); -%! set (h_patch, "DiffuseStrength", 1, "SpecularStrength", .5) -%! isonormals (x+.5, y+1, z, val, h_patch) +%! set (h_patch, "DiffuseStrength", 1, "SpecularStrength", .5); +%! isonormals (x+.5, y+1, z, val, h_patch); %! fv = isosurface (x+1, y+1, z, val, .039); %! h_patch = patch (fv, "FaceColor", "r", "EdgeColor", "none", "FaceLighting", "Gouraud"); -%! set (h_patch, "DiffuseStrength", 1, "SpecularStrength", 1) -%! isonormals (x+1, y+1, z, val, h_patch) +%! set (h_patch, "DiffuseStrength", 1, "SpecularStrength", 1); +%! isonormals (x+1, y+1, z, val, h_patch); %! %! axis equal %! h_light = light ("Position", [-1 1 1]); -%! view(2); +%! view (2); %! -%! xlabel ("SpecularStrength") -%! ylabel ("DiffuseStrength") +%! xlabel ("SpecularStrength"); +%! ylabel ("DiffuseStrength"); %!demo @@ -229,65 +234,65 @@ %! val = (x.^2 + y.^2 + z.^2); %! %! h_axes1 = subplot (3,1,3); -%! set (h_axes1, "AmbientLightColor", "g") +%! set (h_axes1, "AmbientLightColor", "g"); %! fv = isosurface (x, y, z, val, .039); %! h_patch = patch (fv, "FaceColor", "r", "EdgeColor", "none", "FaceLighting", "Gouraud"); -%! set (h_patch, "AmbientStrength", 0) -%! isonormals (x, y, z, val, h_patch) +%! set (h_patch, "AmbientStrength", 0); +%! isonormals (x, y, z, val, h_patch); %! fv = isosurface (x+.5, y, z, val, .039); %! h_patch = patch (fv, "FaceColor", "r", "EdgeColor", "none", "FaceLighting", "Gouraud"); -%! set (h_patch, "AmbientStrength", .7) -%! isonormals (x+.5, y, z, val, h_patch) +%! set (h_patch, "AmbientStrength", .7); +%! isonormals (x+.5, y, z, val, h_patch); %! fv = isosurface (x+1, y, z, val, .039); %! h_patch = patch (fv, "FaceColor", "r", "EdgeColor", "none", "FaceLighting", "Gouraud"); -%! set (h_patch, "AmbientStrength", 1) -%! isonormals (x+1, y, z, val, h_patch) +%! set (h_patch, "AmbientStrength", 1); +%! isonormals (x+1, y, z, val, h_patch); %! h_light = light ("Position", [-1 1 1]); %! axis tight %! axis equal -%! view(2); -%! xlabel ("AmbientStrength") -%! ylabel ("AmbientLightColor [0 1 0]") +%! view (2); +%! xlabel ("AmbientStrength"); +%! ylabel ("AmbientLightColor [0 1 0]"); %! %! h_axes2 = subplot (3,1,2); -%! set (h_axes2, "AmbientLightColor", [.5 0 1]) +%! set (h_axes2, "AmbientLightColor", [.5 0 1]); %! fv = isosurface (x, y, z, val, .039); %! h_patch = patch (fv, "FaceColor", "r", "EdgeColor", "none", "FaceLighting", "Gouraud"); -%! set (h_patch, "AmbientStrength", 0) -%! isonormals (x, y, z, val, h_patch) +%! set (h_patch, "AmbientStrength", 0); +%! isonormals (x, y, z, val, h_patch); %! fv = isosurface (x+.5, y, z, val, .039); %! h_patch = patch (fv, "FaceColor", "r", "EdgeColor", "none", "FaceLighting", "Gouraud"); -%! set (h_patch, "AmbientStrength", .7) -%! isonormals (x+.5, y, z, val, h_patch) +%! set (h_patch, "AmbientStrength", .7); +%! isonormals (x+.5, y, z, val, h_patch); %! fv = isosurface (x+1, y, z, val, .039); %! h_patch = patch (fv, "FaceColor", "r", "EdgeColor", "none", "FaceLighting", "Gouraud"); -%! set (h_patch, "AmbientStrength", 1) -%! isonormals (x+1, y, z, val, h_patch) +%! set (h_patch, "AmbientStrength", 1); +%! isonormals (x+1, y, z, val, h_patch); %! h_light = light ("Position", [-1 1 1]); %! axis tight %! axis equal -%! view(2); -%! ylabel ("AmbientLightColor [.5 0 1]") +%! view (2); +%! ylabel ("AmbientLightColor [.5 0 1]"); %! %! h_axes3 = subplot (3,1,1); -%! set (h_axes3, "AmbientLightColor", "w") +%! set (h_axes3, "AmbientLightColor", "w"); %! fv = isosurface (x, y, z, val, .039); %! h_patch = patch (fv, "FaceColor", "r", "EdgeColor", "none", "FaceLighting", "Gouraud"); -%! set (h_patch, "AmbientStrength", 0) -%! isonormals (x, y, z, val, h_patch) +%! set (h_patch, "AmbientStrength", 0); +%! isonormals (x, y, z, val, h_patch); %! fv = isosurface (x+.5, y, z, val, .039); %! h_patch = patch (fv, "FaceColor", "r", "EdgeColor", "none", "FaceLighting", "Gouraud"); -%! set (h_patch, "AmbientStrength", .7) -%! isonormals (x+.5, y, z, val, h_patch) +%! set (h_patch, "AmbientStrength", .7); +%! isonormals (x+.5, y, z, val, h_patch); %! fv = isosurface (x+1, y, z, val, .039); %! h_patch = patch (fv, "FaceColor", "r", "EdgeColor", "none", "FaceLighting", "Gouraud"); -%! set (h_patch, "AmbientStrength", 1) -%! isonormals (x+1, y, z, val, h_patch) +%! set (h_patch, "AmbientStrength", 1); +%! isonormals (x+1, y, z, val, h_patch); %! h_light = light ("Position", [-1 1 1]); %! axis tight %! axis equal -%! view(2); -%! ylabel ("AmbientLightColor [1 1 1]") +%! view (2); +%! ylabel ("AmbientLightColor [1 1 1]"); %!demo %! %% Specular Exponent @@ -298,21 +303,21 @@ %! h_axes = axes (); %! fv = isosurface (x, y, z, val, .039); %! h_patch = patch (fv, "FaceColor", "r", "EdgeColor", "none", "FaceLighting", "Gouraud"); -%! set (h_patch, "SpecularExponent", 15) -%! isonormals (x, y, z, val, h_patch) +%! set (h_patch, "SpecularExponent", 15); +%! isonormals (x, y, z, val, h_patch); %! fv = isosurface (x+.5, y, z, val, .039); %! h_patch = patch (fv, "FaceColor", "r", "EdgeColor", "none", "FaceLighting", "Gouraud"); -%! set (h_patch, "SpecularExponent", 5) -%! isonormals (x+.5, y, z, val, h_patch) +%! set (h_patch, "SpecularExponent", 5); +%! isonormals (x+.5, y, z, val, h_patch); %! fv = isosurface (x+1, y, z, val, .039); %! h_patch = patch (fv, "FaceColor", "r", "EdgeColor", "none", "FaceLighting", "Gouraud"); -%! set (h_patch, "SpecularExponent", 1) -%! isonormals (x+1, y, z, val, h_patch) +%! set (h_patch, "SpecularExponent", 1); +%! isonormals (x+1, y, z, val, h_patch); %! h_light = light ("Position", [-1 1 1]); %! axis tight %! axis equal -%! view(2); -%! xlabel ("SpecularExponent") +%! view (2); +%! xlabel ("SpecularExponent"); %!demo %! %% SpecularColorReflectance @@ -323,21 +328,21 @@ %! h_axes = axes (); %! fv = isosurface (x, y, z, val, .039); %! h_patch = patch (fv, "FaceColor", "r", "EdgeColor", "none", "FaceLighting", "Gouraud"); -%! set (h_patch, "SpecularColorReflectance", 0) -%! isonormals (x, y, z, val, h_patch) +%! set (h_patch, "SpecularColorReflectance", 0); +%! isonormals (x, y, z, val, h_patch); %! fv = isosurface (x+.5, y, z, val, .039); %! h_patch = patch (fv, "FaceColor", "r", "EdgeColor", "none", "FaceLighting", "Gouraud"); -%! set (h_patch, "SpecularColorReflectance", 0.5) -%! isonormals (x+.5, y, z, val, h_patch) +%! set (h_patch, "SpecularColorReflectance", 0.5); +%! isonormals (x+.5, y, z, val, h_patch); %! fv = isosurface (x+1, y, z, val, .039); %! h_patch = patch (fv, "FaceColor", "r", "EdgeColor", "none", "FaceLighting", "Gouraud"); -%! set (h_patch, "SpecularColorReflectance", 1) -%! isonormals (x+1, y, z, val, h_patch) +%! set (h_patch, "SpecularColorReflectance", 1); +%! isonormals (x+1, y, z, val, h_patch); %! h_light = light ("Position", [-1 1 1]); %! axis tight %! axis equal -%! view(2); -%! xlabel ("SpecularColorReflectance") +%! view (2); +%! xlabel ("SpecularColorReflectance"); %!demo %! %% BackFaceLighting @@ -350,8 +355,8 @@ %! "FaceLighting", "Gouraud", "VertexNormals", vn); %! set (h_patch, "BackFaceLighting", "reverselit"); %! h_light = light (); -%! view (h_axes1, [-50 30]) -%! title ("reverselit") +%! view (h_axes1, [-50 30]); +%! title ("reverselit"); %! axis equal %! %! h_axes2 = subplot (1, 3, 2); @@ -359,8 +364,8 @@ %! "FaceLighting", "Gouraud", "VertexNormals", vn); %! set (h_patch, "BackFaceLighting", "lit"); %! h_light = light (); -%! view (h_axes2, [-50 30]) -%! title ("lit") +%! view (h_axes2, [-50 30]); +%! title ("lit"); %! axis equal %! %! h_axes3 = subplot (1, 3, 3); @@ -368,8 +373,8 @@ %! "FaceLighting", "Gouraud", "VertexNormals", vn); %! set (h_patch, "BackFaceLighting", "unlit"); %! h_light = light (); -%! view (h_axes3, [-50 30]) -%! title ("unlit") +%! view (h_axes3, [-50 30]); +%! title ("unlit"); %! axis equal %!demo @@ -382,8 +387,8 @@ %! fv = isosurface (x, y, z, val, .039, z); %! h_patch = patch (fv, "FaceColor", "flat", "EdgeColor", "none", ... %! "FaceLighting", "Gouraud"); -%! set (h_patch, "SpecularExponent", 15) -%! isonormals (x, y, z, val, h_patch) +%! set (h_patch, "SpecularExponent", 15); +%! isonormals (x, y, z, val, h_patch); %! h_light = light ("Position", [-1 1 1]); %! axis tight %! axis equal
--- a/scripts/testfun/private/dump_demos.m Wed Jul 20 15:32:53 2016 +0100 +++ b/scripts/testfun/private/dump_demos.m Wed Jul 20 08:54:51 2016 -0700 @@ -87,8 +87,11 @@ dump_all_demos (d, fid, fmt); endfor + ## Add helper functions like sombrero + dump_helper_fcns (fid); + ## Stop and flush diary - fprintf (fid, "diary off\n"); + fprintf (fid, "\ndiary off\n"); ## Create script ending fprintf (fid, "end\n\n") @@ -153,7 +156,7 @@ fprintf (fid, "%s ();\n", base_fn); endfor endfor - fprintf (fid, "close all\n"); + fprintf (fid, "\nclose all\n"); endfunction @@ -197,3 +200,67 @@ endfunction +function dump_helper_fcns (fid) + + fprintf (fid, "\n%s\n", repmat ("%", [1, 60])); + fdisp (fid, "% Helper functions"); + fprintf (fid, "%s\n", repmat ("%", [1, 60])); + + ## Add sombrero function + fdisp (fid, [ +"function [x, y, z] = sombrero (n) " +" " +" if (nargin == 0) " +" n = 41; " +" end " +" " +" [xx, yy] = meshgrid (linspace (-8, 8, n)); " +" r = sqrt (xx.^2 + yy.^2) + eps; % eps prevents div/0 errors " +" zz = sin (r) ./ r; " +" " +" if (nargout == 0) " +" surf (xx, yy, zz); " +" elseif (nargout == 1) " +" x = zz; " +" else " +" x = xx; " +" y = yy; " +" z = zz; " +" end " +" " +"end " +]); # End of sombrero dump + + fprintf (fid, "\n"); + + ## Add rgbplot function + fdisp (fid, [ +"function h = rgbplot (cmap, style) " +" " +" if (nargin == 1) " +" style = 'profile'; " +" end " +" " +" switch (lower (style)) " +" case 'profile' " +" htmp = plot (cmap(:,1),'r', cmap(:,2),'g', cmap(:,3),'b'); " +" set (gca (), 'ytick', 0:0.1:1); " +" set (gca (), 'xlim', [0 rows(cmap)]); " +" case 'composite' " +" htmp = image (1:rows(cmap)); " +" set (gca, 'ytick', []); " +" colormap (cmap); " +" end " +" xlabel ('color index'); " +" " +" if (nargout > 0) " +" h = htmp; " +" end " +" " +"end " +]); # End of rgbplot dump + + fprintf (fid, "%s\n", repmat ("%", [1, 60])); + +endfunction +