205 lines
17 KiB
HTML
Executable File
205 lines
17 KiB
HTML
Executable File
<!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=cF0>#</span><span class=cF1>define</span><span class=cF0> BALLS_NUM 7
|
|
<a name="l2"></a>#</span><span class=cF1>define</span><span class=cF0> SPRINGS_NUM 3
|
|
<a name="l3"></a>
|
|
<a name="l4"></a>#</span><span class=cF1>define</span><span class=cF0> STRETCH 500.0
|
|
<a name="l5"></a>#</span><span class=cF1>define</span><span class=cF0> GRAVITY 50.0 </span><span class=cF2>//not really gravity</span><span class=cF0>
|
|
<a name="l6"></a>#</span><span class=cF1>define</span><span class=cF0> BALL_RADIUS 5
|
|
<a name="l7"></a>#</span><span class=cF1>define</span><span class=cF0> BASE_SIZE 10
|
|
<a name="l8"></a>
|
|
<a name="l9"></a></span><span class=cF9>CMass</span><span class=cF0> balls[BALLS_NUM];
|
|
<a name="l10"></a></span><span class=cF9>CSpring</span><span class=cF0> springs[SPRINGS_NUM];
|
|
<a name="l11"></a></span><span class=cF1>F64</span><span class=cF0> collision_t;
|
|
<a name="l12"></a>
|
|
<a name="l13"></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> *task,</span><span class=cF9>CDC</span><span class=cF0> *dc)
|
|
<a name="l14"></a>{
|
|
<a name="l15"></a> </span><span class=cF9>I64</span><span class=cF0> i,
|
|
<a name="l16"></a> cx=task->pix_width>>1,
|
|
<a name="l17"></a> cy=task->pix_height>>1;
|
|
<a name="l18"></a> </span><span class=cF1>Bool</span><span class=cF0> snd_on=</span><span class=cF3>FALSE</span><span class=cF0>;
|
|
<a name="l19"></a> dc->color=</span><span class=cF3>BLACK</span><span class=cF0>;
|
|
<a name="l20"></a> </span><span class=cF5>GrPrint</span><span class=cF0>(dc,0,0,</span><span class=cF6>"Protect your base."</span><span class=cF0>);
|
|
<a name="l21"></a> </span><span class=cF5>GrRect</span><span class=cF0>(dc,cx-BASE_SIZE,cy-BASE_SIZE,BASE_SIZE*2,BASE_SIZE*2);
|
|
<a name="l22"></a> dc->color=</span><span class=cF3>CYAN</span><span class=cF0>;
|
|
<a name="l23"></a> </span><span class=cF5>GrRect</span><span class=cF0>(dc,cx-BASE_SIZE+2,cy-BASE_SIZE+2,BASE_SIZE*2-4,BASE_SIZE*2-4);
|
|
<a name="l24"></a> dc->color=</span><span class=cF3>YELLOW</span><span class=cF0>;
|
|
<a name="l25"></a> </span><span class=cF5>GrLine</span><span class=cF0>(dc,balls[0].x,balls[0].y,
|
|
<a name="l26"></a> </span><span class=cFB>ms</span><span class=cF0>.pos.x-task->pix_left-task->scroll_x,
|
|
<a name="l27"></a> </span><span class=cFB>ms</span><span class=cF0>.pos.y-task->pix_top-task->scroll_y);
|
|
<a name="l28"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i<SPRINGS_NUM;i++)
|
|
<a name="l29"></a> </span><span class=cF5>GrLine</span><span class=cF0>(dc,springs[i].end1->x,springs[i].end1->y,
|
|
<a name="l30"></a> springs[i].end2->x,springs[i].end2->y);
|
|
<a name="l31"></a>
|
|
<a name="l32"></a> dc->color=</span><span class=cF3>LTCYAN</span><span class=cF0>;
|
|
<a name="l33"></a> </span><span class=cF5>GrCircle</span><span class=cF0>(dc,balls[0].x,balls[0].y,BALL_RADIUS);
|
|
<a name="l34"></a> </span><span class=cF5>GrFloodFill</span><span class=cF0>(dc,balls[0].x,balls[0].y,</span><span class=cF3>TRUE</span><span class=cF0>);
|
|
<a name="l35"></a> dc->color=</span><span class=cF3>BLACK</span><span class=cF0>;
|
|
<a name="l36"></a> </span><span class=cF5>GrCircle</span><span class=cF0>(dc,balls[0].x,balls[0].y,BALL_RADIUS);
|
|
<a name="l37"></a>
|
|
<a name="l38"></a> </span><span class=cF1>for</span><span class=cF0> (i=1;i<BALLS_NUM;i++) </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l39"></a> dc->color=</span><span class=cF3>LTPURPLE</span><span class=cF0>;
|
|
<a name="l40"></a> </span><span class=cF5>GrCircle</span><span class=cF0>(dc,balls[i].x,balls[i].y,BALL_RADIUS);
|
|
<a name="l41"></a> </span><span class=cF5>GrFloodFill</span><span class=cF0>(dc,balls[i].x,balls[i].y,</span><span class=cF3>TRUE</span><span class=cF0>);
|
|
<a name="l42"></a> </span><span class=cF1>if</span><span class=cF0> (cx-BASE_SIZE-BALL_RADIUS<=balls[i].x<=cx+BASE_SIZE+BALL_RADIUS &&
|
|
<a name="l43"></a> cy-BASE_SIZE-BALL_RADIUS<=balls[i].y<=cy+BASE_SIZE+BALL_RADIUS)
|
|
<a name="l44"></a> snd_on=</span><span class=cF3>TRUE</span><span class=cF0>;
|
|
<a name="l45"></a> dc->color=</span><span class=cF3>BLACK</span><span class=cF0>;
|
|
<a name="l46"></a> </span><span class=cF5>GrCircle</span><span class=cF0>(dc,balls[i].x,balls[i].y,BALL_RADIUS);
|
|
<a name="l47"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l48"></a> </span><span class=cF1>if</span><span class=cF0> (snd_on)
|
|
<a name="l49"></a> </span><span class=cF5>Snd</span><span class=cF0>(74);
|
|
<a name="l50"></a> </span><span class=cF1>else</span><span class=cF0>
|
|
<a name="l51"></a> </span><span class=cF5>Snd</span><span class=cF0>;
|
|
<a name="l52"></a>}
|
|
<a name="l53"></a>
|
|
<a name="l54"></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> t,</span><span class=cF9>COrder2D3</span><span class=cF0> *,</span><span class=cF9>COrder2D3</span><span class=cF0> *)
|
|
<a name="l55"></a>{
|
|
<a name="l56"></a> </span><span class=cF9>I64</span><span class=cF0> i,j;
|
|
<a name="l57"></a> </span><span class=cF1>F64</span><span class=cF0> d,dd;
|
|
<a name="l58"></a> </span><span class=cF9>CD3</span><span class=cF0> p,p2;
|
|
<a name="l59"></a> </span><span class=cF9>CTask</span><span class=cF0> *task=ode->win_task;
|
|
<a name="l60"></a>
|
|
<a name="l61"></a> </span><span class=cF5>D3SubEqu</span><span class=cF0>(</span><span class=cF5>D3Equ</span><span class=cF7>(</span><span class=cF0>&p2,
|
|
<a name="l62"></a> </span><span class=cFB>ms</span><span class=cF0>.pos.x-task->pix_left-task->scroll_x,
|
|
<a name="l63"></a> </span><span class=cFB>ms</span><span class=cF0>.pos.y-task->pix_top-task->scroll_y,0</span><span class=cF7>)</span><span class=cF0>,
|
|
<a name="l64"></a> &balls[0].state->x);
|
|
<a name="l65"></a> </span><span class=cF5>D3AddEqu</span><span class=cF0>(&balls[0].DstateDt->DxDt,</span><span class=cF5>D3MulEqu</span><span class=cF7>(</span><span class=cF0>&p2,STRETCH</span><span class=cF7>)</span><span class=cF0>);
|
|
<a name="l66"></a>
|
|
<a name="l67"></a> </span><span class=cF5>D3Equ</span><span class=cF0>(&p2,task->pix_width>>1,task->pix_height>>1,0);
|
|
<a name="l68"></a> </span><span class=cF1>for</span><span class=cF0> (i=1;i<BALLS_NUM;i++) </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l69"></a> </span><span class=cF5>D3Sub</span><span class=cF0>(&p,&p2,&balls[i].state->x);
|
|
<a name="l70"></a> </span><span class=cF1>if</span><span class=cF0> (d=</span><span class=cF5>D3Norm</span><span class=cF7>(</span><span class=cF0>&p</span><span class=cF7>)</span><span class=cF0>) {
|
|
<a name="l71"></a></span><span class=cF2>//Gravity would be /(d*d*d), but that's too exponential.</span><span class=cF0>
|
|
<a name="l72"></a> </span><span class=cF5>D3MulEqu</span><span class=cF0>(&p,GRAVITY/d);
|
|
<a name="l73"></a> </span><span class=cF5>D3AddEqu</span><span class=cF0>(&balls[i].DstateDt->DxDt,&p);
|
|
<a name="l74"></a> }
|
|
<a name="l75"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l76"></a>
|
|
<a name="l77"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i<BALLS_NUM;i++)
|
|
<a name="l78"></a> </span><span class=cF1>for</span><span class=cF0> (j=i+1;j<BALLS_NUM;j++) </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l79"></a> </span><span class=cF5>D3Sub</span><span class=cF0>(&p,&balls[j].state->x,&balls[i].state->x);
|
|
<a name="l80"></a> dd=</span><span class=cF5>D3NormSqr</span><span class=cF0>(&p);
|
|
<a name="l81"></a> </span><span class=cF1>if</span><span class=cF0> (dd<=</span><span class=cF7>(</span><span class=cF0>2*BALL_RADIUS</span><span class=cF7>)</span><span class=cF0>*</span><span class=cF7>(</span><span class=cF0>2*BALL_RADIUS</span><span class=cF7>)</span><span class=cF0>) {
|
|
<a name="l82"></a> </span><span class=cF1>if</span><span class=cF0> (t-collision_t>0.05) </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l83"></a> </span><span class=cF5>Noise</span><span class=cF0>(50,102,105);
|
|
<a name="l84"></a> collision_t=t;
|
|
<a name="l85"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l86"></a> d=</span><span class=cF5>Sqrt</span><span class=cF0>(dd)+0.0001;
|
|
<a name="l87"></a> dd=10.0*</span><span class=cF5>Sqr</span><span class=cF0>(</span><span class=cF5>Sqr</span><span class=cF7>(</span><span class=cF0>(2*BALL_RADIUS)*(2*BALL_RADIUS)-dd</span><span class=cF7>)</span><span class=cF0>);
|
|
<a name="l88"></a> </span><span class=cF5>D3MulEqu</span><span class=cF0>(&p,dd/d);
|
|
<a name="l89"></a> </span><span class=cF5>D3AddEqu</span><span class=cF0>(&balls[j].DstateDt->DxDt,&p);
|
|
<a name="l90"></a> </span><span class=cF5>D3SubEqu</span><span class=cF0>(&balls[i].DstateDt->DxDt,&p);
|
|
<a name="l91"></a> }
|
|
<a name="l92"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l93"></a>
|
|
<a name="l94"></a> d=balls[0].state->x;
|
|
<a name="l95"></a> </span><span class=cF1>if</span><span class=cF0> (d-BALL_RADIUS<0)
|
|
<a name="l96"></a> balls[0].DstateDt->DxDt+=</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>(d-BALL_RADIUS)</span><span class=cF7>)</span><span class=cF0>);
|
|
<a name="l97"></a> </span><span class=cF1>if</span><span class=cF0> (d+BALL_RADIUS>task->pix_width)
|
|
<a name="l98"></a> balls[0].DstateDt->DxDt-=</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>(</span><span class=cF7>(</span><span class=cF0>d+BALL_RADIUS</span><span class=cF7>)</span><span class=cF0>-task->pix_width)</span><span class=cF7>)</span><span class=cF0>);
|
|
<a name="l99"></a>
|
|
<a name="l100"></a> d=balls[0].state->y;
|
|
<a name="l101"></a> </span><span class=cF1>if</span><span class=cF0> (d-BALL_RADIUS<0)
|
|
<a name="l102"></a> balls[0].DstateDt->DyDt+=</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>(d-BALL_RADIUS)</span><span class=cF7>)</span><span class=cF0>);
|
|
<a name="l103"></a> </span><span class=cF1>if</span><span class=cF0> (d+BALL_RADIUS>task->pix_height)
|
|
<a name="l104"></a> balls[0].DstateDt->DyDt-=</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>(</span><span class=cF7>(</span><span class=cF0>d+BALL_RADIUS</span><span class=cF7>)</span><span class=cF0>-task->pix_height)</span><span class=cF7>)</span><span class=cF0>);
|
|
<a name="l105"></a>}
|
|
<a name="l106"></a>
|
|
<a name="l107"></a></span><span class=cF1>U0</span><span class=cF0> Whap()
|
|
<a name="l108"></a>{
|
|
<a name="l109"></a> </span><span class=cF9>I64</span><span class=cF0> i;
|
|
<a name="l110"></a> </span><span class=cF9>CMathODE</span><span class=cF0> *ode=</span><span class=cF5>ODENew</span><span class=cF0>(0,1e-2,</span><span class=cF3>ODEF_HAS_MASSES</span><span class=cF0>);
|
|
<a name="l111"></a>
|
|
<a name="l112"></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="l113"></a> </span><span class=cF5>AutoComplete</span><span class=cF0>;
|
|
<a name="l114"></a> </span><span class=cF5>WinBorder</span><span class=cF0>;
|
|
<a name="l115"></a> </span><span class=cF5>WinMax</span><span class=cF0>;
|
|
<a name="l116"></a>
|
|
<a name="l117"></a> </span><span class=cF5>MenuPush</span><span class=cF0>(
|
|
<a name="l118"></a> </span><span class=cF6>"File {"</span><span class=cF0>
|
|
<a name="l119"></a> </span><span class=cF6>" Abort(,CH_SHIFT_ESC);"</span><span class=cF0>
|
|
<a name="l120"></a> </span><span class=cF6>" Exit(,CH_ESC);"</span><span class=cF0>
|
|
<a name="l121"></a> </span><span class=cF6>"}"</span><span class=cF0>
|
|
<a name="l122"></a> );
|
|
<a name="l123"></a> ode->derive=&MyDerivative;
|
|
<a name="l124"></a> ode->drag_v2=0.002;
|
|
<a name="l125"></a> ode->drag_v3=0.00001;
|
|
<a name="l126"></a> ode->acceleration_limit=5e3;
|
|
<a name="l127"></a> </span><span class=cF5>MemSet</span><span class=cF0>(balls,0,BALLS_NUM*</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF9>CMass</span><span class=cF7>)</span><span class=cF0>);
|
|
<a name="l128"></a> </span><span class=cF5>D3Equ</span><span class=cF0>(&balls[0].x,100,100,0);
|
|
<a name="l129"></a> </span><span class=cF1>for</span><span class=cF0> (i=1;i<BALLS_NUM;i++)
|
|
<a name="l130"></a> </span><span class=cF5>D3Equ</span><span class=cF0>(&balls[i].x,
|
|
<a name="l131"></a> </span><span class=cF5>RandI16</span><span class=cF0>%500+</span><span class=cF5>Fs</span><span class=cF0>->pix_width>>1,</span><span class=cF5>RandI16</span><span class=cF0>%500+</span><span class=cF5>Fs</span><span class=cF0>->pix_height>>1,0);
|
|
<a name="l132"></a> balls[0].x=</span><span class=cFB>ms</span><span class=cF0>.pos.x-</span><span class=cF5>Fs</span><span class=cF0>->pix_left-</span><span class=cF5>Fs</span><span class=cF0>->scroll_x;
|
|
<a name="l133"></a> balls[0].y=</span><span class=cFB>ms</span><span class=cF0>.pos.y-</span><span class=cF5>Fs</span><span class=cF0>->pix_top-</span><span class=cF5>Fs</span><span class=cF0>->scroll_y;
|
|
<a name="l134"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i<BALLS_NUM;i++) </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l135"></a> balls[i].mass=1.0;
|
|
<a name="l136"></a> balls[i].drag_profile_factor=1.0;
|
|
<a name="l137"></a> </span><span class=cF5>QueIns</span><span class=cF0>(&balls[i],ode->last_mass);
|
|
<a name="l138"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l139"></a> balls[2].x=balls[1].x+15;
|
|
<a name="l140"></a> balls[2].y=balls[1].y;
|
|
<a name="l141"></a> balls[3].x=balls[1].x;
|
|
<a name="l142"></a> balls[3].y=balls[1].y+15;
|
|
<a name="l143"></a> </span><span class=cF5>MemSet</span><span class=cF0>(springs,0,SPRINGS_NUM*</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF9>CSpring</span><span class=cF7>)</span><span class=cF0>);
|
|
<a name="l144"></a> springs[0].end1=&balls[1];
|
|
<a name="l145"></a> springs[0].end2=&balls[2];
|
|
<a name="l146"></a> springs[0].rest_len=15;
|
|
<a name="l147"></a> springs[0].const=10000;
|
|
<a name="l148"></a> </span><span class=cF5>QueIns</span><span class=cF0>(&springs[0],ode->last_spring);
|
|
<a name="l149"></a> springs[1].end1=&balls[1];
|
|
<a name="l150"></a> springs[1].end2=&balls[3];
|
|
<a name="l151"></a> springs[1].rest_len=15;
|
|
<a name="l152"></a> springs[1].const=10000;
|
|
<a name="l153"></a> </span><span class=cF5>QueIns</span><span class=cF0>(&springs[1],ode->last_spring);
|
|
<a name="l154"></a> springs[2].end1=&balls[2];
|
|
<a name="l155"></a> springs[2].end2=&balls[3];
|
|
<a name="l156"></a> springs[2].rest_len=</span><span class=cF3>sqrt2</span><span class=cF0>*15;
|
|
<a name="l157"></a> springs[2].const=10000;
|
|
<a name="l158"></a> </span><span class=cF5>QueIns</span><span class=cF0>(&springs[2],ode->last_spring);
|
|
<a name="l159"></a>
|
|
<a name="l160"></a> collision_t=0;
|
|
<a name="l161"></a> </span><span class=cF5>QueIns</span><span class=cF0>(ode,</span><span class=cF5>Fs</span><span class=cF0>->last_ode);
|
|
<a name="l162"></a>
|
|
<a name="l163"></a> </span><span class=cF5>DocCursor</span><span class=cF0>;
|
|
<a name="l164"></a> </span><span class=cF5>DocClear</span><span class=cF0>;
|
|
<a name="l165"></a> </span><span class=cF5>Fs</span><span class=cF0>->draw_it=&</span><span class=cF5>DrawIt</span><span class=cF0>;
|
|
<a name="l166"></a> </span><span class=cF5>GetChar</span><span class=cF0>;
|
|
<a name="l167"></a> </span><span class=cF5>SettingsPop</span><span class=cF0>;
|
|
<a name="l168"></a> </span><span class=cF5>QueRem</span><span class=cF0>(ode);
|
|
<a name="l169"></a> </span><span class=cF5>ODEDel</span><span class=cF0>(ode);
|
|
<a name="l170"></a> </span><span class=cF5>MenuPop</span><span class=cF0>;
|
|
<a name="l171"></a>}
|
|
<a name="l172"></a>
|
|
<a name="l173"></a>Whap;
|
|
</span></pre></body>
|
|
</html>
|