/* */ import java.awt.*; import java.applet.Applet; public class LineArt extends Applet implements Runnable { Graphics off_g; Image off; Thread th; int w, h; int line_num; int x[] = new int[2]; int y[] = new int[2]; int lim_x[] = new int[2]; int lim_y[] = new int[2]; Line line[] = new Line[100]; Color color[][][] = new Color[33][33][33]; int color_r, color_g, color_b; int color_speed; int color_prog; int color_mode; /*********init********/ public void init(){ w = getSize().width; h = getSize().height; off = createImage(w,h); off_g = off.getGraphics(); th = null; line_num = 100; for (int i = 0; i < 2; i ++){ x[i] = (int)(Math.random()*(w-1)); y[i] = (int)(Math.random()*(h-1)); } lim_x[0] = lim_y[0] = 10; lim_x[1] = lim_y[1] = 5; for (int i = 0; i < line_num; i++) line[i] = new Line(); for (int r = 0; r < 33; r++){ for (int g = 0; g < 33; g++){ for (int b = 0; b < 33; b++){ color[r][g][b] = new Color(r>0?(r*8)-1:0, g>0?(g*8)-1:0, b>0?(b*8)-1:0); } } } color_r = color_g = color_b = 8; color_speed = 0; color_prog = 0; color_mode = 0; } /*********start*******/ public void start(){ if (th == null){ th = new Thread(this); th.start(); } } /*********run********/ public void run() { while (th != null){ repaint(); try{ Thread.sleep(50); } catch (InterruptedException e){} } } /********paint*******/ public void paint(Graphics g){ off_g.setColor(Color.white); off_g.fillRect(0,0,w,h); set_Color(); drawLine(); g.drawImage(off,0,0,this); } /********set_Color********/ public void set_Color(){ if (color_prog >= 33) color_prog = 0; else color_prog++; if (color_prog == 0){ color_mode = (int)(Math.random()*3); color_prog = 1; } if (color_speed == 0){ switch (color_mode){ case 0: color_r = changeColor(color_r); break; case 1: color_r = changeColor(color_r); color_g = changeColor(color_g); break; case 2: color_r = changeColor(color_r); color_g = changeColor(color_g); color_b = changeColor(color_b); break; } } color_speed++; if (color_speed >= 3) color_speed = 0; off_g.setColor(color[convert_Color(color_r)] [convert_Color(color_g)] [convert_Color(color_b)]); } /*****convert_Color******/ public int convert_Color(int i){ if (i >= 33) return 64-i; else return i; } /********changeColor********/ public int changeColor(int c){ if (c >= 64) c = 0; else c++; return c; } /*******drawLine******/ public void drawLine(){ line[0].draw(x[0],y[0],x[1],y[1],off_g); for(int i = 1; i < line_num; i++){ line[i].draw(line[i-1].getold_x1(),line[i-1].getold_y1(), line[i-1].getold_x2(),line[i-1].getold_y2(),off_g); } for (int i = 0; i < line_num; i++) line[i].set_old(); for (int i = 0; i < 2; i++){ x[i] += lim_x[i]; y[i] += lim_y[i]; if (x[i] <= 0){ x[i] = 0; lim_x[i] = 2+(int)(Math.random()*10); } else if (x[i] >= w-1){ x[i] = w-1; lim_x[i] = -(2+(int)(Math.random()*10)); } if (y[i] <= 0){ y[i] = 0; lim_y[i] = 2+(int)(Math.random()*10); } else if (y[i] >= h-1){ y[i] = h-1; lim_y[i] = -(2+(int)(Math.random()*10)); } } } /*******update********/ public void update(Graphics g){ paint(g); } /*******stop********/ public void stop(){ if (th != null) th = null; } }