function CatMouse;
% Author:Lindo Ouseph
% Research scholar, Dept. of Electronics, Cochin University of science and technology,India
% email:lindoao@gmail.com
clc;close all;clear all;temp=load('catmousedata.mat');
cat=temp.cat;mice=temp.mice;wav=temp.wav;fs=temp.fs;step=1;position=[];Increment=[1 0 0 0];space=0;w=100;pp=[];
s.h = figure('keypressfcn',@direction,'DockControls','off','MenuBar','none','NumberTitle','off','position',[500 400 1000 600]);
S.tmr = timer('Period',.001,'StartDelay',.001,'TasksToExecute',inf,'ExecutionMode','fixedrate','TimerFcn',@tmrfcn);
space = get(s.h,'position');x=round(rand(1)*(space(3)-w));y=round(rand(1)*(space(4)-w));
s.o = uicontrol('style','pushbutton','createFcn',@Initiate,'position',[0 0 w w],'backgroundcolor',[1 1 0],'string',[],'CData',cat);
s.t = uicontrol('style','pushbutton','position',[x y w w],'backgroundcolor',[0 1 0],'CData',mice);
function Initiate(varargin);start(S.tmr);end
function direction(varargin)
switch varargin{2}.Key
case 'rightarrow';Increment = [step 0 0 0];
case 'leftarrow';Increment = [-step 0 0 0];
case 'uparrow';Increment = [0 step 0 0];
case 'downarrow';Increment = [0 -step 0 0];
end
end
function tmrfcn(varargin)
position = get(s.o,'position');
if space(3)<= position(1);position(1) = 0;end
if space(4)<= position(2);position(2) = 0;end
if position(1)+position(3)<0;position(1) = space(3);end
if position(2)+position(4)<0;position(2) = space(4);end
temp=[position+Increment];
set(s.o,'position',temp);drawnow
[xxx yyy]=meshgrid(temp(1):temp(1)+w,temp(2):temp(2)+w);
bb(:,:,1)=xxx;bb(:,:,2)=yyy;[r,c] = size(xxx);u=[x x+w x+w x];v=[y y y+w y+w];
for i=1:4
aa=[];aa(1,1,1)=u(i);aa(1,1,2)=v(i);aa=repmat(aa,r,c)==bb;
if nnz(aa(:,:,1).*aa(:,:,2))
pp=audioplayer(wav,fs);play(pp)
x=round(rand(1)*(space(3)-w));y=round(rand(1)*(space(4)-w));
set(s.t,'position',[x y w w]);set(s.h,'color',[rand(1) rand(1) rand(1)]);drawnow
break
end
end
end
end