CA 生命游戏机.doc
上传人:qw****27 上传时间:2024-09-11 格式:DOC 页数:2 大小:25KB 金币:15 举报 版权申诉
预览加载中,请您耐心等待几秒...

CA 生命游戏机.doc

CA生命游戏机.doc

预览

在线预览结束,喜欢就下载吧,查找使用更方便

15 金币

下载此文档

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

%buildtheGUI%definetheplotbutton%‘Style'(类型)—‘pushbutton'(按钮键)|'togglebutton'%(触发器)|'radiobutton'(无线按钮)|'chechbox'%(检查框)|'edit'(编辑)|'text'(文本)|'slider'%(滑标)|'frame'(框)|'listbox'(列表)|%'popupmenu'(跃上型)%这个属性声明了要生成的uicontrol对象类型。freeze冻结颜色plotbutton=uicontrol('style','pushbutton',...'string','run',...'fontsize',12,...'position',[100,400,50,20],...'callback','run=1;');%definethestopbuttonerasebutton=uicontrol('style','pushbutton',...'string','Stop',...'fontsize',12,...'position',[200,400,50,20],...'callback','freeze=1;');%definetheQuitbuttonquitbutton=uicontrol('style','pushbutton',...'string','Quit',...'fontsize',12,...'position',[300,400,50,20],...'callback','stop=1;close;');number=uicontrol('style','text',...'string','1',...'fontsize',12,...'position',[20,400,50,20]);n=128;z=zeros(n,n);cells=z;sum=z;cells(n/2,.25*n:.75*n)=1;cells(.25*n:.75*n,n/2)=1;cells=(rand(n,n))<.5;imh=image(cat(3,cells,z,z));set(imh,'erasemode','none');axisequal;axistight;x=2:n-1;y=2:n-1;stop=0;%waitforaquitbuttonpushrun=0;%waitforadrawfreeze=0;%waitforafreezewhile(stop==0)if(run==1)%nearestneighborsumsum(x,y)=cells(x,y-1)+cells(x,y+1)+...cells(x-1,y)+cells(x+1,y)+...cells(x-1,y-1)+cells(x-1,y+1)+...cells(3:n,y-1)+cells(x+1,y+1);%TheCArulecells=(sum==3)|(sum==2&cells);%drawthenewimageset(imh,'cdata',cat(3,cells,z,z))%updatethestepnumberdiaplaystepnumber=1+str2num(get(number,'string'));set(number,'string',num2str(stepnumber))endif(freeze==1)run=0;freeze=0;enddrawnow%needthisintheloopforcontrolstoworkend