24小时热门版块排行榜    

Znn3bq.jpeg
汕头大学海洋科学接受调剂
查看: 648  |  回复: 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 的主题更新
普通表情 高级回复 (可上传附件)
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 调剂 +11 月@163.com 2026-04-11 11/550 2026-04-13 22:52 by pies112
[考研] 考研调剂 +11 长弓傲 2026-04-13 12/600 2026-04-13 22:48 by pies112
[考研] 300分求调剂 (085501机械专硕,本科扬大) +8 xu@841019 2026-04-11 9/450 2026-04-13 21:36 by xu@841019
[考研] 339求调剂 +4 hanwudada 2026-04-12 4/200 2026-04-13 12:03 by 蓝云思雨
[考研] 267求调剂 +8 再忙也要吃饭啊 2026-04-09 8/400 2026-04-11 21:42 by cfdbai
[考研] 0854调剂 +4 长弓傲 2026-04-09 4/200 2026-04-11 09:18 by 猪会飞
[考研] 346,工科0854求调剂,专硕 +7 moser233 2026-04-10 8/400 2026-04-11 08:52 by 猪会飞
[考研] 309求调剂 +14 wdhw 2026-04-10 15/750 2026-04-10 21:06 by zhouxiaoyu
[考研] 368求调剂 +3 17385968172 2026-04-10 3/150 2026-04-10 20:12 by 电子奥德彪
[考研] 一志愿矿大,材料工程专硕314分,0856可调都可以 +15 无懈可击的巨人 2026-04-09 15/750 2026-04-10 18:10 by hmn_wj
[考研] 298求调剂 +13 钉叮咚冬瓜 2026-04-09 13/650 2026-04-10 15:49 by jiajinhpu
[考研] 本科西工大 0856 324求调剂 +10 wysyjs25 2026-04-09 11/550 2026-04-10 08:37 by 5268321
[考研] 初试分332,一志愿报考西北工业大学, +11 故人?? 2026-04-09 11/550 2026-04-09 21:54 by JineShine
[考研] 材料专硕调剂 +16 哈哈哈吼吼吼哈 2026-04-07 17/850 2026-04-09 21:16 by wutongshun
[考研] 070300化学 求调剂 +13 73372112 2026-04-08 13/650 2026-04-09 20:22 by maddjdld
[考研] 材料化工总分334求调剂 +16 Riot2025 2026-04-08 17/850 2026-04-09 20:19 by maddjdld
[考研] 331求调剂 +5 luoxin0706. 2026-04-08 5/250 2026-04-08 22:15 by zhouyuwinner
[考研] 293分求调剂,外语为俄语 +7 加一一九 2026-04-07 10/500 2026-04-08 20:14 by yutian743
[考研] 259求调剂 +5 就爱吃土豆呀呀 2026-04-07 5/250 2026-04-07 22:40 by JourneyLucky
[考研] 307求调剂 +3 Youth@@ 2026-04-07 3/150 2026-04-07 09:25 by 小黑不怕难
信息提示
请填处理意见