| 查看: 681 | 回复: 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 |
» 猜你喜欢
售SCI一区文章,我:8.O.55.1.O.54,科目齐全,可伽急
已经有3人回复
售SCI文章,我:8O5.5.1.O.54,科目齐全,可+急
已经有3人回复
售SCI一区文章,我:8.O.551.O.5.4,科目全,可伽急
已经有3人回复
售SCI文章,我:8O5.5.1.O.54,科目齐全,可+急
已经有3人回复
售SCI一区T0P文章,我:8O.55.1.O.5.4,科目齐全,可+急
已经有5人回复
售SCI-T0P文章,我:8O.5.5.1.O.54,科目齐全,可+急
已经有7人回复
上海工程技术大学 激光智能制造课题组 2027级博士研究生招生
已经有6人回复
课题组招2027级博士 上海工程技术大学 激光智能制造方向
已经有6人回复
现代”学阀”该如何界定
已经有14人回复
师弟论文见刊大半年才想起来申请专利,还能抢救一下吗?
已经有4人回复

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










;
回复此楼