配色: 字号:
matlab编写的小游戏拼图
2012-09-20 | 阅:  转:  |  分享 
  
closeall;clc;clear;

ss=''cameraman'';

L=128;

%Author''semail:zjliu2001@163.com

figure(''Position'',[55198903349]);

aa=axes(''position'',[0.15,0.06,0.3,0.8]);

Im=imread([ss,''.tif'']);

N=256/L;p=1:L;

Imt=Im'';

hoi=imshow(Im,[]);

k=1;T=0;

backcall=[''ifT==0;'',...

''ka=get(gcbo,''''UserData'''');'',...

''Q=get(ph(ka(1)),''''cdata'''');'',...

''set(ph(ka(1)),''''cdata'''',[]);'',...

''set(hpu,''''cdata'''',Q);'',...

''else;'',...

''kb=get(gcbo,''''UserData'''');'',...

''QQ=get(ph(kb(1)),''''cdata'''');'',...

''set(ph(kb(1)),''''cdata'''',Q);'',....

''set(ph(ka(1)),''''cdata'''',QQ);'',...

''set(hpu,''''cdata'''',[]);'',...

''set(ph(kb(1)),''''UserData'''',[kb(1),ka(2)]);'',...

''set(ph(ka(1)),''''UserData'''',[ka(1),kb(2)]);'',...

''qa=find(ord==ka(2));qb=find(ord==kb(2));'',...

''ord(qa)=kb(2);ord(qb)=ka(2);end;'',...

''ifmin(diff(ord))==1;'',...

''msgbox(''''Congratulation!'''');'',...

''end;T=~T;''];

ord=randperm(NN);

ph=zeros(N);



fork=1:(NN);

[x,y]=ind2sub([N,N],k);

ph(x,y)=uicontrol(gcf,''style'',''pushbutton'',...

''unit'',''normalized'',''position'',[0.47+0.3/N(x-1),...

0.85-0.78/Ny,0.3/N,0.78/N],''UserData'',[k,ord(k)],...

''callback'',backcall);

[xg,yg]=ind2sub([N,N],ord(k));

sr=repmat(Imt((xg-1)L+p,(yg-1)L+p)'',[1,1,3]);

set(ph(k),''cdata'',sr);

end

hpu=uicontrol(gcf,''style'',''push'',...

''unit'',''normalized'',''position'',[0.82,0.5,0.3/N,0.78/N],...

''BackgroundColor'',[0.8,0.8,0.8],...

''ForegroundColor'',''b'',''fontsize'',12,...

''string'',''previewchart'');

ht1=uicontrol(gcf,''style'',''text'',...

''unit'',''normalized'',''position'',[0.02,0.7,0.1,0.1],...

''BackgroundColor'',[0.8,0.8,0.8],...

''ForegroundColor'',''b'',''fontsize'',12,...

''string'',''choseapic'');

Sc={''cameraman'',''rice'',''ic'',''testpat1''};

hp=uicontrol(gcf,''style'',''popupmenu'',...

''unit'',''normalized'',''position'',[0.02,0.6,0.1,0.1],...

''string'',''cameraman|rice|ic|testpat1|lena'',''callback'',...

[''ss=char(Sc(get(hp,''''value'''')));'',...

''Im=imread([ss,''''.tif'''']);Imt=Im'''';'',...

''set(hoi,''''cdata'''',Im);k=1;'',...

''ord=randperm(NN);[xx,yy]=ind2sub([N,N],ord);'',...

''fork=1:NN;'',...

''[x,y]=ind2sub([N,N],k);'',...

''[xg,yg]=ind2sub([N,N],ord(k));'',...

''sr=repmat(Imt((xg-1)L+p,(yg-1)L+p)'''',[1,1,3]);'',...

''set(ph(k),''''cdata'''',sr);end;'']);

ht2=uicontrol(gcf,''style'',''text'',...

''unit'',''normalized'',''position'',[0.01,0.5,0.12,0.1],...

''BackgroundColor'',[0.8,0.8,0.8],...

''ForegroundColor'',''b'',''fontsize'',12,...

''string'',''sizeofthepic'');

Si=[128,64,32,16];

aax=axes(''position'',[0.78,0.05,0.22,0.4]);

text(0.02,0.8,''\copyrightzjliu'',...

''fontsize'',14);axisoff;

text(0.02,0.6,''email:'',''fontsize'',14);

text(0.02,0.4,''zjliu@hit.edu.cn'',''fontsize'',14);

text(0.02,0.2,''zjliu2001@2001.com'',''fontsize'',14);

hs=uicontrol(gcf,''style'',''popupmenu'',...

''unit'',''normalized'',''position'',[0.02,0.4,0.1,0.1],...

''string'',''128x128|64x64|32x32|16x16'',''callback'',...

[''L=Si(get(hs,''''value''''));N=256/L;p=1:L;'',...

''ss=char(Sc(get(hp,''''value'''')));'',...

''Im=imread([ss,''''.tif'''']);Imt=Im'''';'',...

''set(hoi,''''cdata'''',Im);'',...

''clf([aa,hs,hp,ht1,ht2,aax]);'',...

''ord=randperm(NN);T=0;ph=zeros(N);'',...

''fork=1:(NN);'',...

''[x,y]=ind2sub([N,N],k);'',...

''ph(x,y)=uicontrol(gcf,''''style'''',''''pushbutton'''','',...

''''''unit'''',''''normalized'''',''''position'''',[0.47+0.3/N(x-1),'',...

''0.85-0.78/Ny,0.3/N,0.78/N],''''UserData'''',[k,ord(k)],'',...

''''''callback'''',backcall);'',...

''[xg,yg]=ind2sub([N,N],ord(k));'',...

''sr=repmat(Imt((xg-1)L+p,(yg-1)L+p)'''',[1,1,3]);'',...

''set(ph(k),''''cdata'''',sr);end;'',...

''hpu=uicontrol(gcf,''''style'''',''''push'''','',...

''''''unit'''',''''normalized'''',''''position'''',[0.82,0.5,0.3/N,0.78/N],'',...

''''''BackgroundColor'''',[0.8,0.8,0.8],'',...

''''''ForegroundColor'''',''''b'''',''''fontsize'''',12,'',...

''''''string'''',{''''preview'''';''''chart''''});'']);

献花(0)
+1
(本文系薇薇one图书...首藏)