// ------------------------------------------------ // 映画「マト○ックス」っぽい表示をするアニメ // // ------------------------------------------------ import java.applet.*; import java.awt.*; import java.lang.*; public class MatrixLike extends Applet implements Runnable { // グローバル変数 Thread thread = null; int th_counter; int th_state; int fall_counter; int th_sleep; Image backimage; // ダブルバッファリング用 Graphics bg; String bin_str; // bin_disの元となる0と1の羅列 String bin_dis[]; // 画面に表示される数字(0 or 1) int bin_pos[]; // bin_disのbin_str上の位置 int bin_x[]; // bin_disの画面表示x座標 int bin_yy[]; String ent_str; // ent_disの元となる文字列 String ent_dis[]; // bin_disが崩れた後表示される文字 int ent_pos; // ent_strの何文字目かを記録 int ent_line; // 何行目かを記録 int rect_size; // 四角形の大きさを保存 int cv; int ct; // 汎用カウンター String title_str; // HPのタイトル public void init() { // 変数初期化 th_counter =0; th_state = 0; fall_counter = 0; th_sleep = 100; backimage = createImage( 480, 640); bg = backimage.getGraphics(); bin_dis = new String[21]; bin_pos = new int[21]; bin_x = new int[21]; bin_yy = new int[80]; // @で改行 [で行末まで一気に表示 `で終了 ent_str = "#type matrix open 231.115.39.80@"; ent_str +="[Now Connecting...@"; ent_str +="[Connection is established. OK.@"; ent_str +="[Server is running Matrix/1.9.99(United)@"; ent_str +="@"; ent_str +="join: type-matrix@"; ent_str +="password: ********@"; ent_str +="Please wait...`"; ent_dis = new String[8]; for(int i=0; i<8; i++) ent_dis[i] = ""; ent_pos = 0; ent_line = 0; rect_size = 1; cv = 255; ct = 0; title_str = getParameter("title_string"); int rd = 0; bin_str = "0"; for(int i=0; i<400; i++) { rd = (int)(2 * Math.random()); bin_str += String.valueOf(rd); } for(int i=0; i<21; i++) { bin_pos[i] = (int)(220 * Math.random()) + 100; bin_dis[i] = bin_str.substring( bin_pos[i], bin_pos[i]+80); bin_x[i] = 0; } for(int i=0; i<80; i++) bin_yy[i] = 0; start_title(); repaint(); } // init() public void paint(Graphics g) { g.drawImage( backimage, 0, 0, null); } public void update(Graphics g) { paint( g ); } // update() public void start() { if (thread==null) { thread = new Thread(this); thread.start(); } } // start() public void stop() { thread = null; } // stop() public void run() { while (thread!=null) { switch( th_state ) { case 0: for(int i=0; i<20; i++) { bin_pos[i]--; bin_dis[i] = bin_str.substring( bin_pos[i], bin_pos[i]+80); } draw_bin_dis(); break; case 1: if(th_counter%10 == 5) { draw_bin_dis(); bg.setColor(Color.red); bg.setFont(new Font("DIALOG", Font.BOLD, 30)); bg.drawString("ERROR!", 190, 150); } if(th_counter%10 == 0) { draw_bin_dis(); } break; case 2: fall_string(0, fall_counter); fall_string(18,fall_counter); fall_string(36, fall_counter); fall_string(54,fall_counter); fall_counter++; break; case 3: th_sleep = 100; String s= ent_str.substring(ent_pos, ent_pos+1); if (s.equals("@")) { ent_line++; th_sleep=200; }else if(s.equals("[")){ int endl = ent_str.indexOf("@", ent_pos); ent_dis[ent_line] = ent_str.substring(ent_pos+1, endl); ent_pos = --endl; th_sleep = 400; }else if(s.equals("`")){ th_state = 4; th_counter=300; break; }else { ent_dis[ent_line] += s; } bg.setColor(Color.black); bg.fillRect( 0, ent_line*16, 480, 320); bg.setColor(Color.green); bg.drawString(ent_dis[ent_line] + "_", 2, ent_line*16+16); ent_pos++; break; case 4: bg.setColor(Color.white); bg.fillRect( 240-(int)(rect_size*3/2), 160-rect_size, rect_size*3, rect_size*2); rect_size+=2; break; case 5: bg.setColor(Color.white); bg.fillRect( 240-(int)(rect_size*3/2), 160-rect_size, rect_size*3, rect_size*2); rect_size+=10; break; case 6: bg.setFont(new Font("Serif",Font.PLAIN,30)); bg.setColor(Color.gray); bg.drawString("Welcome", 150, 71); bg.drawString("Welcome", 151, 70); bg.setColor(new Color(cv,cv,cv)); bg.drawString("Welcome", 150, 70); cv -= 5; break; case 7: bg.setColor(Color.gray); bg.drawString("to", 290, 171); bg.drawString("to", 291, 170); bg.setColor(new Color(cv,cv,cv)); bg.drawString("to", 290, 170); cv -= 5; break; case 8: bg.setColor(Color.gray); bg.drawString("My Homepage", 90, 271); bg.drawString("My Homepage", 91, 270); bg.setColor(new Color(cv,cv,cv)); bg.drawString("My Homepage", 90, 270); cv -= 5; break; case 9: // "Welcome" (150,70) to (50, 170) // "to" (290,170) to (190,170) // "My Homepage" (90,270) to (240,170) bg.setColor(Color.white); bg.fillRect( 0, 0, 480, 320); bg.setColor(new Color(cv,cv,cv)); bg.drawString("Welcome", 150-ct*2, 70+ct*2); bg.drawString("to", 290-ct*2, 170); bg.drawString("My Homepage", 90+ct*3, 270-ct*2); ct++; break; case 10: // 画面を黒に bg.setColor(new Color(ct,ct,ct)); bg.fillRect( 0, 0, 480, 320); bg.setColor(new Color(cv,cv,cv)); bg.drawString("Welcome", 50, 170); bg.drawString("to", 190, 170); bg.drawString("My Homepage", 240, 170); ct-=17; cv-=17; if(cv<255) cv=0; break; case 11: bg.setColor(new Color(cv,cv,cv)); bg.drawString("Thank you for your visiting.", 50, 170); cv+=17; break; case 12: // wait break; case 13: bg.setColor(new Color(cv,cv,cv)); bg.drawString("Thank you for your visiting.", 50, 170); cv-=17; break; default: break; } repaint(); try { // スレッド一時停止 thread.sleep(th_sleep); } catch (InterruptedException e) { } th_counter++; if (th_counter == 50) th_state=1; if (th_counter == 80) th_state=2; if (th_counter == 120){ th_state=3; bg.setFont(new Font("DIALOG", Font.PLAIN, 12)); } if (th_counter == 300) th_state=4; if (th_counter == 310){ th_state=5; th_sleep=30; } if (th_counter == 335) th_state=99; if (th_counter == 345){ th_state=6; th_sleep=100; } if (th_counter == 355){ th_state=7; cv = 255; } if (th_counter == 365){ th_state=8; cv = 255; } if (th_counter == 375){ th_state=9; th_sleep=30; ct=0; } if (th_counter == 425){ th_state=10; th_sleep=100; ct = 238; } if (th_counter == 440){ th_state=11; cv = 0; } if (th_counter == 455) th_state=12; if (th_counter == 465) th_state=13; if (th_counter == 480) th_state=99; // 実際には処理せずwait if (th_counter == 490) { thread = null; start_title(); repaint(); } } } public void draw_bin_dis() { // 変数bin_disの内容を画面に表示 bg.setColor(Color.black); bg.fillRect( 0, 0, 488, 320); bg.setColor(Color.green); bg.setFont(new Font("Courier", Font.PLAIN, 12)); for(int i=0; i<20; i++) { bg.drawString(bin_dis[i], bin_x[i], i*16+12); } } // draw_bin_dis() public void fall_string(int k, int n) { // k列からn列分の縦列を1段下げる(実際にはコピーしてずらす) bg.setColor(Color.black); // 退避 bg.fillRect( 0, 320, 480, 320); bg.copyArea( k*7, 0, n*7+7, 320, 0, 320); bg.fillRect( k*7, 0, n*7+7, 320); // 黒で消去 // 退避されていた画像をy方向に+16して戻す bg.copyArea( k*7, 320, n*7+7, 320, 0, -304); bin_yy[n]++; } // fall_string() public void start_title() { // 初期画面 bg.setColor(Color.black); bg.fillRect( 0, 0, 480, 320); bg.setColor(Color.gray); bg.setFont(new Font("DIALOG", Font.BOLD, 30)); bg.drawString("Fin", 100, 100); bg.setColor(Color.yellow); bg.setFont(new Font("DIALOG", Font.ITALIC, 12)); bg.drawString("Presented by wakyou", 300, 300); } // start_title() } // End