Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- new Thread()
- {
- public void run()
- {
- int R,redL,redR,redU,redD;
- int G,greenL,greenR,greenU,greenD;
- int B,blueL,blueR,blueU,blueD;
- double probability;
- int delay;
- Thread thread = new Thread();
- {
- while(true){
- synchronized(board)
- {
- try
- {
- for( int y = 0; y < hei; y++ )
- {
- for( int x = 0; x < wid; x++ )
- {
- 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);
- }
- }
- } catch( InterruptedException e ){};
- Thread.yield();
- }
- }
- }thread.start();
- }
- }.start();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement