home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l460 / 3.ddi / DEMOS.DI$ / SQDEMO.M < prev    next >
Encoding:
Text File  |  1993-03-07  |  4.0 KB  |  119 lines

  1. %SQDEMO    Demonstrate UIControls with Superquadrics.
  2. %
  3. %    Click "help" to see this preamble.
  4. %    Vary the superquadric shape parameters with the "roundness" sliders.
  5. %    Click "first" to select the current shape as the first one in a movie.
  6. %    Click "make" to select the current shape as the last one, and make a
  7. %       movie, interpolating between the shapes, and rotating 1/4 turn.
  8. %    Click "play" to play the movie.  If the first and last shapes are
  9. %       the same, play the movie forward to get a spinning effect.
  10. %       Otherwise, play the movie back and forth to get a pulsing effect.
  11. %    Click "done" to clear the window.
  12. %    The pulldown menu, colormaps, offers several color maps.
  13. %
  14. %    *  WARNING: When a button is green, work is in progress.  *
  15. %    *  Do not click another button.                           *
  16. %
  17. %    Other parameters can be altered by typing in the command window.
  18. %       nf = number of frames, initially 12.
  19. %       dt = rotation increment, initially pi/24, so 12 frames is 1/4 turn.
  20. %       np = number of plays, initially 10.
  21. %
  22. %    See also: SUPERQUAD.
  23.  
  24. %    Copyright (c) 1984-93 by The MathWorks, Inc.
  25.  
  26. echo off
  27. % Initialize
  28.  
  29. nf = 12;       % Number of frames
  30. dt = pi/2/nf;  % Rotation increment
  31. np = 10;       % Number of plays
  32.  
  33. clf
  34. darkgray = [1/3 1/3 1/3];
  35. set(gcf,'color',darkgray')
  36. gcfpos = zeros(1,4);
  37.  
  38. rand('seed',fix(100*sum(clock)))
  39. n = max(0,1+randn/2);
  40. e = max(0,1+randn/2);
  41. shape1 = [n e];
  42. superquad(n,e)
  43.  
  44. % Callback strings
  45.  
  46. helps = 'help sqdemo;';
  47.  
  48. firsts = 'shape1 = [n e];';
  49.  
  50. makes = [ ...
  51.   'set(makeh,''back'',''g''); ' ...
  52.   'if any(get(gcf,''pos'') ~= gcfpos), ' ...
  53.      'clear M; ' ...
  54.      'M = moviein(nf); ' ...
  55.      'moviebytes = 8*prod(size(M)), ' ...
  56.      'gcfpos = get(gcf,''pos''); ' ...
  57.   'end, ' ...
  58.   'shapef = [n e]; ' ...
  59.   't = 0; ' ...
  60.   'for j = 1:nf, ' ...
  61.      'shape = ((j-1)*shapef + (nf-j)*shape1)/(nf-1); ' ...
  62.      'set(nc,''value'',shape(1)); ' ...
  63.      'set(ec,''value'',shape(2)); ' ...
  64.      '[x,y,z] = superquad(shape(1),shape(2)); ' ...
  65.      'xy = [x(:) y(:)]*[cos(t) sin(t); -sin(t) cos(t)]; ' ...
  66.      'x(:) = xy(:,1); y(:) = xy(:,2); ' ...
  67.      'surf(x,y,z); ' ...
  68.      'axis([-1 1 -1 1 -1 1]); ' ...
  69.      't = t + dt; ' ...
  70.      'M(:,j) = getframe(gcf); ' ...
  71.   'end; '...
  72.   'np = (2*all(shapef==shape1)-1)*abs(np); ' ...
  73.   'set(makeh,''back'',''default''); '];
  74.  
  75. plays = [ ...
  76.   'if exist(''M'')~=1,disp([7,''You must make a movie first.'']), return, end,',...
  77.   'set(playh,''back'',''g'');'];
  78. com = computer;
  79. if ~(strcmp(com(1:2),'PC') | strcmp(com(1:2),'MA'))
  80.    plays = [plays ...
  81.      'disp(''Please wait while MATLAB sends data to the graphics server...'');'];
  82. end
  83. plays = [plays ...
  84.   'movie(M,np);' ...
  85.   'set(playh,''back'',''default'');'];
  86.  
  87. done = 'clf reset';
  88.  
  89.  
  90. % Sliders
  91.  
  92. nc = uicontrol('style','slider','units','normal','pos',[.05 .05 .25 .035], ...
  93.      'min',0,'max',6,'val',n, ...
  94.      'call','n = get(nc,''value''); superquad(n,e)');
  95. nct = uicontrol('style','text','units','normal','pos',[.05 .09 .25 .04], ...
  96.      'string','Vertical roundness','fore','white','back',darkgray);
  97. ec = uicontrol('style','slider','units','normal','pos',[.70 .05 .25 .035], ...
  98.      'min',0,'max',6,'val',e, ...
  99.      'call','e = get(ec,''value''); superquad(n,e)');
  100. ect = uicontrol('style','text','units','normal','pos',[.70 .09 .25 .04], ...
  101.      'string','Horizontal roundness','fore','white','back',darkgray);
  102.  
  103. % Push buttons
  104.  
  105. helph = uicontrol('style','push','units','normal','pos',[.9 .9 .08 .06], ...
  106.         'string','help','call',helps);
  107. firsth = uicontrol('style','push','units','normal','pos',[.9 .82 .08 .06], ...
  108.         'string','first','call',firsts);
  109. makeh = uicontrol('style','push','units','normal','pos',[.9 .74 .08 .06], ...
  110.         'string','make','call',makes);
  111. playh = uicontrol('style','push','units','normal','pos',[.9 .66 .08 .06], ...
  112.         'string','play','call',plays);
  113. endh = uicontrol('style','push','units','normal','pos',[.9 .58 .08 .06], ...
  114.         'string','done','call',done);
  115.  
  116. % Color map menu
  117.  
  118. colormenu
  119.