| ²é¿´: 647 | »Ø¸´: 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 |
» ²ÂÄãϲ»¶
085600²ÄÁÏÓ뻯¹¤329·ÖÇóµ÷¼Á
ÒѾÓÐ20È˻ظ´
085600²ÄÁÏÓ뻯¹¤349·ÖÇóµ÷¼Á
ÒѾÓÐ15È˻ظ´
Çóµ÷¼Á
ÒѾÓÐ13È˻ظ´
Ò»Ö¾Ô¸»ªÄÏÀí¹¤´óѧ331·Ö²ÄÁÏÇóµ÷¼Á
ÒѾÓÐ11È˻ظ´
271Çóµ÷¼Á
ÒѾÓÐ40È˻ظ´
Çóµ÷¼ÁѧУ
ÒѾÓÐ3È˻ظ´
332Çóµ÷¼Á
ÒѾÓÐ15È˻ظ´
297Çóµ÷¼Á
ÒѾÓÐ25È˻ظ´
±¾¿ÆÎ÷¹¤´ó 324Çóµ÷¼Á
ÒѾÓÐ5È˻ظ´
297¹¤¿Æµ÷¼Á?
ÒѾÓÐ7È˻ظ´

huqifang
½ð³æ (ÕýʽдÊÖ)
- Ó¦Öú: 0 (Ó×¶ùÔ°)
- ½ð±Ò: 681.5
- Ìû×Ó: 311
- ÔÚÏß: 21·ÖÖÓ
- ³æºÅ: 250535
- ×¢²á: 2006-05-13
- ÐÔ±ð: GG
- רҵ: ½ðÊô½á¹¹²ÄÁÏ
ºÃÎÄÕ°¡£¬×öÄý¹ÌÄ£ÄâµÄ¶¥ÆðÀ´°¡£¡
| ºÃÏñ×öÄý¹ÌÄ£ÄâµÄ²»¶à°¡£¬Á½¸öÌÖÂÛµÄÈ˶¼ÕÒ²»µ½°¡£¡¶àл§סµÄ·¨Ìû |
2Â¥2006-10-16 17:47:00














;
»Ø¸´´ËÂ¥