Advertisement
Guest User

Untitled

a guest
May 25th, 2015
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.23 KB | None | 0 0
  1. package d;
  2.  
  3. public class test {
  4.  
  5. public test() {
  6. public void run() {
  7. for( int y = 0; y < hei; y++ ) {
  8. for( int x = 0; x < wid; x++ ) {
  9. Thread thread = new Thread(new Runnable() {
  10.  
  11. @Override
  12. public void run() {
  13. while(true){
  14. delay = (int) ( ( random.nextDouble() + 0.5 ) * k );
  15. probability = random.nextDouble();
  16.  
  17. if(probability <= p) //random color
  18. {
  19. board[x][y].setBackground( new Color( random.nextInt(256),
  20. random.nextInt(256),
  21. random.nextInt(256) ));
  22. }
  23. else //neighbors color
  24. {
  25. try{ redL = ((board[x-1][y].getBackground()).getRed()); } catch( ArrayIndexOutOfBoundsException e ) { redL = 0; }
  26. try{ redR = ((board[x+1][y].getBackground()).getRed()); } catch( ArrayIndexOutOfBoundsException e ) { redR = 0; }
  27. try{ redU = ((board[x][y+1].getBackground()).getRed()); } catch( ArrayIndexOutOfBoundsException e ) { redU = 0; }
  28. try{ redD = ((board[x][y-1].getBackground()).getRed()); } catch( ArrayIndexOutOfBoundsException e ) { redD = 0; }
  29.  
  30. R = (int) ( (redL + redR + redU + redD) / 4 );
  31.  
  32. try{ greenL = ((board[x-1][y].getBackground()).getGreen()); } catch( ArrayIndexOutOfBoundsException e ) { greenL = 0; }
  33. try{ greenR = ((board[x+1][y].getBackground()).getGreen()); } catch( ArrayIndexOutOfBoundsException e ) { greenR = 0; }
  34. try{ greenU = ((board[x][y+1].getBackground()).getGreen()); } catch( ArrayIndexOutOfBoundsException e ) { greenU = 0; }
  35. try{ greenD = ((board[x][y-1].getBackground()).getGreen()); } catch( ArrayIndexOutOfBoundsException e ) { greenD = 0; }
  36.  
  37. G = (int) ( (greenL + greenR + greenU + greenD) / 4 );
  38.  
  39. try{ blueL = ((board[x-1][y].getBackground()).getBlue()); } catch( ArrayIndexOutOfBoundsException e ) { blueL = 0; }
  40. try{ blueR = ((board[x+1][y].getBackground()).getBlue()); } catch( ArrayIndexOutOfBoundsException e ) { blueR = 0; }
  41. try{ blueU = ((board[x][y+1].getBackground()).getBlue()); } catch( ArrayIndexOutOfBoundsException e ) { blueU = 0; }
  42. try{ blueD = ((board[x][y-1].getBackground()).getBlue()); } catch( ArrayIndexOutOfBoundsException e ) { blueD = 0; }
  43.  
  44. B = (int) ( (blueL + blueR + blueU + blueD) / 4 );
  45.  
  46. board[x][y].setBackground( new Color(R,G,B) );
  47. }
  48. sleep(delay);
  49. }
  50. }
  51.  
  52. });
  53. thread.start();
  54.  
  55. }
  56. }
  57. }
  58. }
  59.  
  60.  
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement