Home > chronux_1_50 > spikesort > fancy.m

fancy

PURPOSE ^

FANCY Collection of graphics test figures.

SYNOPSIS ^

function fancy(select)

DESCRIPTION ^

FANCY             Collection of graphics test figures.
   fancy(1)    Sphere with a cloudy (transparency-mapped) ring
   fancy(2)    World map, mapped onto a sphere, with transparent oceans
   fancy(3)    3-D relief model of a US penny, with colored lighting

 Each of the figures will briefly animate after creation.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function fancy(select)
0002 %FANCY             Collection of graphics test figures.
0003 %   fancy(1)    Sphere with a cloudy (transparency-mapped) ring
0004 %   fancy(2)    World map, mapped onto a sphere, with transparent oceans
0005 %   fancy(3)    3-D relief model of a US penny, with colored lighting
0006 %
0007 % Each of the figures will briefly animate after creation.
0008 
0009 switch(select),
0010 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0011 case(1),  %%% sphere w/ ring
0012 figure
0013 resol  = 50;    % # pts for sphere & theta pts for ring
0014 resol2 = 25;    % radial pts for ring
0015 blur   = 13;    % feature blurring on sphere
0016 blur2  = 5;     % alpha blurring on ring
0017 
0018 set(gcf,'DoubleBuffer','on', 'Color',[0 0 0]);
0019 colormap(autumn(256));
0020 
0021 [X1,Y1,Z1] = sphere(resol-1);                   % make inner sphere
0022 C1 = conv2(Z1(reshape(randperm(resol.^2), resol, resol)), gausswin(blur) * gausswin(blur)', 'same');
0023 C1 = staggermatrix(C1);      % creates a 'swept' look by breaking latitudinal blurring only
0024 
0025 [TH, R] = meshgrid(linspace(0,2*pi,resol), linspace(1.5, 2.5, resol2));  % make ring
0026 [X2,Y2] = pol2cart(TH', R');
0027 Z2 = zeros(resol, resol2);
0028 A2 = conv2(rand(resol,resol2), gausswin(blur2) * gausswin(blur2)','same');  % random alpha map, blurred
0029 A2 = staggermatrix(A2')';    % good for rings too, since it breaks the radial blurring
0030 A2(1,:) = A2(end,:);         % prevents a seam by allowing interpolation from both sides
0031 
0032 h1 = surf(X1,Y1,Z1,C1);          % draw inner sphere
0033 set(h1, 'Ambient', 0.6);
0034 
0035 hold on                                         % draw ring
0036 h2 = surf(X2,Y2,Z2);
0037 set(h2, 'FaceAlpha','interp', 'AlphaData', A2);
0038 
0039 shading interp; lighting gouraud; material dull;
0040 axis equal; axis off;
0041 set(gca,'CameraViewAngleMode','manual', 'CameraViewAngle', 7);
0042 lightangle(90,40);
0043 
0044 set(h2, 'FaceColor', [0.7, 0.7, 0.7]);  % ring should be plain gray in color
0045 
0046 % Animate
0047 view([0,15]);
0048 for steps = 1:72, 
0049     camorbit(10,0); drawnow;
0050     pause(0.010); 
0051 end
0052 
0053 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0054 case(2),  %%% display globe on a sphere with transparent oceans
0055 figure;  load topo;
0056 topo = padmatrix(topo, [0 0 0 10], -3500);  % the topo map leaves off the top of the globe ...
0057 
0058 [X,Y,Z] = sphere(180);
0059 h1 = surf(X,Y,Z);
0060 
0061 set(h1, 'FaceColor', 'texture', 'EdgeColor', 'none', 'FaceAlpha', 'texture', 'AlphaDataMapping', 'none');
0062 set(h1, 'CData', topo, 'AlphaData', (double(topo > 0) .* 0.6) + 0.4);
0063 
0064 colormap(topomap1);
0065 axis equal;
0066 set(gca, 'CameraViewAngleMode', 'manual');
0067 axis off;
0068 
0069 lt1 = lightangle(0,0);  set(lt1, 'Color', [1, 1, 1]);
0070 
0071 % Animate
0072 view([0,5]);
0073 for step = 1:24, 
0074     camOrbit(15, 0); drawnow; 
0075 end
0076 
0077 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0078 case(3),  %%% create a penny surface model with lights, etc
0079 figure;  load penny;
0080 P = fliplr(P);
0081 coords = -63:64;  [X,Y] = meshgrid(coords);
0082 coppercolor = copper(2);  coppercolor = coppercolor(2,:);
0083 
0084 mask = double(sqrt((X-0).^2 + (Y-12).^2) < 80);
0085 mask(~mask) = NaN;
0086 surf(X,Y,mask.*P, 'FaceColor', coppercolor, 'EdgeColor', 'none');
0087 
0088 axis equal;  axis off;
0089 set(gca,'CameraViewAngleMode','manual', 'CameraViewAngle', 9, 'DataAspectRatio', [1 1 30]);
0090 
0091 material metal; lighting gouraud;
0092 lt1 = lightangle(90, 10);    set(lt1, 'Color', 'r');
0093 lt2 = lightangle(180, 30);   set(lt2, 'Color', 'g');
0094 lt3 = lightangle(270, 60);   set(lt3, 'Color', 'b');
0095 lt4 = lightangle(0, -90);    set(lt4, 'Color', 'w');
0096 
0097 % Animate
0098 view([160,50]);
0099 for step = 1:71
0100     camorbit(3, 20); drawnow;
0101 end
0102 
0103 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0104 otherwise,
0105     error('Unknown selection.');
0106 end
0107 
0108 %%%%%%%%%%%%%%%%%%%%%%%% HELPER FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%
0109 
0110 function A = staggermatrix(A)
0111 % STAGGERMATRIX  Randomly circularly shifts the rows of an input matrix.
0112 %    B = STAGGERMATRIX(A) circularly shifts each row of the matrix A by a
0113 %    random (integer) amount.
0114 
0115 [M, N] = size(A);
0116 for row = 1:M
0117     shifts = randperm(N);
0118     A(row, :) = circshift(A(row, :), [1, shifts(1)]);
0119 end

Generated on Mon 09-Oct-2006 00:54:52 by m2html © 2003