Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package d;
- public class test {
- public test() {
- public void run() {
- for( int y = 0; y < hei; y++ ) {
- for( int x = 0; x < wid; x++ ) {
- Thread thread = new Thread(new Runnable() {
- @Override
- public void run() {
- while(true){
- delay = (int) ( ( random.nextDouble() + 0.5 ) * k );
- probability = random.nextDouble();
- if(probability <= p) //random color
- {
- board[x][y].setBackground( new Color( random.nextInt(256),
- random.nextInt(256),
- random.nextInt(256) ));
- }
- else //neighbors color
- {
- try{ redL = ((board[x-1][y].getBackground()).getRed()); } catch( ArrayIndexOutOfBoundsException e ) { redL = 0; }
- try{ redR = ((board[x+1][y].getBackground()).getRed()); } catch( ArrayIndexOutOfBoundsException e ) { redR = 0; }
- try{ redU = ((board[x][y+1].getBackground()).getRed()); } catch( ArrayIndexOutOfBoundsException e ) { redU = 0; }
- try{ redD = ((board[x][y-1].getBackground()).getRed()); } catch( ArrayIndexOutOfBoundsException e ) { redD = 0; }
- R = (int) ( (redL + redR + redU + redD) / 4 );
- try{ greenL = ((board[x-1][y].getBackground()).getGreen()); } catch( ArrayIndexOutOfBoundsException e ) { greenL = 0; }
- try{ greenR = ((board[x+1][y].getBackground()).getGreen()); } catch( ArrayIndexOutOfBoundsException e ) { greenR = 0; }
- try{ greenU = ((board[x][y+1].getBackground()).getGreen()); } catch( ArrayIndexOutOfBoundsException e ) { greenU = 0; }
- try{ greenD = ((board[x][y-1].getBackground()).getGreen()); } catch( ArrayIndexOutOfBoundsException e ) { greenD = 0; }
- G = (int) ( (greenL + greenR + greenU + greenD) / 4 );
- try{ blueL = ((board[x-1][y].getBackground()).getBlue()); } catch( ArrayIndexOutOfBoundsException e ) { blueL = 0; }
- try{ blueR = ((board[x+1][y].getBackground()).getBlue()); } catch( ArrayIndexOutOfBoundsException e ) { blueR = 0; }
- try{ blueU = ((board[x][y+1].getBackground()).getBlue()); } catch( ArrayIndexOutOfBoundsException e ) { blueU = 0; }
- try{ blueD = ((board[x][y-1].getBackground()).getBlue()); } catch( ArrayIndexOutOfBoundsException e ) { blueD = 0; }
- B = (int) ( (blueL + blueR + blueU + blueD) / 4 );
- board[x][y].setBackground( new Color(R,G,B) );
- }
- sleep(delay);
- }
- }
- });
- thread.start();
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement