mirror of
https://github.com/Zeal-Operating-System/ZealOS.git
synced 2024-12-28 16:26:35 +00:00
213 lines
17 KiB
HTML
Executable file
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 V1.06">
|
|
<style type="text/css">
|
|
body {background-color:#1f1f1f;}
|
|
.cF0{color:#e3e3e3;background-color:#1f1f1f;}
|
|
.cF1{color:#4f84a6;background-color:#1f1f1f;}
|
|
.cF2{color:#73a255;background-color:#1f1f1f;}
|
|
.cF3{color:#297582;background-color:#1f1f1f;}
|
|
.cF4{color:#b34f4b;background-color:#1f1f1f;}
|
|
.cF5{color:#8a52c3;background-color:#1f1f1f;}
|
|
.cF6{color:#b7822f;background-color:#1f1f1f;}
|
|
.cF7{color:#444444;background-color:#1f1f1f;}
|
|
.cF8{color:#6d6d6d;background-color:#1f1f1f;}
|
|
.cF9{color:#94bfde;background-color:#1f1f1f;}
|
|
.cFA{color:#a1ce97;background-color:#1f1f1f;}
|
|
.cFB{color:#6db4be;background-color:#1f1f1f;}
|
|
.cFC{color:#e88e88;background-color:#1f1f1f;}
|
|
.cFD{color:#ca94e8;background-color:#1f1f1f;}
|
|
.cFE{color:#d4b475;background-color:#1f1f1f;}
|
|
.cFF{color:#1f1f1f;background-color:#1f1f1f;}
|
|
</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->color = </span><span class=cF3>RED</span><span class=cF0>;
|
|
<a name="l18"></a> tmps = ode->next_spring;
|
|
<a name="l19"></a> </span><span class=cF1>while</span><span class=cF0> (tmps != &ode->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->end1->x, tmps->end1->y, tmps->end2->x, tmps->end2->y);
|
|
<a name="l22"></a> tmps = tmps->next;
|
|
<a name="l23"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l24"></a>
|
|
<a name="l25"></a> dc->color = </span><span class=cF3>BLACK</span><span class=cF0>;
|
|
<a name="l26"></a> tmpm = ode->next_mass;
|
|
<a name="l27"></a> </span><span class=cF1>while</span><span class=cF0> (tmpm != &ode->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->x, tmpm->y, tmpm->radius);
|
|
<a name="l30"></a> tmpm = tmpm->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->next_mass;
|
|
<a name="l43"></a> </span><span class=cF1>while</span><span class=cF0> (tmpm1 != &ode->next_mass)
|
|
<a name="l44"></a> </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l45"></a> tmpm2 = tmpm1->next;
|
|
<a name="l46"></a> </span><span class=cF1>while</span><span class=cF0> (tmpm2 != &ode->next_mass)
|
|
<a name="l47"></a> {
|
|
<a name="l48"></a> </span><span class=cF5>D3Sub</span><span class=cF0>(&p, &tmpm2->state->x, &tmpm1->state->x);
|
|
<a name="l49"></a> dd = </span><span class=cF5>D3NormSqr</span><span class=cF0>(&p);
|
|
<a name="l50"></a> </span><span class=cF1>if</span><span class=cF0> (dd <= </span><span class=cF5>Sqr</span><span class=cF7>(</span><span class=cF0>tmpm1->radius + tmpm2->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->radius + tmpm2->radius) - dd</span><span class=cF7>)</span><span class=cF0>);
|
|
<a name="l54"></a> </span><span class=cF5>D3MulEqu</span><span class=cF0>(&p, dd / d);
|
|
<a name="l55"></a> </span><span class=cF5>D3AddEqu</span><span class=cF0>(&tmpm2->DstateDt->DxDt, &p);
|
|
<a name="l56"></a> </span><span class=cF5>D3SubEqu</span><span class=cF0>(&tmpm1->DstateDt->DxDt, &p);
|
|
<a name="l57"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l58"></a> tmpm2 = tmpm2->next;
|
|
<a name="l59"></a> }
|
|
<a name="l60"></a> tmpm1 = tmpm1->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->mass = </span><span class=cFE>1</span><span class=cF0>.</span><span class=cFE>0</span><span class=cF0>;
|
|
<a name="l69"></a> tmpm->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->x = x;
|
|
<a name="l71"></a> tmpm->y = y;
|
|
<a name="l72"></a> tmpm->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->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->end1 = tmpm1;
|
|
<a name="l81"></a> tmps->end2 = tmpm2;
|
|
<a name="l82"></a> tmps->const = </span><span class=cFE>10000</span><span class=cF0>;
|
|
<a name="l83"></a> tmps->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->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->derive = &MyDerivative;
|
|
<a name="l91"></a> ode->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->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->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>->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>(&ode->next_mass, </span><span class=cF3>TRUE</span><span class=cF0>);
|
|
<a name="l102"></a> </span><span class=cF5>QueueDel</span><span class=cF0>(&ode->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>"Left-Click to place mas\n"</span><span class=cF0>
|
|
<a name="l112"></a> </span><span class=cF6>"Right-Click and drag to\n"</span><span class=cF0>
|
|
<a name="l113"></a> </span><span class=cF6>"connect with spring.\n\n"</span><span class=cF0>
|
|
<a name="l114"></a> </span><span class=cF6>"Springs are 100 pixs long.\n"</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://zeal-operating-system.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>->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>"File {"</span><span class=cF0>
|
|
<a name="l125"></a> </span><span class=cF6>" Abort(,CH_SHIFT_ESC);"</span><span class=cF0>
|
|
<a name="l126"></a> </span><span class=cF6>" Exit(,CH_ESC);"</span><span class=cF0>
|
|
<a name="l127"></a> </span><span class=cF6>"}"</span><span class=cF0>
|
|
<a name="l128"></a> </span><span class=cF6>"Play {"</span><span class=cF0>
|
|
<a name="l129"></a> </span><span class=cF6>" Restart(,'\n');"</span><span class=cF0>
|
|
<a name="l130"></a> </span><span class=cF6>"}"</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>->draw_it = &</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>(&arg1, &arg2,
|
|
<a name="l141"></a> </span><span class=cFE>1</span><span class=cF0> << </span><span class=cF3>MESSAGE_MS_L_DOWN</span><span class=cF0> | </span><span class=cFE>1</span><span class=cF0> << </span><span class=cF3>MESSAGE_MS_R_DOWN</span><span class=cF0> | </span><span class=cFE>1</span><span class=cF0> << </span><span class=cF3>MESSAGE_MS_R_UP</span><span class=cF0> | </span><span class=cFE>1</span><span class=cF0> << </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 && </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> && 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> << </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>
|