rdline,prompt="Yorickの例"; write,format="%s\n","Fibonacci数の例" write,format="%s\n","func Fib2(n){\n \ local F0,F1,tmp;\n \ F0=0.; F1=1.;\n \ if(n==0) F1=F0;\n \ for(i=2;i<=n;i++){tmp=F1; F1=F0+F1; F0=tmp;};\n \ return(F1);};"; func Fib2(n){ local F0,F1,tmp; F0=0.; F1=1.; if(n==0) F1=F0; for(i=2;i<=n;i++){tmp=F1; F1=F0+F1; F0=tmp;}; return(F1);}; write,format="%s\n","多倍長精度の例" write,format="%s\n","include,\"FibMP.i\";"; include,"FibMP.i" rdline,prompt="> "; write,format="%s\n","setMPIDigit;"; setMPIDigit; rdline,prompt="> "; write,format="%s\n","printMPI(Fib2MPI(10));"; printMPI(Fib2MPI(10)); rdline,prompt="> "; write,format="%s\n","printMPI(Fib2MPI(100));"; printMPI(Fib2MPI(100)); rdline,prompt="> "; write,format="%s\n","printMPI(Fib2MPI(10000));"; printMPI(Fib2MPI(10000)); rdline,prompt="> "; rdline,prompt="画像処理の簡単な例"; extern _Px, _Py, _Q, _Pred; _Px=1;_Py=1;_Q=1;_Pred=1; rdline,prompt="画像ファイルを読み込みます "; write,format="%s\n","skel=jpeg_read(\"Kodairi.jpeg\");"; skel=jpeg_read("Kodairi.jpeg"); rdline,prompt="描画ウィンドウの生成を行います"; write,format="%s\n","window,1,dpi=100;"; window,1,dpi=100; rdline,prompt="画像の表示"; write,format="%s\n","pli,skel;" pli,skel; rdline,prompt="画像の縦横比を保つ様に変更します"; write,format="%s\n","limits,square=1;" limits,square=1; rdline,prompt="画像の表示で上下を逆にします"; write,format="%s\n","fma;pli,skel(,,::-1);" fma;pli,skel(,,::-1); rdline,prompt="この様に添字::-1で行えます"; rdline,prompt="正方形に表示した方が見易いので縦横比の保持を止めます"; write,format="%s\n","limits,square=0;" limits,square=0; rdline,prompt="輝度で領域の取り出しを行います"; write,format="%s\n","B1=skel(1,,::-1)>200;"; B1=skel(1,,::-1)>200; write,format="%s\n","B2=skel(2,,::-1)>200;"; B2=skel(2,,::-1)>200; write,format="%s\n","B3=skel(3,,::-1)>100;"; B3=skel(3,,::-1)>100; write,format="%s\n","C1=B1*B2*B3;"; C1=B1*B2*B3; write,format="%s\n","fma;pli,C1"; fma;pli,C1; rdline,prompt="白い部分が取り出す部位になります"; write,format="%s\n","A1=skel;"; A1=skel; write,format="%s\n","A1(1,,)=C1*A1(1,,::-1);"; A1(1,,)=C1*A1(1,,::-1); write,format="%s\n","A1(2,,)=C1*A1(2,,::-1);"; A1(2,,)=C1*A1(2,,::-1); write,format="%s\n","A1(3,,)=C1*A1(3,,::-1);"; A1(3,,)=C1*A1(3,,::-1); write,format="%s\n","fma;pli,A1;"; fma;pli,A1; rdline,prompt="もとの画像から引き算を行うこともできます"; write,format="%s\n","fma;pli,skel(,,::-1)-A1;"; fma;pli,skel(,,::-1)-A1; rdline,prompt="述語で指定した領域を取出す函数を定義:" func getDOMAIN(image, p0, pred, option=) { extern _Px, _Py, _Q, _Pred; local dnm,i,n,X,Y,Z; dnm=dimsof(image); Z=image; n=dnm(1); _Px=indgen(1:dnm(3))(,,-:1:dnm(4)); _Py=transpose(indgen(1:dnm(4))(,,-:1:dnm(3))); _Q =p0; predx=pred+" _Px _Py _Q "+option; funcdef(predx); for(i=1;i<=n;i++) Z(i,,)=Z(i,,)*_Pred; return Z;}; write,format="%s\n","func getDOMAIN(image, p0, pred, option=)\n \ {\n \ extern _Px, _Py, _Q, _Pred;\n \ local dnm,i,n,X,Y,Z;\n \ dnm=dimsof(image); Z=image; n=dnm(1);\n \ _Px=indgen(1:dnm(3))(,,-:1:dnm(4));\n \ _Py=transpose(indgen(1:dnm(4))(,,-:1:dnm(3)));\n \ _Q =p0; predx=pred+\" _Px _Py _Q \"+option;\n \ funcdef(predx);\n \ for(i=1;i<=n;i++) Z(i,,)=Z(i,,)*_Pred;\n \ return Z;};"; rdline,prompt="getDOMAIN函数ではfuncdefを用いて文字列として与えられた述語の評価を行います"; rdline,prompt="では, 次に述語を定義します."; rdline,prompt="最初に円状の領域を取出す為の述語:"; func Pred1(Px,Py,Qxy,r) { extern _Pred; _Pred=((Px-Qxy(1))^2+(Py-Qxy(2))^2<=r^2);}; write,format="%s\n","func Pred1(Px,Py,Qxy,r)\n \ {\n \ extern _Pred;\n \ _Pred=((Px-Qxy(1))^2+(Py-Qxy(2))^2<=r^2);};"; rdline,prompt="次は星型の領域を取出す為の述語:"; func Pred2(Px,Py,Qxy,r) { extern _Pred; Px=Px-Qxy(1); Py=Py-Qxy(2); th=pi*2/5; L1=(1-cos(2*th))/sin(2*th)*Px+r-Py; L2=(cos(4*th)-cos(2*th))/(sin(2*th)-sin(4*th))* (Px+r*sin(2*th))+r*cos(2*th)-Py; L3=r*cos(th)-Py; L4=(cos(3*th)-cos(th))/(sin(th)-sin(3*th))* (Px+r*sin(th))+r*cos(th)-Py; L5=(1-cos(3*th))/sin(3*th)*(Px+r*sin(3*th))+r*cos(3*th)-Py; pL1=(L1>=0); mL1=(L1<=0); pL2=(L2>=0); mL2=(L2<=0); pL3=(L3>=0); mL3=(L3<=0); pL4=(L4>=0); mL4=(L4<=0); pL5=(L5>=0); mL5=(L5<=0); R1=pL1*pL5*mL3; R2=pL3*mL4*mL1; R3=pL1*mL2*pL4; R4=pL2*mL4*pL5; R5=pL3*mL2*mL5; R6=pL1*pL3*pL5*mL2*mL4; _Pred=((R1+R2+R3+R4+R5+R6)>0);}; write,format="%s\n","func Pred2(Px,Py,Qxy,r)\n \ {\n \ extern _Pred;\n \ Px=Px-Qxy(1); Py=Py-Qxy(2); th=pi*2/5;\n \ L1=(1-cos(2*th))/sin(2*th)*Px+r-Py;\n \ L2=(cos(4*th)-cos(2*th))/(sin(2*th)-sin(4*th))*\n \ (Px+r*sin(2*th))+r*cos(2*th)-Py;\n \ L3=r*cos(th)-Py;\n \ L4=(cos(3*th)-cos(th))/(sin(th)-sin(3*th))*\n \ (Px+r*sin(th))+r*cos(th)-Py;\n \ L5=(1-cos(3*th))/sin(3*th)*(Px+r*sin(3*th))+r*cos(3*th)-Py;\n \ pL1=(L1>=0); mL1=(L1<=0); pL2=(L2>=0); mL2=(L2<=0);\n \ pL3=(L3>=0); mL3=(L3<=0); pL4=(L4>=0); mL4=(L4<=0);\n \ pL5=(L5>=0); mL5=(L5<=0); \n \ R1=pL1*pL5*mL3; R2=pL3*mL4*mL1; R3=pL1*mL2*pL4;\n \ R4=pL2*mL4*pL5; R5=pL3*mL2*mL5; R6=pL1*pL3*pL5*mL2*mL4;\n \ _Pred=((R1+R2+R3+R4+R5+R6)>0);};"; rdline,prompt="では実行例を"; write,format="%s\n","Hero1=getDOMAIN(skel(,,::-1),[1500,777],\"Pred2\", option=\"200\");\n \ Hime=getDOMAIN(skel(,,::-1),[500,1300],\"Pred1\",option=\"300\")\n \ Hero=getDOMAIN(skel(,,::-1),[1500,777],\"Pred2\",option=\"200\")\n \ Maru=getDOMAIN(skel(,,::-1),[2000,500],\"Pred2\",option=\"200\")\n \ Gai=getDOMAIN(skel(,,::-1),[1750,1300],\"Pred1\",option=\"400\")\n \ fma;pli,Hime+Hero+Maru+Gai"; winkill,1; window,1,dpi=150; Hero=getDOMAIN(skel(,,::-1),[1500,777],"Pred2", option="200"); fma;pli,Hero; rdline,prompt="光圀"; Hime=getDOMAIN(skel(,,::-1),[500,1300],"Pred1",option="300"); fma;pli,Hime; rdline,prompt="滝夜叉姫"; Maru=getDOMAIN(skel(,,::-1),[2000,500],"Pred2",option="200"); fma;pli,Maru; rdline,prompt="手下"; Gai=getDOMAIN(skel(,,::-1),[1750,1300],"Pred1",option="400"); fma;pli,Gai; rdline,prompt="髑髏"; rdline,prompt="では,オールスターで!"; fma;pli,Hime+Hero+Maru+Gai