NCCOOS Trac Projects: Top | Web | Platforms | Processing | Viz | Sprints | Sandbox | (Wind)

root/gliderproc/trunk/MATLAB/plots/starsafe.m

Revision 495 (checked in by cbc, 12 years ago)

Initial import of Stark code.

Line 
1 function [x, y] = starsafe(x0, y0, theSize, theColor, varargin)
2
3 % starsafe -- Star symbols.
4 %  starsafe(x0, y0, theSize, theColor, ...) draws stars as patchs,
5 %   centered on (x0, y0), with theSize and theColor.  Additional
6 %   name/value pairs are passed directly to the "patch" routine.
7 %   The star sizes are given in the units of the y-axis.
8 %  [xx, yy] = starsafe(...) returns the (x, y) coordinates of
9 %   the stars, one per row, but does not plot them.
10 %  h = starsafe(...) draws the stars and returns their handles.
11 %
12 % Also see: arrowsafe.
13 %
14 % Note: this routine is a useful example for dealing with
15 %  symbol-like entities.
16 %
17 % Calls: none
18  
19 % Copyright (C) 2000 Dr. Charles R. Denham, ZYDECO.
20 %  All Rights Reserved.
21 %   Disclosure without explicit written consent from the
22 %    copyright owner does not constitute publication.
23  
24 % Version of 13-Jan-2000 16:21:37.
25 % Updated    13-Jan-2000 17:12:22.
26
27 if nargin < 2, y0 = 0; end
28 if nargin < 3, theSize = 1; end
29 if nargin < 4, theColor = [0 0 0]; end
30
31 % Update.
32
33 if nargin < 1
34         h = findobj(gcf, 'Type', 'patch', 'Tag', mfilename);
35         if any(h)
36                 for i = 1:length(h)
37                         u = get(h(i), 'UserData');
38                         [xx, yy] = feval(mfilename, u(1), u(2), u(3));
39                         set(h(i), 'XData', xx, 'YData', yy)
40                 end
41         end
42         return
43 end
44
45 % Demonstration.
46
47 if nargin == 1
48         if isequal(x0, 'demo'), x0 = 10; end
49         n = x0;
50         if ischar(n), n = eval(n); end
51         delete(findobj(gcf, 'Type', 'patch', 'Tag', mfilename))
52         axis auto
53         x0 = (rand(1, n) - 0.5) * n;
54         y0 = rand(1, n) - 0.5;
55         s = rand(1, n)/10;
56         cmap = colormap;
57         index = floor(rand(prod(size(x0)), 1) * size(cmap, 1)) + 1;
58         c = cmap(index, :);
59         feval(mfilename, x0, y0, s, c)
60         set(gca, 'XLim', [-n n], 'Ylim', [-1 1])
61         feval(mfilename)
62         return
63 end
64
65 if length(x0) == 1
66         x0 = x0 * ones(size(y0));
67 elseif length(y0) == 1
68         y0 = y0 * ones(size(x0));
69 end
70
71 if length(theSize) == 1
72         theSize = theSize * ones(size(x0));
73 end
74
75 if size(theColor, 1) == 1
76         theColor = ones(prod(size(x0)), 1) * theColor;
77 end
78
79 oldUnits = get(gca, 'Units');
80 set(gca, 'Units', 'pixels')
81 thePosition = get(gca, 'Position');
82 set(gca, 'Units', oldUnits)
83 theWidth = thePosition(3);
84 theHeight = thePosition(4);
85
86 axis('manual')
87 dx = diff(get(gca, 'XLim'));
88 dy = diff(get(gca, 'YLim'));
89 dydx = dy / dx;   % Not used.
90 dxdp = dx / theWidth;   % sci/pixel.
91 dydp = dy / theHeight;   % sci/pixel.
92
93 scale = dxdp / dydp;
94
95 f = zeros(1, 10);
96 f(2) = 1;
97 f = ifft(f)*length(f);
98 f(2:2:end) = f(2:2:end) * 0.38;
99 f(end+1) = f(1);
100 xs = -imag(f);
101 ys = real(f);
102
103 h = zeros(size(x0));
104
105 for i = 1:prod(size(x0))
106         xstar = xs * theSize(i) * scale + x0(i);
107         ystar = ys * theSize(i) + y0(i);
108         cstar = theColor(i, :);
109         ustar = [x0(i) y0(i) theSize(i)];
110         if nargout == 2
111                 x(i, 1:length(xstar)) = xstar;
112                 y(i, 1:length(ystar)) = ystar;
113         else
114                 if length(varargin) > 1
115                         h(i) = patch(xstar, ystar, cstar, ...
116                                 'Tag', mfilename, ...
117                                 'UserData', ustar);
118                 else
119                         h(i) = patch(xstar, ystar, cstar, ...
120                                 'Tag', mfilename, ...
121                                 'UserData', ustar);
122                 end
123         end
124 end
125
126 set(gcf, 'ResizeFcn', mfilename)
Note: See TracBrowser for help on using the browser.