/*********************************/ /* */ /* マンデルブロ集合の軌道 */ /* */ /* 1998/ 1/19 宍戸 輝光 */ /* */ /*********************************/ import java.awt.*; public class mandd extends java.applet.Applet implements Runnable { int max; double sr,si,range,dr,di; int sn[][]=new int[300][300]; Image screen; Graphics g_screen; Color cl[]=new Color[8]; boolean doing,go; Button ctrb; Label nl,pl,il; TextField rf,imf; Thread runner=null; public void init(){ resize(420,360); setBackground(Color.lightGray); setFont(new Font("TimesRoman",Font.PLAIN,12)); screen=createImage(302,302); /* 表示用イメージ */ g_screen=screen.getGraphics(); this.setLayout((LayoutManager)null); ctrb=new Button("Clear"); add(ctrb); ctrb.reshape(316,240,64,32); nl=new Label("0 "); add(nl); nl.reshape(316,288,64,32); rf=new TextField(10); add(rf); rf.reshape(8,316,80,24); rf.setBackground(Color.lightGray); pl=new Label("+"); add(pl); pl.reshape(90,316,20,20); imf=new TextField(10); add(imf); imf.reshape(112,316,80,24); imf.setBackground(Color.lightGray); il=new Label("i"); add(il); il.reshape(200,316,16,20); cl[0]=new Color(255,255,255); cl[1]=new Color(255,192,255); cl[2]=new Color(255,128,255); cl[3]=new Color(255,128,192); cl[4]=new Color(255,128,128); cl[5]=new Color(255,0,128); cl[6]=new Color(255,0,0); cl[7]=new Color(160,0,0); max=500; clearScreen(); startDraw(); } public void stop() { /*終了時にスレッド破棄*/ if (runner!=null) { runner.stop(); runner=null; } } public void clearScreen() { g_screen.setColor(Color.black); g_screen.fillRect(0,0,300,300); sr=-1.5; si=-1.0; range=2.0; dr=range/300.0; di=range/300.0; } public void run() { doing=true; draw_screen(); doing=false; } public void draw_screen() { /* グラフ描画 */ int i,j,k,n; double rlr[]=new double[8]; double imr[]=new double[8]; double znr,zni,znr2,zni2,cr,ci; dr=range/300.0; di=range/300.0; for (i=0;i<300;i++) for (j=0;j<300;j++) sn[j][i]=0; for (i=0;i<300;i++) { for (j=0;j<300;j++) { znr=0; /* 実数部初期値 */ zni=0; /* 虚数部係数初期値 */ cr=sr+dr*j; /* Cの実数部 */ ci=si+di*i; /* Cの虚数部係数 */ n=1; do { /* マンデルブロ集合判定 */ znr2=(znr*znr)-(zni*zni)+cr; zni2=(znr*zni)*2.0+ci; znr=znr2; zni=zni2; if (n>=max-8) { rlr[n-(max-8)]=znr; imr[n-(max-8)]=zni; } n++; } while (n299 ||y<0 ||y>299) return false; nl.setText(String.valueOf(sn[x][y])); rf.setText(String.valueOf(sr+x*dr)); imf.setText(String.valueOf(si+(299-y)*di)); return true; } public boolean mouseDown(Event evt,int x,int y) { double wr,wi; x-=8; y-=8; if (x<0 ||x>299 ||y<0 ||y>299) return false; wr=sr+(range/300.0)*x; wi=si+(range/300.0)*(299-y); range=range/2.0; sr=wr-range/2.0; si=wi-range/2.0; if (doing) { go=false; while(doing); } startDraw(); return true; } public void paint(Graphics g){ g.drawImage(screen,8,8,this); } public void update(Graphics g){ paint(g); } }