| 查看: 637 | 回复: 1 | |||
| 当前主题已经存档。 | |||
ganchunlei至尊木虫 (著名写手)
|
[交流]
元胞自动机模拟
|
||
|
元胞自动机模拟 cellular automaton /*------------------------------------------------------------------------------* * File Name: Cellular Automator example for Origin C * *------------------------------------------------------------------------------*/ #include //********************************** // to implement a command // ca // for a simple celluar automator program // usage: // 1. compile this file // 2. close CodeBuilder for faster execution // 3. create a new matrix // 4. from script window, type ca and press enter //********************************** //////////////////////////////////////////////////////////////////////////////////// //static int temp[8] = {0,0,0,1,1,1,1,0}; // Rule 30 static int my_rules[8] = {0,0,0,1,1,0,1,0}; //////////////////////////////////////////////////////////////////////////////////// // our basic rule function // we take all the 8 possible permutations for the three cells above the // current cell and we need to determine live (1) or die (0) // and the determinations are stored in the my_rules array above // // use static function to avoid being visible from LabTalk static int rule(int left, int top, int right) { if(left && top && right) return my_rules[0]; if(left && top && !right) return my_rules[1]; if(left && !top && right) return my_rules[2]; if(left && !top && !right) return my_rules[3]; if(!left && top && right) return my_rules[4]; if(!left && top && !right) return my_rules[5]; if(!left && !top && right) return my_rules[6]; // for left=top=right=0 return my_rules[7]; } // this is our main function to be called from labtalk void ca() { MatrixLayer ml = Project.ActiveLayer(); if(ml==NULL) { out_str("Must have matrix as active window" ;return; } ml.SetInternalData(FSI_BYTE); ml.SetNumCols(1000); ml.SetNumRows(500); Matrix int nCols = mat.GetNumCols(); //--------- // init 1st row of matrix to be all zero except 1 in the middle for(int ii = 0; ii < nCols; ii++) { mat[0][ii] = 0; } mat[0][nCols/2] = 1; //--------- int left,top,right; // start from 2nd row progressBox show("calculating...." ;show.SetRange(1,mat.GetNumRows()); for(int nR = 1, nRLast=0; nR < mat.GetNumRows(); nR++,nRLast ++) { if(!show.Set(nR)) // user click cancel break; for(int nC = 0; nC < nCols; nC++) { left = nC > 0? mat[nRLast][nC-1] : 0; top = mat[nRLast][nC]; right = nC < nCols-1? mat[nRLast][nC+1] : 0; mat[nR][nC] = rule(left,top,right); } } ml.SetViewImage(TRUE); ml.LT_execute("Z1=0;Z2=1" ;// this is needed to set Z range to show bitmap as black and white} //----------------------------- EOF |
» 猜你喜欢
拟解决的关键科学问题还要不要写
已经有9人回复
最失望的一年
已经有17人回复
为什么nbs上溴 没有产物点出现呢
已经有6人回复
求推荐博导
已经有4人回复
存款400万可以在学校里躺平吗
已经有34人回复
求助一下有机合成大神
已经有4人回复
求推荐英文EI期刊
已经有5人回复
26申博
已经有3人回复
基金委咋了?2026年的指南还没有出来?
已经有10人回复
疑惑?
已经有5人回复

2楼2006-10-16 17:47:00













;
回复此楼