%Conway's life with GUI clf clear all %============================================= %build the GUI %define the plot button plotbutton=uicontrol('style','pushbutton',... 'string','Run', ... 'fontsize',12, ... 'position',[100,400,50,20], ... 'callback', 'run=1;'); %define the stop button erasebutton=uicontrol('style','pushbutton',... 'string','Stop', ... 'fontsize',12, ... 'position',[200,400,50,20], ... 'callback','freeze=1;'); %define the Quit button quitbutton=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]); %============================================= %CA setup n=128; %initialize the arrays z = zeros(n,n); cells = z; sum = z; %set a few cells to one cells(n/2,.25*n:.75*n) = 1; cells(.25*n:.75*n,n/2) = 1; %cells(.5*n-1,.5*n-1)=1; %cells(.5*n-2,.5*n-2)=1; %cells(.5*n-3,.5*n-3)=1; cells = (rand(n,n))<.5 ; %how long for each case to stability or simple oscillators %build an image and display it imh = image(cat(3,cells,z,z)); set(imh, 'erasemode', 'none') axis equal axis tight %index definition for cell update x = 2:n-1; y = 2:n-1; %Main event loop stop= 0; %wait for a quit button push run = 0; %wait for a draw freeze = 0; %wait for a freeze while (stop==0) if (run==1) %nearest neighbor sum sum(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); % The CA rule cells = (sum==3) | (sum==2 & cells); %draw the new image set(imh, 'cdata', cat(3,cells,z,z) ) %update the step number diaplay stepnumber = 1 + str2num(get(number,'string')); set(number,'string',num2str(stepnumber)) end if (freeze==1) run = 0; freeze = 0; end drawnow %need this in the loop for controls to work end
相关推荐
the game of life,C++,亲测可以运行。Main.cpp #include "utility.h" #include "life.h" void main() // Program to play Conway's game of Life. /* Pre: The user supplies an initial configuration of living ...
模拟细胞的生命游戏,通过编写类来模拟细胞的整体,然后输出来描述细胞的存活状态,其中细胞更细换代满足一定的规则
一种在很多格子里不断进化的生命进化的小游戏。 它的规则是这样的: 对其中一个网格,如果它的邻居少于两个,则它会死于孤独;如果多于三个,它亦会因拥挤而死。只有当它的邻居数等于二或三时它才会生存到下一代;...
一个模拟生活的游戏源码
TheGameOfLife:未来的游戏
thegameoflife:埃尔·朱戈·德拉维达·德·琼·康威
Game-Of-LifeA simple simulator showing the game of life based on Conway's Game of Life. Run Game.py to start!Note: settings functions not enabled yet coming soon!Prerequisitespython pygame module ...
The Game of Life
生命游戏 源码 vc Game of life beautiful and interesting 敲空格开始游戏 knock at space bar to start the game
Conway——the game of life,特别发行的精装版,以此来纪念一年来学习编程的蛋疼时光!
game in assembler language, a turn-based quest with a choice of answers. One day from the life of a fisherman
matlab导入excel代码utl_fun_with_python_and_the_game_of_life_intro_to_animation 有趣的python和动画动画的生活游戏。 关键字:sas sql join合并大数据分析宏oracle teradata mysql sas社区stackoverflow ...
生活游戏用java编写的生命游戏。 接收一个文件,该文件的第一行说明了游戏网格将使用的行数和列数。 第一行还有游戏将持续的回合数,0 表示游戏永远不会结束。 下一行是网格的初始设置。
6.5.4. The Game of Life 6.5.5. A Simple Lisp Interpreter 6.6. Acknowledgments 6.7. References Index -------------------------------------------------------------------------------- Copyright ©...
The Internet of Things (IoT) has emerged as a massive technology, which discovers new elds that touch life especially in building protocols for smart cities and health care. It poses a new trend of ...
智能新时代 安全新起点 生活如「戏」 游戏?现实!
Enabling you to add life to your games, this book will focus on the Slick2D game library. Starting with the installation and configuration of a game library, you will then move onto understanding the ...
Martin Gardner的生命游戏论文,希望对你们有所帮助^_^