24СʱÈÈÃŰæ¿éÅÅÐаñ    

Znn3bq.jpeg
ÉÇÍ·´óѧº£Ñó¿ÆÑ§½ÓÊܵ÷¼Á
²é¿´: 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        mat(ml);
        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
»Ø¸´´ËÂ¥

» ²ÂÄãϲ»¶

ÈËÉúµÄ¾«²Ê²»ÊÇÄÃÒ»¸±ºÃÅÆ£¬¶øÊǰÑÒ»¸±ÀµÅÆ´ò³ÉºÃÅÆ£¡
ÒÑÔÄ   »Ø¸´´ËÂ¥   ¹Ø×¢TA ¸øTA·¢ÏûÏ¢ ËÍTAºì»¨ TAµÄ»ØÌû

huqifang

½ð³æ (ÕýʽдÊÖ)

ºÃÎÄÕ°¡£¬×öÄý¹ÌÄ£ÄâµÄ¶¥ÆðÀ´°¡£¡

ºÃÏñ×öÄý¹ÌÄ£ÄâµÄ²»¶à°¡£¬Á½¸öÌÖÂÛµÄÈ˶¼ÕÒ²»µ½°¡£¡¶àл§סµÄ·¨Ìû
2Â¥2006-10-16 17:47:00
ÒÑÔÄ   »Ø¸´´ËÂ¥   ¹Ø×¢TA ¸øTA·¢ÏûÏ¢ ËÍTAºì»¨ TAµÄ»ØÌû
Ïà¹Ø°æ¿éÌø×ª ÎÒÒª¶©ÔÄÂ¥Ö÷ ganchunlei µÄÖ÷Ìâ¸üÐÂ
×î¾ßÈËÆøÈÈÌûÍÆ¼ö [²é¿´È«²¿] ×÷Õß »Ø/¿´ ×îºó·¢±í
[¿¼ÑÐ] »¯Ñ§070300 Çóµ÷¼Á +21 ¹þ¹þ¹þ^_^ 2026-04-12 21/1050 2026-04-13 21:36 by nxybio2007
[»ù½ðÉêÇë] 2026 WRÇà°Î +3 liuchb715 2026-04-09 6/300 2026-04-13 18:40 by liuchb715
[¿¼ÑÐ] ÉúÎïѧµ÷¼Á +11 СȽҪŬÁ¦ 2026-04-10 13/650 2026-04-13 11:46 by µç»¯Ñ§¼°´ß»¯
[¿¼ÑÐ] 266µ÷¼Á +10 daya sun 2026-04-07 11/550 2026-04-13 10:12 by fenglj492
[¿¼ÑÐ] ÉúÎïѧµ÷¼Á£¬Ò»Ö¾Ô¸Î÷ÄÏ´óѧ348£¬TopÆÚ¿¯Ò»Çø¶þ×÷¡¢¶þÇøÈý×÷£¬ÈýµÈ½±Ñ§½ðÈý´Î +5 candyyyi 2026-04-09 5/250 2026-04-13 09:02 by ¿Éµ­²»¿ÉÍü
[¿¼ÑÐ] 322Çóµ÷¼Á£¬08¹¤¿Æ +4 ½ñÌìÊǸöСºÅ 2026-04-08 4/200 2026-04-13 00:20 by baobaoye
[¿¼ÑÐ] ÉúÎïѧ308Çóµ÷¼Á +5 ÏàÐűػá¹ââÍòÕ 2026-04-11 5/250 2026-04-12 18:14 by zhouxiaoyu
[¿¼ÑÐ] Çóµ÷¼Á£¬Ò»Ö¾Ô¸²ÄÁÏ¿ÆÑ§Ó빤³Ì985£¬365·Ö£¬ +8 ²Ä»¯Àî¿É 2026-04-11 10/500 2026-04-12 08:42 by 852137818
[¿¼ÑÐ] µ÷¼Á +6 ÇàµÆ²»¸º 2026-04-09 6/300 2026-04-11 20:35 by dongdian1
[¿¼ÑÐ] 085501»úеר˶ 302·Ö ²»ÌôרҵÇóµ÷¼Á +7 Íôij. 2026-04-09 7/350 2026-04-11 14:37 by luhong1990
[¿¼ÑÐ] 296Çóµ÷¼Á +6 Íô£¡£¿£¡ 2026-04-09 6/300 2026-04-11 11:25 by zhq0425
[¿¼ÑÐ] 298Çóµ÷¼Á +5 ²ÐºÉÐÂÁø 2026-04-07 5/250 2026-04-11 11:02 by ×ÏêØ×ÏÆå
[¿¼ÑÐ] ũѧ0904 312Çóµ÷¼Á +6 Say Never 2026-04-10 6/300 2026-04-11 10:33 by wwj2530616
[¿¼ÑÐ] Ò»Ö¾Ô¸985»úеѧ˶380Çóµ÷¼Á +5 ¹Ø¹ØöÂð¯10 2026-04-11 5/250 2026-04-11 10:10 by ÖªÄî¡£A
[¿¼ÑÐ] Ò»Ö¾Ô¸¾©Çø985£¬085401µç×ÓÐÅÏ¢£¬±¾¿Æµç×ÓÐÅÏ¢ +3 Ñô¹â¿ªÀʵÄÄк¢ 2026-04-10 3/150 2026-04-10 16:29 by sophia_93
[¿¼ÑÐ] 344Çóµ÷¼Á +7 ؼ·çѩҹ¹éÈËØ¼ 2026-04-09 7/350 2026-04-10 12:05 by pengliang8036
[¿¼ÑÐ] Ò»Ö¾Ô¸»ª¶«Ê¦·¶ÉúÎïѧ326·Ö£¬Çóµ÷¼Á +8 Áõīī 2026-04-09 8/400 2026-04-10 12:00 by pengliang8036
[¿¼ÑÐ] 278Çóµ÷¼Á +27 ·¶æÃÄÈ 2026-04-07 31/1550 2026-04-09 20:49 by zhouxiaoyu
[¿¼ÑÐ] »¯Ñ§¹¤³ÌÓë¼¼Êõרҵһ־Ը¹þ¹¤³Ì 291·ÖBÇø ¹ú¼Ò¼¶´ó´´¸ºÔðÈË ÓÐÒ»×÷ÂÛÎÄ +13 Emmy~ 2026-04-09 13/650 2026-04-09 14:47 by onlyÖÜ
[¿¼ÑÐ] 296Çóµ÷¼Á +3 Íô£¡£¿£¡ 2026-04-08 3/150 2026-04-08 22:00 by zhouyuwinner
ÐÅÏ¢Ìáʾ
ÇëÌî´¦ÀíÒâ¼û