ZealOS/docs/Demo/Graphics/Life.CC.html
TomAwezome 22e3d8f06e Clean up E1000 Driver.
Remove some palettes.
Add PaletteSetSlate.
Change all gr_palette_std to gr32_palette_std.
Change all CBGR48 to CBGR24.
2021-07-28 22:20:15 -04:00

147 lines
13 KiB
HTML
Executable file

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=US-ASCII">
<meta name="generator" content="ZealOS V0.11">
<style type="text/css">
body {background-color:#fef1f0;}
.cF0{color:#000000;background-color:#fef1f0;}
.cF1{color:#0148a4;background-color:#fef1f0;}
.cF2{color:#3b7901;background-color:#fef1f0;}
.cF3{color:#057c7e;background-color:#fef1f0;}
.cF4{color:#bb2020;background-color:#fef1f0;}
.cF5{color:#9e42ae;background-color:#fef1f0;}
.cF6{color:#b57901;background-color:#fef1f0;}
.cF7{color:#b2b6af;background-color:#fef1f0;}
.cF8{color:#555753;background-color:#fef1f0;}
.cF9{color:#678fbb;background-color:#fef1f0;}
.cFA{color:#82bc49;background-color:#fef1f0;}
.cFB{color:#0097a2;background-color:#fef1f0;}
.cFC{color:#e26a6a;background-color:#fef1f0;}
.cFD{color:#c671bc;background-color:#fef1f0;}
.cFE{color:#c7ab00;background-color:#fef1f0;}
.cFF{color:#fef1f0;background-color:#fef1f0;}
</style>
</head>
<body>
<pre style="font-family:monospace;font-size:12pt">
<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[</span><span class=cFE>2</span><span class=cF0>]; </span><span class=cF2>//double 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]-&gt;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, </span><span class=cFE>0</span><span class=cF0>, </span><span class=cFE>0</span><span class=cF0>, 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, count, next_dc;
<a name="l16"></a>
<a name="l17"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF3>TRUE</span><span class=cF0>)
<a name="l18"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l19"></a> next_dc = cur_dc ^ </span><span class=cFE>1</span><span class=cF0>;
<a name="l20"></a>start_over:
<a name="l21"></a> restart = </span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l22"></a> </span><span class=cF5>DCClear</span><span class=cF0>(dc[next_dc]);
<a name="l23"></a> </span><span class=cF1>for</span><span class=cF0> (y = </span><span class=cFE>1</span><span class=cF0>; y &lt; </span><span class=cF5>Fs</span><span class=cF0>-&gt;parent_task-&gt;pix_height - </span><span class=cFE>1</span><span class=cF0>; y++)
<a name="l24"></a> {
<a name="l25"></a> </span><span class=cF1>for</span><span class=cF0> (x = </span><span class=cFE>1</span><span class=cF0>; x &lt; </span><span class=cF5>Fs</span><span class=cF0>-&gt;parent_task-&gt;pix_width - </span><span class=cFE>1</span><span class=cF0>; x++)
<a name="l26"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l27"></a> count = </span><span class=cFE>0</span><span class=cF0>;
<a name="l28"></a> </span><span class=cF1>for</span><span class=cF0> (y1 = y - </span><span class=cFE>1</span><span class=cF0>; y1 &lt;= y + </span><span class=cFE>1</span><span class=cF0>; y1++)
<a name="l29"></a> </span><span class=cF1>for</span><span class=cF0> (x1 = x - </span><span class=cFE>1</span><span class=cF0>; x1 &lt;= x + </span><span class=cFE>1</span><span class=cF0>; x1++)
<a name="l30"></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="l31"></a> count++;
<a name="l32"></a> </span><span class=cF1>if</span><span class=cF0> (restart)
<a name="l33"></a> </span><span class=cF1>goto</span><span class=cF0> start_over;
<a name="l34"></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="l35"></a> {
<a name="l36"></a> </span><span class=cF1>if</span><span class=cF0> (count == </span><span class=cFE>3</span><span class=cF0>)
<a name="l37"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l38"></a> dc[next_dc]-&gt;color = </span><span class=cF3>GREEN</span><span class=cF0>;
<a name="l39"></a> </span><span class=cF5>GrPlot</span><span class=cF0>(dc[next_dc], x, y);
<a name="l40"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l41"></a> }
<a name="l42"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l43"></a> {
<a name="l44"></a></span><span class=cF2>//</span><span class=cF0> </span><span class=cF2>if (count == 3) //Use this for the classic rules</span><span class=cF0>
<a name="l45"></a> </span><span class=cF1>if</span><span class=cF0> (count == </span><span class=cFE>2</span><span class=cF0>)
<a name="l46"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l47"></a> dc[next_dc]-&gt;color = </span><span class=cF3>GREEN</span><span class=cF0>;
<a name="l48"></a> </span><span class=cF5>GrPlot</span><span class=cF0>(dc[next_dc], x, y);
<a name="l49"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l50"></a> }
<a name="l51"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l52"></a> </span><span class=cF5>Yield</span><span class=cF0>;
<a name="l53"></a> }
<a name="l54"></a> </span><span class=cF5>Sleep</span><span class=cF0>(</span><span class=cFE>50</span><span class=cF0>);
<a name="l55"></a> cur_dc = next_dc;
<a name="l56"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l57"></a>}
<a name="l58"></a>
<a name="l59"></a></span><span class=cF1>public</span><span class=cF0> </span><span class=cF1>U0</span><span class=cF0> Life()
<a name="l60"></a>{
<a name="l61"></a> </span><span class=cF9>I64</span><span class=cF0> message_code, count, x1, y1, x2, y2, arg1, arg2;
<a name="l62"></a>
<a name="l63"></a> dc[</span><span class=cFE>0</span><span class=cF0>] = </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="l64"></a> dc[</span><span class=cFE>1</span><span class=cF0>] = </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="l65"></a> cur_dc = </span><span class=cFE>0</span><span class=cF0>;
<a name="l66"></a> restart = </span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l67"></a>
<a name="l68"></a> </span><span class=cF5>SettingsPush</span><span class=cF0>; </span><span class=cF2>//See </span><a href="https://zeal-operating-system.github.io/ZealOS/System/TaskSettings.CC.html#l3"><span class=cF4>SettingsPush</span></a><span class=cF0>
<a name="l69"></a> </span><span class=cF5>AutoComplete</span><span class=cF0>;
<a name="l70"></a> </span><span class=cF5>WinBorder</span><span class=cF0>;
<a name="l71"></a> </span><span class=cF5>WinMax</span><span class=cF0>;
<a name="l72"></a> </span><span class=cF5>DocClear</span><span class=cF0>;
<a name="l73"></a> </span><span class=cF5>DCFill</span><span class=cF0>;
<a name="l74"></a>
<a name="l75"></a> </span><span class=cF5>Fs</span><span class=cF0>-&gt;animate_task = </span><span class=cF5>Spawn</span><span class=cF0>(&amp;AnimateTask, </span><span class=cF3>NULL</span><span class=cF0>, </span><span class=cF6>&quot;Animate&quot;</span><span class=cF0>,, </span><span class=cF5>Fs</span><span class=cF0>);
<a name="l76"></a> </span><span class=cF5>Fs</span><span class=cF0>-&gt;draw_it = &amp;</span><span class=cF5>DrawIt</span><span class=cF0>;
<a name="l77"></a> </span><span class=cF5>Fs</span><span class=cF0>-&gt;win_inhibit = </span><span class=cF3>WIG_TASK_DEFAULT</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="l78"></a> </span><span class=cF1>do</span><span class=cF0>
<a name="l79"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l80"></a> message_code = </span><span class=cF5>MessageGet</span><span class=cF0>(&amp;arg1, &amp;arg2, </span><span class=cFE>1</span><span class=cF0> &lt;&lt; </span><span class=cF3>MESSAGE_KEY_DOWN</span><span class=cF0> + </span><span class=cFE>1</span><span class=cF0> &lt;&lt; </span><span class=cF3>MESSAGE_MS_L_DOWN</span><span class=cF0>);
<a name="l81"></a> </span><span class=cF1>switch</span><span class=cF0> (message_code)
<a name="l82"></a> {
<a name="l83"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>MESSAGE_MS_L_DOWN</span><span class=cF0>:
<a name="l84"></a> x1 = arg1;
<a name="l85"></a> y1 = arg2;
<a name="l86"></a> x2 = arg1;
<a name="l87"></a> y2 = arg2;
<a name="l88"></a> count = </span><span class=cFE>0</span><span class=cF0>;
<a name="l89"></a> </span><span class=cF1>while</span><span class=cF0> (message_code != </span><span class=cF3>MESSAGE_MS_L_UP</span><span class=cF0>)
<a name="l90"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l91"></a> restart = </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l92"></a> dc[cur_dc]-&gt;color = </span><span class=cF3>GREEN</span><span class=cF0>;
<a name="l93"></a> dc[cur_dc]-&gt;thick = </span><span class=cFE>0</span><span class=cF0>.</span><span class=cFE>04</span><span class=cF0> * </span><span class=cFB>mouse</span><span class=cF0>.speed;
<a name="l94"></a> </span><span class=cF5>GrLine3</span><span class=cF0>(dc[cur_dc], x1, y1, </span><span class=cFE>0</span><span class=cF0>, x2, y2, </span><span class=cFE>0</span><span class=cF0>);
<a name="l95"></a> restart = </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l96"></a> message_code = </span><span class=cF5>MessageGet</span><span class=cF0>(&amp;arg1, &amp;arg2, </span><span class=cFE>1</span><span class=cF0> &lt;&lt; </span><span class=cF3>MESSAGE_MS_L_UP</span><span class=cF0> + </span><span class=cFE>1</span><span class=cF0> &lt;&lt; </span><span class=cF3>MESSAGE_MS_MOVE</span><span class=cF0>);
<a name="l97"></a> x1 = x2;
<a name="l98"></a> y1 = y2;
<a name="l99"></a> x2 = arg1;
<a name="l100"></a> y2 = arg2;
<a name="l101"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l102"></a> </span><span class=cF5>GrLine3</span><span class=cF0>(dc[cur_dc], x1, y1, </span><span class=cFE>0</span><span class=cF0>, x2, y2, </span><span class=cFE>0</span><span class=cF0>);
<a name="l103"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l104"></a>
<a name="l105"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>MESSAGE_KEY_DOWN</span><span class=cF0>:
<a name="l106"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l107"></a> }
<a name="l108"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l109"></a> </span><span class=cF1>while</span><span class=cF0> (message_code != </span><span class=cF3>MESSAGE_KEY_DOWN</span><span class=cF0> || !arg1);
<a name="l110"></a>
<a name="l111"></a> </span><span class=cF5>MessageGet</span><span class=cF0>(,, </span><span class=cFE>1</span><span class=cF0> &lt;&lt; </span><span class=cF3>MESSAGE_KEY_UP</span><span class=cF0>);
<a name="l112"></a> </span><span class=cF5>SettingsPop</span><span class=cF0>;
<a name="l113"></a> </span><span class=cF5>DCFill</span><span class=cF0>;
<a name="l114"></a> </span><span class=cF5>DCDel</span><span class=cF0>(dc[</span><span class=cFE>0</span><span class=cF0>]);
<a name="l115"></a> </span><span class=cF5>DCDel</span><span class=cF0>(dc[</span><span class=cFE>1</span><span class=cF0>]);
<a name="l116"></a>}
<a name="l117"></a>
<a name="l118"></a>Life;
</span></pre></body>
</html>