130 lines
10 KiB
Plaintext
130 lines
10 KiB
Plaintext
|
<!DOCTYPE html>
|
||
|
<html lang="en">
|
||
|
<head>
|
||
|
<meta charset="UTF-8">
|
||
|
<meta name="generator" content="TempleOS V5.03">
|
||
|
<meta name="viewport" content="width=device-width">
|
||
|
<link rel="stylesheet" href="/style/templeos.css">
|
||
|
<script src="/script/templeos.js"></script>
|
||
|
<style type="text/css">
|
||
|
.cF0{color:#000000;background-color:#ffffff;}
|
||
|
.cF1{color:#0000aa;background-color:#ffffff;}
|
||
|
.cF2{color:#00aa00;background-color:#ffffff;}
|
||
|
.cF3{color:#00aaaa;background-color:#ffffff;}
|
||
|
.cF4{color:#aa0000;background-color:#ffffff;}
|
||
|
.cF5{color:#aa00aa;background-color:#ffffff;}
|
||
|
.cF6{color:#aa5500;background-color:#ffffff;}
|
||
|
.cF7{color:#aaaaaa;background-color:#ffffff;}
|
||
|
.cF8{color:#555555;background-color:#ffffff;}
|
||
|
.cF9{color:#5555ff;background-color:#ffffff;}
|
||
|
.cFA{color:#55ff55;background-color:#ffffff;}
|
||
|
.cFB{color:#55ffff;background-color:#ffffff;}
|
||
|
.cFC{color:#ff5555;background-color:#ffffff;}
|
||
|
.cFD{color:#ff55ff;background-color:#ffffff;}
|
||
|
.cFE{color:#ffff55;background-color:#ffffff;}
|
||
|
.cFF{color:#ffffff;background-color:#ffffff;}
|
||
|
</style>
|
||
|
</head>
|
||
|
<body>
|
||
|
<pre id="content">
|
||
|
<a name="l1"></a><span class=cF2>//Conway's Game of Life</span><span class=cF0>
|
||
|
<a name="l2"></a>
|
||
|
<a name="l3"></a></span><span class=cF9>CDC</span><span class=cF0> *dc[2]; </span><span class=cF2>//dbl buf</span><span class=cF0>
|
||
|
<a name="l4"></a></span><span class=cF9>I64</span><span class=cF0> cur_dc,;
|
||
|
<a name="l5"></a></span><span class=cF1>Bool</span><span class=cF0> restart;
|
||
|
<a name="l6"></a>
|
||
|
<a name="l7"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>DrawIt</span><span class=cF0>(</span><span class=cF9>CTask</span><span class=cF0> *,</span><span class=cF9>CDC</span><span class=cF0> *dc2)
|
||
|
<a name="l8"></a>{
|
||
|
<a name="l9"></a> dc[cur_dc]->flags|=</span><span class=cF3>DCF_NO_TRANSPARENTS</span><span class=cF0>;
|
||
|
<a name="l10"></a> </span><span class=cF5>GrBlot</span><span class=cF0>(dc2,0,0,dc[cur_dc]);
|
||
|
<a name="l11"></a>}
|
||
|
<a name="l12"></a>
|
||
|
<a name="l13"></a></span><span class=cF1>U0</span><span class=cF0> AnimateTask(</span><span class=cF9>I64</span><span class=cF0>)
|
||
|
<a name="l14"></a>{
|
||
|
<a name="l15"></a> </span><span class=cF9>I64</span><span class=cF0> x,y,x1,y1,cnt,next_dc;
|
||
|
<a name="l16"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF3>TRUE</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
|
||
|
<a name="l17"></a> next_dc=cur_dc^1;
|
||
|
<a name="l18"></a>start_over:
|
||
|
<a name="l19"></a> restart=</span><span class=cF3>FALSE</span><span class=cF0>;
|
||
|
<a name="l20"></a> </span><span class=cF5>DCClear</span><span class=cF0>(dc[next_dc]);
|
||
|
<a name="l21"></a> </span><span class=cF1>for</span><span class=cF0> (y=1;y<</span><span class=cF5>Fs</span><span class=cF0>->parent_task->pix_height-1;y++) {
|
||
|
<a name="l22"></a> </span><span class=cF1>for</span><span class=cF0> (x=1;x<</span><span class=cF5>Fs</span><span class=cF0>->parent_task->pix_width-1;x++) </span><span class=cF7>{</span><span class=cF0>
|
||
|
<a name="l23"></a> cnt=0;
|
||
|
<a name="l24"></a> </span><span class=cF1>for</span><span class=cF0> (y1=y-1;y1<=y+1;y1++)
|
||
|
<a name="l25"></a> </span><span class=cF1>for</span><span class=cF0> (x1=x-1;x1<=x+1;x1++)
|
||
|
<a name="l26"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>GrPeek</span><span class=cF7>(</span><span class=cF0>dc[cur_dc],x1,y1</span><span class=cF7>)</span><span class=cF0>==</span><span class=cF3>GREEN</span><span class=cF0>)
|
||
|
<a name="l27"></a> cnt++;
|
||
|
<a name="l28"></a> </span><span class=cF1>if</span><span class=cF0> (restart) </span><span class=cF1>goto</span><span class=cF0> start_over;
|
||
|
<a name="l29"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>GrPeek</span><span class=cF7>(</span><span class=cF0>dc[cur_dc],x,y</span><span class=cF7>)</span><span class=cF0>==</span><span class=cF3>GREEN</span><span class=cF0>) {
|
||
|
<a name="l30"></a> </span><span class=cF1>if</span><span class=cF0> (cnt==3) </span><span class=cF7>{</span><span class=cF0>
|
||
|
<a name="l31"></a> dc[next_dc]->color=</span><span class=cF3>GREEN</span><span class=cF0>;
|
||
|
<a name="l32"></a> </span><span class=cF5>GrPlot</span><span class=cF0>(dc[next_dc],x,y);
|
||
|
<a name="l33"></a> </span><span class=cF7>}</span><span class=cF0>
|
||
|
<a name="l34"></a> } </span><span class=cF1>else</span><span class=cF0> {
|
||
|
<a name="l35"></a></span><span class=cF2>//</span><span class=cF0> </span><span class=cF2> if (cnt==3) {//Use this for the classic rules</span><span class=cF0>
|
||
|
<a name="l36"></a> </span><span class=cF1>if</span><span class=cF0> (cnt==2) </span><span class=cF7>{</span><span class=cF0>
|
||
|
<a name="l37"></a> dc[next_dc]->color=</span><span class=cF3>GREEN</span><span class=cF0>;
|
||
|
<a name="l38"></a> </span><span class=cF5>GrPlot</span><span class=cF0>(dc[next_dc],x,y);
|
||
|
<a name="l39"></a> </span><span class=cF7>}</span><span class=cF0>
|
||
|
<a name="l40"></a> }
|
||
|
<a name="l41"></a> </span><span class=cF7>}</span><span class=cF0>
|
||
|
<a name="l42"></a> </span><span class=cF5>Yield</span><span class=cF0>;
|
||
|
<a name="l43"></a> }
|
||
|
<a name="l44"></a> </span><span class=cF5>Sleep</span><span class=cF0>(50);
|
||
|
<a name="l45"></a> cur_dc=next_dc;
|
||
|
<a name="l46"></a> </span><span class=cF7>}</span><span class=cF0>
|
||
|
<a name="l47"></a>}
|
||
|
<a name="l48"></a>
|
||
|
<a name="l49"></a></span><span class=cF1>public</span><span class=cF0> </span><span class=cF1>U0</span><span class=cF0> Life()
|
||
|
<a name="l50"></a>{
|
||
|
<a name="l51"></a> </span><span class=cF9>I64</span><span class=cF0> msg_code,cnt,x1,y1,x2,y2,arg1,arg2;
|
||
|
<a name="l52"></a>
|
||
|
<a name="l53"></a> dc[0]=</span><span class=cF5>DCNew</span><span class=cF0>(</span><span class=cF3>GR_WIDTH</span><span class=cF0>,</span><span class=cF3>GR_HEIGHT</span><span class=cF0>);
|
||
|
<a name="l54"></a> dc[1]=</span><span class=cF5>DCNew</span><span class=cF0>(</span><span class=cF3>GR_WIDTH</span><span class=cF0>,</span><span class=cF3>GR_HEIGHT</span><span class=cF0>);
|
||
|
<a name="l55"></a> cur_dc=0;
|
||
|
<a name="l56"></a> restart=</span><span class=cF3>FALSE</span><span class=cF0>;
|
||
|
<a name="l57"></a>
|
||
|
<a name="l58"></a> </span><span class=cF5>SettingsPush</span><span class=cF0>; </span><span class=cF2>//See </span><a href="/Wb/Adam/TaskSettings.HC.HTML#l3"><span class=cF4>SettingsPush</span></a><span class=cF0>
|
||
|
<a name="l59"></a> </span><span class=cF5>AutoComplete</span><span class=cF0>;
|
||
|
<a name="l60"></a> </span><span class=cF5>WinBorder</span><span class=cF0>;
|
||
|
<a name="l61"></a> </span><span class=cF5>WinMax</span><span class=cF0>;
|
||
|
<a name="l62"></a> </span><span class=cF5>DocClear</span><span class=cF0>;
|
||
|
<a name="l63"></a> </span><span class=cF5>DCFill</span><span class=cF0>;
|
||
|
<a name="l64"></a>
|
||
|
<a name="l65"></a> </span><span class=cF5>Fs</span><span class=cF0>->animate_task=</span><span class=cF5>Spawn</span><span class=cF0>(&AnimateTask,</span><span class=cF3>NULL</span><span class=cF0>,</span><span class=cF6>"Animate"</span><span class=cF0>,,</span><span class=cF5>Fs</span><span class=cF0>);
|
||
|
<a name="l66"></a> </span><span class=cF5>Fs</span><span class=cF0>->draw_it=&</span><span class=cF5>DrawIt</span><span class=cF0>;
|
||
|
<a name="l67"></a> </span><span class=cF5>Fs</span><span class=cF0>->win_inhibit=</span><span class=cF3>WIG_TASK_DFT</span><span class=cF0>-</span><span class=cF3>WIF_SELF_FOCUS</span><span class=cF0>-</span><span class=cF3>WIF_SELF_BORDER</span><span class=cF0>;
|
||
|
<a name="l68"></a> </span><span class=cF1>do</span><span class=cF0> </span><span class=cF7>{</span><span class=cF0>
|
||
|
<a name="l69"></a> msg_code=</span><span class=cF5>GetMsg</span><span class=cF0>(&arg1,&arg2,1<<</span><span class=cF3>MSG_KEY_DOWN</span><span class=cF0>+1<<</span><span class=cF3>MSG_MS_L_DOWN</span><span class=cF0>);
|
||
|
<a name="l70"></a> </span><span class=cF1>switch</span><span class=cF0> (msg_code) {
|
||
|
<a name="l71"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>MSG_MS_L_DOWN</span><span class=cF0>:
|
||
|
<a name="l72"></a> x1=arg1; y1=arg2;
|
||
|
<a name="l73"></a> x2=arg1; y2=arg2;
|
||
|
<a name="l74"></a> cnt=0;
|
||
|
<a name="l75"></a> </span><span class=cF1>while</span><span class=cF0> (msg_code!=</span><span class=cF3>MSG_MS_L_UP</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
|
||
|
<a name="l76"></a> restart=</span><span class=cF3>TRUE</span><span class=cF0>;
|
||
|
<a name="l77"></a> dc[cur_dc]->color=</span><span class=cF3>GREEN</span><span class=cF0>;
|
||
|
<a name="l78"></a> dc[cur_dc]->thick=0.04*</span><span class=cFB>ms</span><span class=cF0>.speed;
|
||
|
<a name="l79"></a> </span><span class=cF5>GrLine3</span><span class=cF0>(dc[cur_dc],x1,y1,0,x2,y2,0);
|
||
|
<a name="l80"></a> restart=</span><span class=cF3>TRUE</span><span class=cF0>;
|
||
|
<a name="l81"></a> msg_code=</span><span class=cF5>GetMsg</span><span class=cF0>(&arg1,&arg2,1<<</span><span class=cF3>MSG_MS_L_UP</span><span class=cF0>+1<<</span><span class=cF3>MSG_MS_MOVE</span><span class=cF0>);
|
||
|
<a name="l82"></a> x1=x2; y1=y2;
|
||
|
<a name="l83"></a> x2=arg1; y2=arg2;
|
||
|
<a name="l84"></a> </span><span class=cF7>}</span><span class=cF0>
|
||
|
<a name="l85"></a> </span><span class=cF5>GrLine3</span><span class=cF0>(dc[cur_dc],x1,y1,0,x2,y2,0);
|
||
|
<a name="l86"></a> </span><span class=cF1>break</span><span class=cF0>;
|
||
|
<a name="l87"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>MSG_KEY_DOWN</span><span class=cF0>:
|
||
|
<a name="l88"></a> </span><span class=cF1>break</span><span class=cF0>;
|
||
|
<a name="l89"></a> }
|
||
|
<a name="l90"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>while</span><span class=cF0> (msg_code!=</span><span class=cF3>MSG_KEY_DOWN</span><span class=cF0> || !arg1);
|
||
|
<a name="l91"></a> </span><span class=cF5>GetMsg</span><span class=cF0>(,,1<<</span><span class=cF3>MSG_KEY_UP</span><span class=cF0>);
|
||
|
<a name="l92"></a> </span><span class=cF5>SettingsPop</span><span class=cF0>;
|
||
|
<a name="l93"></a> </span><span class=cF5>DCFill</span><span class=cF0>;
|
||
|
<a name="l94"></a> </span><span class=cF5>DCDel</span><span class=cF0>(dc[0]);
|
||
|
<a name="l95"></a> </span><span class=cF5>DCDel</span><span class=cF0>(dc[1]);
|
||
|
<a name="l96"></a>}
|
||
|
<a name="l97"></a>
|
||
|
<a name="l98"></a>Life;
|
||
|
</span></pre></body>
|
||
|
</html>
|