templeos-info/public/Wb/Demo/Graphics/PoleZeros.HC.HTML

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> ZEROS_NUM 2
<a name="l2"></a></span><span class=cF9>Complex</span><span class=cF0> zeros[ZEROS_NUM]={</span><span class=cF7>{</span><span class=cF0>10.0,0</span><span class=cF7>}</span><span class=cF0>,</span><span class=cF7>{</span><span class=cF0>-30,0</span><span class=cF7>}</span><span class=cF0>};
<a name="l3"></a>#</span><span class=cF1>define</span><span class=cF0> POLES_NUM 2
<a name="l4"></a></span><span class=cF9>Complex</span><span class=cF0> poles[POLES_NUM]={</span><span class=cF7>{</span><span class=cF0>-20.0,-15.0</span><span class=cF7>}</span><span class=cF0>,</span><span class=cF7>{</span><span class=cF0>-20.0,15.0</span><span class=cF7>}</span><span class=cF0>};
<a name="l5"></a>
<a name="l6"></a></span><span class=cF1>F64</span><span class=cF0> scale;
<a name="l7"></a>
<a name="l8"></a></span><span class=cF9>Complex</span><span class=cF0> *PoleZeroFind(</span><span class=cF9>I64</span><span class=cF0> x,</span><span class=cF9>I64</span><span class=cF0> y)
<a name="l9"></a>{
<a name="l10"></a> </span><span class=cF9>I64</span><span class=cF0> i;
<a name="l11"></a> </span><span class=cF1>F64</span><span class=cF0> dd,best_dd=</span><span class=cF3>F64_MAX</span><span class=cF0>;
<a name="l12"></a> </span><span class=cF9>Complex</span><span class=cF0> *res=</span><span class=cF3>NULL</span><span class=cF0>;
<a name="l13"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i&lt;POLES_NUM;i++) </span><span class=cF7>{</span><span class=cF0>
<a name="l14"></a> dd=</span><span class=cF5>Sqr</span><span class=cF0>(poles[i].x-x)+</span><span class=cF5>Sqr</span><span class=cF0>(poles[i].y-y);
<a name="l15"></a> </span><span class=cF1>if</span><span class=cF0> (dd&lt;best_dd) {
<a name="l16"></a> best_dd=dd;
<a name="l17"></a> res=&amp;poles[i];
<a name="l18"></a> }
<a name="l19"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l20"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i&lt;ZEROS_NUM;i++) </span><span class=cF7>{</span><span class=cF0>
<a name="l21"></a> dd=</span><span class=cF5>Sqr</span><span class=cF0>(zeros[i].x-x)+</span><span class=cF5>Sqr</span><span class=cF0>(zeros[i].y-y);
<a name="l22"></a> </span><span class=cF1>if</span><span class=cF0> (dd&lt;best_dd) {
<a name="l23"></a> best_dd=dd;
<a name="l24"></a> res=&amp;zeros[i];
<a name="l25"></a> }
<a name="l26"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l27"></a> </span><span class=cF1>return</span><span class=cF0> res;
<a name="l28"></a>}
<a name="l29"></a>
<a name="l30"></a></span><span class=cF1>F64</span><span class=cF0> </span><span class=cF5>F</span><span class=cF0>(</span><span class=cF9>Complex</span><span class=cF0> *x)
<a name="l31"></a>{
<a name="l32"></a> </span><span class=cF1>F64</span><span class=cF0> m,a;
<a name="l33"></a> </span><span class=cF9>Complex</span><span class=cF0> num,denom,n1;
<a name="l34"></a>
<a name="l35"></a> </span><span class=cF5>CPoly</span><span class=cF0>(&amp;num, ZEROS_NUM,zeros,x);
<a name="l36"></a> </span><span class=cF5>CPoly</span><span class=cF0>(&amp;denom,POLES_NUM,poles,x);
<a name="l37"></a> </span><span class=cF5>CDiv</span><span class=cF0>(&amp;n1,&amp;num,&amp;denom);
<a name="l38"></a>
<a name="l39"></a> </span><span class=cF5>R2P</span><span class=cF0>(&amp;m,&amp;a,n1.x,n1.y);
<a name="l40"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cFB>ms</span><span class=cF0>.rb)
<a name="l41"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>pi</span><span class=cF0>+a;
<a name="l42"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l43"></a> </span><span class=cF1>return</span><span class=cF0> m;
<a name="l44"></a>}
<a name="l45"></a>
<a name="l46"></a></span><span class=cF1>F64</span><span class=cF0> MPDraw(</span><span class=cF9>CTask</span><span class=cF0> *task)
<a name="l47"></a>{
<a name="l48"></a> </span><span class=cF9>Complex</span><span class=cF0> xx;
<a name="l49"></a> </span><span class=cF9>I64</span><span class=cF0> x,y,w=task-&gt;pix_width,h=task-&gt;pix_height,cx=w/2,cy=h/2,
<a name="l50"></a> lo=</span><span class=cF5>Gs</span><span class=cF0>-&gt;num*h/</span><span class=cFB>mp_cnt</span><span class=cF0>,hi=(</span><span class=cF5>Gs</span><span class=cF0>-&gt;num+1)*h/</span><span class=cFB>mp_cnt</span><span class=cF0>;
<a name="l51"></a> </span><span class=cF1>F64</span><span class=cF0> yy,y_total=0;
<a name="l52"></a> </span><span class=cF9>CDC</span><span class=cF0> *dc=</span><span class=cF5>DCAlias</span><span class=cF0>(,task);
<a name="l53"></a> </span><span class=cF1>for</span><span class=cF0> (y=lo;y&lt;hi;y++) </span><span class=cF7>{</span><span class=cF0>
<a name="l54"></a> </span><span class=cF1>for</span><span class=cF0> (x=0;x&lt;w;x++) {
<a name="l55"></a> </span><span class=cF5>CEqu</span><span class=cF0>(&amp;xx,x-cx,cy-y);
<a name="l56"></a> yy=scale*</span><span class=cF5>F</span><span class=cF0>(&amp;xx);
<a name="l57"></a> dc-&gt;color=</span><span class=cF5>Clamp</span><span class=cF0>(yy,0,14);
<a name="l58"></a> y_total+=</span><span class=cF5>Clamp</span><span class=cF0>(yy,-14,14);
<a name="l59"></a> </span><span class=cF5>GrPlot</span><span class=cF0>(dc,x,y);
<a name="l60"></a> }
<a name="l61"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l62"></a> </span><span class=cF5>DCDel</span><span class=cF0>(dc);
<a name="l63"></a> </span><span class=cF1>return</span><span class=cF0> y_total;
<a name="l64"></a>}
<a name="l65"></a>
<a name="l66"></a></span><span class=cF1>U0</span><span class=cF0> Draw()
<a name="l67"></a>{
<a name="l68"></a> </span><span class=cF9>CJob</span><span class=cF0> *tmpm[</span><span class=cF3>MP_PROCESSORS_NUM</span><span class=cF0>];
<a name="l69"></a> </span><span class=cF1>F64</span><span class=cF0> y_total,old_y_total=</span><span class=cF3>F64_MAX</span><span class=cF0>;
<a name="l70"></a> </span><span class=cF9>I64</span><span class=cF0> i,w=</span><span class=cF5>Fs</span><span class=cF0>-&gt;pix_width,h=</span><span class=cF5>Fs</span><span class=cF0>-&gt;pix_height,cx=w/2,cy=h/2;
<a name="l71"></a> </span><span class=cF9>CDC</span><span class=cF0> *dc=</span><span class=cF5>DCAlias</span><span class=cF0>;
<a name="l72"></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="l73"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i&lt;</span><span class=cFB>mp_cnt</span><span class=cF0>;i++)
<a name="l74"></a> tmpm[i]=</span><span class=cF5>JobQue</span><span class=cF0>(&amp;MPDraw,</span><span class=cF5>Fs</span><span class=cF0>,i,0);
<a name="l75"></a> y_total=0;
<a name="l76"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i&lt;</span><span class=cFB>mp_cnt</span><span class=cF0>;i++)
<a name="l77"></a> y_total+=</span><span class=cF5>JobResGet</span><span class=cF0>(tmpm[i])(</span><span class=cF1>F64</span><span class=cF0>);
<a name="l78"></a>
<a name="l79"></a> </span><span class=cF1>if</span><span class=cF0> (!y_total) </span><span class=cF1>break</span><span class=cF0>;
<a name="l80"></a> scale*=7*</span><span class=cF3>GR_WIDTH</span><span class=cF0>*</span><span class=cF3>GR_HEIGHT</span><span class=cF0>/y_total;
<a name="l81"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>Abs</span><span class=cF7>(</span><span class=cF0>y_total-old_y_total</span><span class=cF7>)</span><span class=cF0>&lt;1.0*</span><span class=cF3>GR_WIDTH</span><span class=cF0>*</span><span class=cF3>GR_HEIGHT</span><span class=cF0>)
<a name="l82"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l83"></a> old_y_total=y_total;
<a name="l84"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l85"></a> dc-&gt;color=15;
<a name="l86"></a> </span><span class=cF5>GrLine</span><span class=cF0>(dc,0,cy,w,cy);
<a name="l87"></a> </span><span class=cF5>GrLine</span><span class=cF0>(dc,cx,0,cx,h);
<a name="l88"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i&lt;ZEROS_NUM;i++)
<a name="l89"></a> </span><span class=cF5>GrPrint</span><span class=cF0>(dc,cx+zeros[i].x-</span><span class=cF3>FONT_WIDTH</span><span class=cF0>/2,cy-zeros[i].y-</span><span class=cF3>FONT_HEIGHT</span><span class=cF0>/2,</span><span class=cF6>&quot;o&quot;</span><span class=cF0>);
<a name="l90"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i&lt;POLES_NUM;i++)
<a name="l91"></a> </span><span class=cF5>GrPrint</span><span class=cF0>(dc,cx+poles[i].x-</span><span class=cF3>FONT_WIDTH</span><span class=cF0>/2,cy-poles[i].y-</span><span class=cF3>FONT_HEIGHT</span><span class=cF0>/2,</span><span class=cF6>&quot;x&quot;</span><span class=cF0>);
<a name="l92"></a> </span><span class=cF5>DCDel</span><span class=cF0>(dc);
<a name="l93"></a>}
<a name="l94"></a>
<a name="l95"></a></span><span class=cF1>U0</span><span class=cF0> PoleZeros()
<a name="l96"></a>{
<a name="l97"></a> </span><span class=cF9>I64</span><span class=cF0> msg_code,arg1,arg2,p11,p22,cx,cy;
<a name="l98"></a> </span><span class=cF9>Complex</span><span class=cF0> *tmpc=</span><span class=cF3>NULL</span><span class=cF0>;
<a name="l99"></a>
<a name="l100"></a> </span><span class=cF5>PopUpOk</span><span class=cF0>(
<a name="l101"></a> </span><span class=cF6>&quot;Drag the poles and zeros with left mouse.\n&quot;</span><span class=cF0>
<a name="l102"></a> </span><span class=cF6>&quot;Hold right mouse for phase plot.\n&quot;</span><span class=cF0>
<a name="l103"></a> );
<a name="l104"></a>
<a name="l105"></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="l106"></a> </span><span class=cF5>Fs</span><span class=cF0>-&gt;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="l107"></a> </span><span class=cF5>GrPaletteSet</span><span class=cF0>(</span><span class=cFB>gr_palette_gray</span><span class=cF0>);
<a name="l108"></a> </span><span class=cF5>GrPaletteColorSet</span><span class=cF0>(15,0xFFFF00000000); </span><span class=cF2>//White is red</span><span class=cF0>
<a name="l109"></a>
<a name="l110"></a> </span><span class=cF5>AutoComplete</span><span class=cF0>;
<a name="l111"></a> </span><span class=cF5>WinBorder</span><span class=cF0>;
<a name="l112"></a> </span><span class=cF5>WinMax</span><span class=cF0>;
<a name="l113"></a> </span><span class=cF5>DocClear</span><span class=cF0>;
<a name="l114"></a> </span><span class=cF5>DCFill</span><span class=cF0>;
<a name="l115"></a> scale=1.0;
<a name="l116"></a>
<a name="l117"></a> </span><span class=cF1>try</span><span class=cF0> </span><span class=cF7>{</span><span class=cF0>
<a name="l118"></a> Draw;
<a name="l119"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF3>TRUE</span><span class=cF0>) {
<a name="l120"></a> msg_code=</span><span class=cF5>GetMsg</span><span class=cF0>(&amp;arg1,&amp;arg2,1&lt;&lt;</span><span class=cF3>MSG_KEY_DOWN</span><span class=cF0>+1&lt;&lt;</span><span class=cF3>MSG_MS_L_DOWN</span><span class=cF0>+
<a name="l121"></a> 1&lt;&lt;</span><span class=cF3>MSG_MS_L_UP</span><span class=cF0>+1&lt;&lt;</span><span class=cF3>MSG_MS_R_DOWN</span><span class=cF0>+1&lt;&lt;</span><span class=cF3>MSG_MS_R_UP</span><span class=cF0>+1&lt;&lt;</span><span class=cF3>MSG_MS_MOVE</span><span class=cF0>);
<a name="l122"></a>pz_msg:
<a name="l123"></a> cx=</span><span class=cF5>Fs</span><span class=cF0>-&gt;pix_width/2;
<a name="l124"></a> cy=</span><span class=cF5>Fs</span><span class=cF0>-&gt;pix_height/2;
<a name="l125"></a> </span><span class=cF1>switch</span><span class=cF0> (msg_code) </span><span class=cF7>{</span><span class=cF0>
<a name="l126"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>MSG_MS_L_DOWN</span><span class=cF0>:
<a name="l127"></a> tmpc=PoleZeroFind(arg1-cx,cy-arg2);
<a name="l128"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l129"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>MSG_MS_MOVE</span><span class=cF0>:
<a name="l130"></a> </span><span class=cF1>if</span><span class=cF0> (tmpc) {
<a name="l131"></a> p11=arg1;p22=arg2;
<a name="l132"></a></span><span class=cF2>//get to last mouse move</span><span class=cF0>
<a name="l133"></a> </span><span class=cF1>while</span><span class=cF0> (msg_code=</span><span class=cF5>ScanMsg</span><span class=cF7>(</span><span class=cF0>&amp;arg1,&amp;arg2,
<a name="l134"></a> 1&lt;&lt;</span><span class=cF3>MSG_KEY_DOWN</span><span class=cF0>+1&lt;&lt;</span><span class=cF3>MSG_MS_L_DOWN</span><span class=cF0>+
<a name="l135"></a> 1&lt;&lt;</span><span class=cF3>MSG_MS_L_UP</span><span class=cF0>+1&lt;&lt;</span><span class=cF3>MSG_MS_R_DOWN</span><span class=cF0>+
<a name="l136"></a> 1&lt;&lt;</span><span class=cF3>MSG_MS_R_UP</span><span class=cF0>+1&lt;&lt;</span><span class=cF3>MSG_MS_MOVE</span><span class=cF7>)</span><span class=cF0>)
<a name="l137"></a> </span><span class=cF1>if</span><span class=cF0> (msg_code==</span><span class=cF3>MSG_MS_MOVE</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
<a name="l138"></a> p11=arg1;p22=arg2;
<a name="l139"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>else</span><span class=cF0>
<a name="l140"></a> </span><span class=cF1>goto</span><span class=cF0> pz_msg;
<a name="l141"></a>
<a name="l142"></a> tmpc-&gt;x=p11-cx;
<a name="l143"></a> tmpc-&gt;y=cy-p22;
<a name="l144"></a> Draw;
<a name="l145"></a> }
<a name="l146"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l147"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>MSG_MS_L_UP</span><span class=cF0>:
<a name="l148"></a> </span><span class=cF1>if</span><span class=cF0> (tmpc) {
<a name="l149"></a> tmpc-&gt;x=arg1-cx;
<a name="l150"></a> tmpc-&gt;y=cy-arg2;
<a name="l151"></a> tmpc=</span><span class=cF3>NULL</span><span class=cF0>;
<a name="l152"></a> Draw;
<a name="l153"></a> }
<a name="l154"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l155"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>MSG_MS_R_DOWN</span><span class=cF0>:
<a name="l156"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>MSG_MS_R_UP</span><span class=cF0>:
<a name="l157"></a> Draw;
<a name="l158"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l159"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>MSG_KEY_DOWN</span><span class=cF0>:
<a name="l160"></a> </span><span class=cF1>if</span><span class=cF0> (arg1==</span><span class=cF3>CH_SHIFT_ESC</span><span class=cF0>||arg1==</span><span class=cF3>CH_ESC</span><span class=cF0>)
<a name="l161"></a> </span><span class=cF1>goto</span><span class=cF0> pz_done;
<a name="l162"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l163"></a> </span><span class=cF5>Refresh</span><span class=cF0>;
<a name="l164"></a> }
<a name="l165"></a>pz_done:
<a name="l166"></a> </span><span class=cF5>GetMsg</span><span class=cF0>(,,1&lt;&lt;</span><span class=cF3>MSG_KEY_UP</span><span class=cF0>);
<a name="l167"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>catch</span><span class=cF0>
<a name="l168"></a> </span><span class=cF5>PutExcept</span><span class=cF0>;
<a name="l169"></a> </span><span class=cF5>SettingsPop</span><span class=cF0>;
<a name="l170"></a> </span><span class=cF5>DCFill</span><span class=cF0>;
<a name="l171"></a>}
<a name="l172"></a>
<a name="l173"></a>PoleZeros;
</span></pre></body>
</html>