Advertisement
Guest User

Untitled

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