No BSD License  

Highlights from
DISPLACE

image thumbnail
from DISPLACE by Vassili Pastushenko
drags nonmodified line/patch/text objects

displace
function displace
% DISPLACE LINE, PATCH or TEXT objects 
% Press mouse left or right button at line or patch, drag it
% and release button. Repeat the same with next or the same object.
% If you want to repeat draggging the same object, instead of new pressing
% mouse button, you can press/release space button, bring object to its position
% and do mouse click to finish object dragging.
% 
%Call:
%           displace
%Output:
%		changed object(s) position(s)
%       
%   Usage Example (any line/patch/text objects can be used)
%
%   c=bow;
%   c=c(4:4:60,:);
%   c=c(randperm(15),:);
%   hf=figure;
%   for i=1:9
%   t=sum(rand(3,4),1);
%   t(3:4)=t(3:4)/1.5;
%   if i<6
%   h=powel(t,'2');
%   set(h,'color',c(i,:));
%   else
%   xy=powel(t,{50});
%   h=patch(xy(:,1),xy(:,2),'k');
%   set(h,'facecolor',c(i,:),'facealpha',.6);
%   end
%   end;
%   text(1,.9,'Hollare!','fontsize',15,'color',c(1,:),'Edgecolor','r');
%   axis(2*(axis));
%   displace
%   close(hf)

%	Vassili Pastushenko	 Nov 2007
%==============================================
figh=gcf;
currax=gca;
titlestring=get(get(currax,'title'),'string');
titlecolor=get(get(currax,'title'),'color');
fixpointer=get(figh,'pointer');
posit=axis;
axis(posit);
xli=posit(1:2);
yli=posit(3:4);

%Preparations   
FS=get(currax,'Fontsize');
%Save Button 'Up' and 'Motion'  Fcn's, and titlestring
Button_move_old=get(figh,'WindowButtonMotionFcn');
Button_up_old=get(figh,'WindowButtonUpFcn');
set(currax,'fontsize',15)

title({'Press button at your object and drag it.';...
    'Click outside axis limits to finish'},'color','b')
numerr=0;

%Start cycling
while true

    waitforbuttonpress
set(figh,'pointer','fleur');
    start=get(currax,'Currentpoint');
start=start(2:3);
if prod(start(1)-xli)>0|prod(start(2)-yli)>0
    rectit
    flyback;
    return
end 
hlin=gco;
stru=get(hlin);
yeslin=isfield(stru,'XData');
yestxt=isfield(stru,'Interpreter');
yes=yeslin|yestxt;
if yes
    set(hlin,'Selected','on');
else
    numerr=numerr+1
    switch even(numerr)
        case true
         o_o;
        case false
         o_o(1);
    end
    continue
end

if yeslin
    xor=get(hlin,'xdata');xor=xor(:);
    yor=get(hlin,'ydata');yor=yor(:);
    funpont=@displac;
else
    pos=get(hlin,'Position');
    del=pos(1:2)-start;
    funpont=@dispos;
end 
    set(figh,'Windowbuttonmotionfcn',funpont,'Windowbuttonupfcn',@stopdis)
    uiwait
end


    function displac(obj,cas)
    pont=get(currax,'CurrentPoint');
    dis=pont(2:3)-start;
    set(hlin,'xdata',xor+dis(1),'ydata',yor+dis(2))
    drawnow
    end
function dispos(obj,cas)
    pont=get(currax,'CurrentPoint');
    pos(1:2)=pont(2:3)+del;
    set(hlin,'Position',pos)
    %drawnow
    end
function  stopdis(obj,cas)
 %recover WindowButtonFcn's Motion, Up and down
    set(figh,'WindowButtonMotionFcn',Button_move_old,'WindowButtonUpFcn',Button_up_old );
   set(hlin,'Selected','off')
    uiresume
end 

function flyback
         L=2500;
         xs=((L:-1:1)')/2;
        t=(1:5)*400+200;
        t=t+round(320*(rand(size(t))-.5));
        s=zeros(L,1);
        for i=1:length(t),s=s+600./(abs(xs-t(i))+350);end 
        sound(sin(.8*s.*xs)/3);
       
end

    function rectit
        %Recover title & FS
       set(currax,'Fontsize',FS)
       title(titlestring,'color',titlecolor)
       set(figh,'pointer',fixpointer);
    end


function  o_o(arg)
%	Vassili Pastushenko	 2005
%==============================
if nargin
         S=bip(1);
else
    S=bip;
end
         S=[S;zeros(1200,1);flipud(S)];
         sound(S);
         pause(.2);
end

function  S=bip(pib)
%Sound bit
%Vassili Pastushenko	Jul	2004
%==============================
t=(1:.1:100)';
ONETWO=linspace(1,3,length(t))';
S=cos(t.*ONETWO)./(2+ONETWO);
if nargin
    S=flipud(S);
end

if nargout<1
sound(S);
end
end

end

Contact us at files@mathworks.com