24小时热门版块排行榜    

查看: 664  |  回复: 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 的主题更新
普通表情 高级回复 (可上传附件)
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[基金申请] 咱们一起用铁证分析2026国家社科基金中标与否 +7 启萌科技 2026-08-12 27/1350 2026-08-18 21:44 by Noways
[教师之家] 为什么余额宝的年化利率越来越低?主要原因有哪些? +3 瞬息宇宙 2026-08-15 3/150 2026-08-18 21:40 by xiaohuixin
[基金申请] 2027广东省杰青 +3 奶牛小黑 2026-08-15 9/450 2026-08-18 20:09 by 奶牛小黑
[基金申请] 朋友圈看到的 +4 wangzilk 2026-08-18 5/250 2026-08-18 19:25 by wangzilk
[基金申请] 欢迎发来filecode的Mz6后的代码验证其规律 +51 医学老男孩 2026-08-13 110/5500 2026-08-18 19:07 by icerianxia
[基金申请] 明天放榜? +5 Shxjjxjkx 2026-08-18 5/250 2026-08-18 18:14 by -大大大大大-
[基金申请] 时间戳变了,能看出什么问题? +8 基诺咪客 2026-08-17 11/550 2026-08-18 17:13 by 悠然熊猫
[基金申请] 重要消息,中午系统在维护 +9 yuleib84 2026-08-18 10/500 2026-08-18 16:52 by archvillain
[论文投稿] 投稿咨询 +4 wwm09 2026-08-17 6/300 2026-08-18 15:36 by wwm09
[基金申请] 时间戳又变了8-15 +14 archvillain 2026-08-15 26/1300 2026-08-18 13:37 by phantomgost
[基金申请] 今天维护系统维护 祝所有人 高中 +8 gjjjzhong 2026-08-18 9/450 2026-08-18 13:01 by 家与远方
[基金申请] 哪位老哥知道今年的国自然具体哪一天放榜? +13 Ldrop2023 2026-08-13 16/800 2026-08-18 12:25 by 淀粉搬运工
[基金申请] 快农历七夕节了,轻松一下,男人悄悄话,女施主请不要进来。 +4 Tide man 2026-08-14 5/250 2026-08-18 11:35 by Tide man
[基金申请] 93BebMhtakh前后11位开头都是大写 +4 且听虎啸 2026-08-17 5/250 2026-08-18 00:49 by 蔡棒棒菂
[基金申请] 感觉是下周放榜了 +6 angus9576 2026-08-17 11/550 2026-08-17 23:57 by angus9576
[基金申请] filecode=后面第一个是大写字母 +8 wangze12014 2026-08-14 10/500 2026-08-17 17:05 by xter9665
[基金申请] 今天系统多次维护,明天很可能放榜! +8 zju2000 2026-08-16 9/450 2026-08-17 12:20 by lmz0216
[精细化工] 招聘 金属平磨液,抛光液研发工程师 +3 小天0311 2026-08-14 3/150 2026-08-16 07:31 by H9PLUS
[基金申请] 各位道友,我要去昆明玩几天,回来见。 +7 Tide man 2026-08-14 8/400 2026-08-15 01:11 by arzu_hma
[基金申请] 重要来源:本周末出结果 +10 瞬息宇宙 2026-08-12 10/500 2026-08-13 15:46 by likettle
信息提示
请填处理意见