再帰図形
s(n)を表示します。描画開始この位置は、描画する次数で変化します。
int order=3,h0=512; h=h0/4; x0=2*h;y0=3*h; order=Integer.parseInt(textField1.getText()); if(order>6) { order=6; textField1.setText("6"); } for(i=0;i<=order;i++){ x0=x0-h; h=h/2;y0=y0+h; if(i==order){ x=x0;y=y0;setplot(); da(i,g); x +=h; y -=h;plot(g); db(i,g); x -=h;y -=h;plot(g); dc(i,g); x -=h;y +=h;plot(g); dd(i,g); x +=h;y +=h;plot(g); } } }
public void da(int i,Graphics g){ if(i>0){ da(i-1,g); x +=h;y -=h;plot(g); db(i-1,g); x +=2*h;plot(g); dd(i-1,g); x +=h;y +=h;plot(g); da(i-1,g); } }