ZealOS/docs/Demo/Games/MassSpring.CC.html
TomAwezome dbf8647d59 Fixed non-writable drive throw on F5 and Ctrl-S.
Added top & right borders to RawDr.
Improved spacing in some debug and compiler reporting.
Fixed RawPutChar and EdLite tab width.
Fixed Ui missing '0x' prefix syntax highlighter bug.
Added 32BitPaint demo.
2021-07-14 18:38:02 -04:00

213 lines
17 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.08">
<style type="text/css">
body {background-color:#000000;}
.cF0{color:#ffffff;background-color:#000000;}
.cF1{color:#3465a4;background-color:#000000;}
.cF2{color:#4e9a06;background-color:#000000;}
.cF3{color:#06989a;background-color:#000000;}
.cF4{color:#a24444;background-color:#000000;}
.cF5{color:#75507b;background-color:#000000;}
.cF6{color:#ce982f;background-color:#000000;}
.cF7{color:#bcc0b9;background-color:#000000;}
.cF8{color:#555753;background-color:#000000;}
.cF9{color:#729fcf;background-color:#000000;}
.cFA{color:#82bc49;background-color:#000000;}
.cFB{color:#34e2e2;background-color:#000000;}
.cFC{color:#ac3535;background-color:#000000;}
.cFD{color:#ad7fa8;background-color:#000000;}
.cFE{color:#fce94f;background-color:#000000;}
.cFF{color:#000000;background-color:#000000;}
</style>
</head>
<body>
<pre style="font-family:monospace;font-size:12pt">
<a name="l1"></a><span class=cF1>class</span><span class=cF0> MyMass:</span><span class=cF9>CMass</span><span class=cF0>
<a name="l2"></a>{
<a name="l3"></a> </span><span class=cF1>F64</span><span class=cF0> radius;
<a name="l4"></a>};
<a name="l5"></a>
<a name="l6"></a></span><span class=cF1>class</span><span class=cF0> MySpring:</span><span class=cF9>CSpring</span><span class=cF0>
<a name="l7"></a>{
<a name="l8"></a>};
<a name="l9"></a>
<a name="l10"></a></span><span class=cF9>CMathODE</span><span class=cF0> *ode=</span><span class=cF3>NULL</span><span class=cF0>;
<a name="l11"></a>
<a name="l12"></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> *dc)
<a name="l13"></a>{
<a name="l14"></a> MyMass *tmpm;
<a name="l15"></a> MySpring *tmps;
<a name="l16"></a>
<a name="l17"></a> dc-&gt;color = </span><span class=cF3>RED</span><span class=cF0>;
<a name="l18"></a> tmps = ode-&gt;next_spring;
<a name="l19"></a> </span><span class=cF1>while</span><span class=cF0> (tmps != &amp;ode-&gt;next_spring)
<a name="l20"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l21"></a> </span><span class=cF5>GrLine</span><span class=cF0>(dc, tmps-&gt;end1-&gt;x, tmps-&gt;end1-&gt;y, tmps-&gt;end2-&gt;x, tmps-&gt;end2-&gt;y);
<a name="l22"></a> tmps = tmps-&gt;next;
<a name="l23"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l24"></a>
<a name="l25"></a> dc-&gt;color = </span><span class=cF3>BLACK</span><span class=cF0>;
<a name="l26"></a> tmpm = ode-&gt;next_mass;
<a name="l27"></a> </span><span class=cF1>while</span><span class=cF0> (tmpm != &amp;ode-&gt;next_mass)
<a name="l28"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l29"></a> </span><span class=cF5>GrCircle</span><span class=cF0>(dc, tmpm-&gt;x, tmpm-&gt;y, tmpm-&gt;radius);
<a name="l30"></a> tmpm = tmpm-&gt;next;
<a name="l31"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l32"></a>}
<a name="l33"></a>
<a name="l34"></a></span><span class=cF1>U0</span><span class=cF0> MyDerivative(</span><span class=cF9>CMathODE</span><span class=cF0> *ode, </span><span class=cF1>F64</span><span class=cF0>, </span><span class=cF9>COrder2D3</span><span class=cF0> *, </span><span class=cF9>COrder2D3</span><span class=cF0> *)
<a name="l35"></a>{</span><span class=cF2>//The forces due to springs and drag are</span><span class=cF0>
<a name="l36"></a></span><span class=cF2>//automatically handled by the ode code.</span><span class=cF0>
<a name="l37"></a> </span><span class=cF2>//We can add new forces here.</span><span class=cF0>
<a name="l38"></a> </span><span class=cF1>F64</span><span class=cF0> d, dd;
<a name="l39"></a> </span><span class=cF9>CD3</span><span class=cF0> p;
<a name="l40"></a> MyMass *tmpm1, *tmpm2;
<a name="l41"></a>
<a name="l42"></a> tmpm1 = ode-&gt;next_mass;
<a name="l43"></a> </span><span class=cF1>while</span><span class=cF0> (tmpm1 != &amp;ode-&gt;next_mass)
<a name="l44"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l45"></a> tmpm2 = tmpm1-&gt;next;
<a name="l46"></a> </span><span class=cF1>while</span><span class=cF0> (tmpm2 != &amp;ode-&gt;next_mass)
<a name="l47"></a> {
<a name="l48"></a> </span><span class=cF5>D3Sub</span><span class=cF0>(&amp;p, &amp;tmpm2-&gt;state-&gt;x, &amp;tmpm1-&gt;state-&gt;x);
<a name="l49"></a> dd = </span><span class=cF5>D3NormSqr</span><span class=cF0>(&amp;p);
<a name="l50"></a> </span><span class=cF1>if</span><span class=cF0> (dd &lt;= </span><span class=cF5>Sqr</span><span class=cF7>(</span><span class=cF0>tmpm1-&gt;radius + tmpm2-&gt;radius</span><span class=cF7>)</span><span class=cF0>)
<a name="l51"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l52"></a> d = </span><span class=cF5>Sqrt</span><span class=cF0>(dd) + </span><span class=cFE>0</span><span class=cF0>.</span><span class=cFE>0001</span><span class=cF0>;
<a name="l53"></a> dd = </span><span class=cFE>10</span><span class=cF0>.</span><span class=cFE>0</span><span class=cF0> * </span><span class=cF5>Sqr</span><span class=cF0>(</span><span class=cF5>Sqr</span><span class=cF7>(</span><span class=cF5>Sqr</span><span class=cF0>(tmpm1-&gt;radius + tmpm2-&gt;radius) - dd</span><span class=cF7>)</span><span class=cF0>);
<a name="l54"></a> </span><span class=cF5>D3MulEqu</span><span class=cF0>(&amp;p, dd / d);
<a name="l55"></a> </span><span class=cF5>D3AddEqu</span><span class=cF0>(&amp;tmpm2-&gt;DstateDt-&gt;DxDt, &amp;p);
<a name="l56"></a> </span><span class=cF5>D3SubEqu</span><span class=cF0>(&amp;tmpm1-&gt;DstateDt-&gt;DxDt, &amp;p);
<a name="l57"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l58"></a> tmpm2 = tmpm2-&gt;next;
<a name="l59"></a> }
<a name="l60"></a> tmpm1 = tmpm1-&gt;next;
<a name="l61"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l62"></a>}
<a name="l63"></a>
<a name="l64"></a></span><span class=cF1>U0</span><span class=cF0> PlaceMass(</span><span class=cF9>I64</span><span class=cF0> x, </span><span class=cF9>I64</span><span class=cF0> y)
<a name="l65"></a>{
<a name="l66"></a> MyMass *tmpm = </span><span class=cF5>CAlloc</span><span class=cF0>(</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF0>MyMass</span><span class=cF7>)</span><span class=cF0>);
<a name="l67"></a>
<a name="l68"></a> tmpm-&gt;mass = </span><span class=cFE>1</span><span class=cF0>.</span><span class=cFE>0</span><span class=cF0>;
<a name="l69"></a> tmpm-&gt;drag_profile_factor = </span><span class=cFE>100</span><span class=cF0>.</span><span class=cFE>0</span><span class=cF0>;
<a name="l70"></a> tmpm-&gt;x = x;
<a name="l71"></a> tmpm-&gt;y = y;
<a name="l72"></a> tmpm-&gt;radius = </span><span class=cFE>10</span><span class=cF0> * (</span><span class=cF5>Rand</span><span class=cF0> + </span><span class=cFE>0</span><span class=cF0>.</span><span class=cFE>25</span><span class=cF0>);
<a name="l73"></a> </span><span class=cF5>QueueInsert</span><span class=cF0>(tmpm, ode-&gt;last_mass);
<a name="l74"></a>}
<a name="l75"></a>
<a name="l76"></a></span><span class=cF1>U0</span><span class=cF0> PlaceSpring(MyMass *tmpm1, MyMass *tmpm2)
<a name="l77"></a>{
<a name="l78"></a> MySpring *tmps = </span><span class=cF5>CAlloc</span><span class=cF0>(</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF0>MySpring</span><span class=cF7>)</span><span class=cF0>);
<a name="l79"></a>
<a name="l80"></a> tmps-&gt;end1 = tmpm1;
<a name="l81"></a> tmps-&gt;end2 = tmpm2;
<a name="l82"></a> tmps-&gt;const = </span><span class=cFE>10000</span><span class=cF0>;
<a name="l83"></a> tmps-&gt;rest_len = </span><span class=cFE>100</span><span class=cF0>;
<a name="l84"></a> </span><span class=cF5>QueueInsert</span><span class=cF0>(tmps, ode-&gt;last_spring);
<a name="l85"></a>}
<a name="l86"></a>
<a name="l87"></a></span><span class=cF1>U0</span><span class=cF0> Init()
<a name="l88"></a>{
<a name="l89"></a> ode = </span><span class=cF5>ODENew</span><span class=cF0>(</span><span class=cFE>0</span><span class=cF0>, </span><span class=cFE>1</span><span class=cF0>e-</span><span class=cFE>4</span><span class=cF0>, </span><span class=cF3>ODEF_HAS_MASSES</span><span class=cF0>);
<a name="l90"></a> ode-&gt;derive = &amp;MyDerivative;
<a name="l91"></a> ode-&gt;drag_v2 = </span><span class=cFE>0</span><span class=cF0>.</span><span class=cFE>002</span><span class=cF0>;
<a name="l92"></a> ode-&gt;drag_v3 = </span><span class=cFE>0</span><span class=cF0>.</span><span class=cFE>00001</span><span class=cF0>;
<a name="l93"></a> ode-&gt;acceleration_limit = </span><span class=cFE>5</span><span class=cF0>e3;
<a name="l94"></a>
<a name="l95"></a> </span><span class=cF5>QueueInsert</span><span class=cF0>(ode, </span><span class=cF5>Fs</span><span class=cF0>-&gt;last_ode);
<a name="l96"></a>}
<a name="l97"></a>
<a name="l98"></a></span><span class=cF1>U0</span><span class=cF0> CleanUp()
<a name="l99"></a>{
<a name="l100"></a> </span><span class=cF5>QueueRemove</span><span class=cF0>(ode);
<a name="l101"></a> </span><span class=cF5>QueueDel</span><span class=cF0>(&amp;ode-&gt;next_mass, </span><span class=cF3>TRUE</span><span class=cF0>);
<a name="l102"></a> </span><span class=cF5>QueueDel</span><span class=cF0>(&amp;ode-&gt;next_spring, </span><span class=cF3>TRUE</span><span class=cF0>);
<a name="l103"></a> </span><span class=cF5>ODEDel</span><span class=cF0>(ode);
<a name="l104"></a>}
<a name="l105"></a>
<a name="l106"></a></span><span class=cF1>U0</span><span class=cF0> MassSpringDemo()
<a name="l107"></a>{
<a name="l108"></a> </span><span class=cF9>I64</span><span class=cF0> message_code, arg1, arg2;
<a name="l109"></a> MyMass *tmpm1 = </span><span class=cF3>NULL</span><span class=cF0>, *tmpm2 = </span><span class=cF3>NULL</span><span class=cF0>;
<a name="l110"></a>
<a name="l111"></a> </span><span class=cF5>PopUpOk</span><span class=cF0>(</span><span class=cF6>&quot;Left-Click to place mas\n&quot;</span><span class=cF0>
<a name="l112"></a> </span><span class=cF6>&quot;Right-Click and drag to\n&quot;</span><span class=cF0>
<a name="l113"></a> </span><span class=cF6>&quot;connect with spring.\n\n&quot;</span><span class=cF0>
<a name="l114"></a> </span><span class=cF6>&quot;Springs are 100 pixs long.\n&quot;</span><span class=cF0>);
<a name="l115"></a> </span><span class=cF5>SettingsPush</span><span class=cF0>; </span><span class=cF2>//See </span><a href="https://tomawezome.github.io/ZealOS/System/TaskSettings.CC.html#l3"><span class=cF4>SettingsPush</span></a><span class=cF0>
<a name="l116"></a> </span><span class=cF5>AutoComplete</span><span class=cF0>;
<a name="l117"></a> </span><span class=cF5>WinBorder</span><span class=cF0>;
<a name="l118"></a> </span><span class=cF5>WinMax</span><span class=cF0>;
<a name="l119"></a> </span><span class=cF5>DocCursor</span><span class=cF0>;
<a name="l120"></a> </span><span class=cF5>DocClear</span><span class=cF0>;
<a name="l121"></a>
<a name="l122"></a> </span><span class=cF5>Fs</span><span class=cF0>-&gt;win_inhibit |= </span><span class=cF3>WIG_DBL_CLICK</span><span class=cF0>;
<a name="l123"></a>
<a name="l124"></a> </span><span class=cF5>MenuPush</span><span class=cF0>( </span><span class=cF6>&quot;File {&quot;</span><span class=cF0>
<a name="l125"></a> </span><span class=cF6>&quot; Abort(,CH_SHIFT_ESC);&quot;</span><span class=cF0>
<a name="l126"></a> </span><span class=cF6>&quot; Exit(,CH_ESC);&quot;</span><span class=cF0>
<a name="l127"></a> </span><span class=cF6>&quot;}&quot;</span><span class=cF0>
<a name="l128"></a> </span><span class=cF6>&quot;Play {&quot;</span><span class=cF0>
<a name="l129"></a> </span><span class=cF6>&quot; Restart(,'\n');&quot;</span><span class=cF0>
<a name="l130"></a> </span><span class=cF6>&quot;}&quot;</span><span class=cF0>
<a name="l131"></a> );
<a name="l132"></a>
<a name="l133"></a> Init;
<a name="l134"></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="l135"></a>
<a name="l136"></a> </span><span class=cF1>try</span><span class=cF0>
<a name="l137"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l138"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF3>TRUE</span><span class=cF0>)
<a name="l139"></a> {
<a name="l140"></a> message_code = </span><span class=cF5>MessageGet</span><span class=cF0>(&amp;arg1, &amp;arg2,
<a name="l141"></a> </span><span class=cFE>1</span><span class=cF0> &lt;&lt; </span><span class=cF3>MESSAGE_MS_L_DOWN</span><span class=cF0> | </span><span class=cFE>1</span><span class=cF0> &lt;&lt; </span><span class=cF3>MESSAGE_MS_R_DOWN</span><span class=cF0> | </span><span class=cFE>1</span><span class=cF0> &lt;&lt; </span><span class=cF3>MESSAGE_MS_R_UP</span><span class=cF0> | </span><span class=cFE>1</span><span class=cF0> &lt;&lt; </span><span class=cF3>MESSAGE_KEY_DOWN</span><span class=cF0>);
<a name="l142"></a> </span><span class=cF1>switch</span><span class=cF0> (message_code)
<a name="l143"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l144"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>MESSAGE_MS_L_DOWN</span><span class=cF0>:
<a name="l145"></a> PlaceMass(arg1, arg2);
<a name="l146"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l147"></a>
<a name="l148"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>MESSAGE_MS_R_DOWN</span><span class=cF0>:
<a name="l149"></a> tmpm1 = </span><span class=cF5>MassFind</span><span class=cF0>(ode, arg1, arg2);
<a name="l150"></a> tmpm2 = </span><span class=cF3>NULL</span><span class=cF0>;
<a name="l151"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l152"></a>
<a name="l153"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>MESSAGE_MS_R_UP</span><span class=cF0>:
<a name="l154"></a> </span><span class=cF1>if</span><span class=cF0> (tmpm1 &amp;&amp; </span><span class=cF7>(</span><span class=cF0>tmpm2=</span><span class=cF5>MassFind</span><span class=cF0>(ode, arg1, arg2)</span><span class=cF7>)</span><span class=cF0> &amp;&amp; tmpm1 != tmpm2)
<a name="l155"></a> PlaceSpring(tmpm1, tmpm2);
<a name="l156"></a> tmpm1 = tmpm2 = </span><span class=cF3>NULL</span><span class=cF0>;
<a name="l157"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l158"></a>
<a name="l159"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>MESSAGE_KEY_DOWN</span><span class=cF0>:
<a name="l160"></a> </span><span class=cF1>switch</span><span class=cF0> (arg1)
<a name="l161"></a> {
<a name="l162"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF6>'\n'</span><span class=cF0>:
<a name="l163"></a> CleanUp;
<a name="l164"></a> Init;
<a name="l165"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l166"></a>
<a name="l167"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>CH_SHIFT_ESC</span><span class=cF0>:
<a name="l168"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>CH_ESC</span><span class=cF0>:
<a name="l169"></a> </span><span class=cF1>goto</span><span class=cF0> mouse_done;
<a name="l170"></a> }
<a name="l171"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l172"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l173"></a> }
<a name="l174"></a>mouse_done: </span><span class=cF2>//Don't goto out of try</span><span class=cF0>
<a name="l175"></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="l176"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l177"></a> </span><span class=cF1>catch</span><span class=cF0>
<a name="l178"></a> </span><span class=cF5>PutExcept</span><span class=cF0>;
<a name="l179"></a> </span><span class=cF5>SettingsPop</span><span class=cF0>;
<a name="l180"></a> CleanUp;
<a name="l181"></a> </span><span class=cF5>MenuPop</span><span class=cF0>;
<a name="l182"></a>}
<a name="l183"></a>
<a name="l184"></a>MassSpringDemo;
</span></pre></body>
</html>