12.07.2015 Views

Chapter 13 - Davidson Physics

Chapter 13 - Davidson Physics

Chapter 13 - Davidson Physics

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CHAPTER 14. FRACTALS AND KINETIC GROWTH MODELS 543}i f ( startRadius =h a l f L ) { // s t o p t h e s i m u l a t i o nc o n t r o l . c a l c u l a t i o n D o n e ( "Done" ) ;l a t t i c e F r a m e . setMessage ( "Done" ) ;}l a t t i c e F r a m e . setMessage ( "n = "+numberOfParticles ) ;public boolean walk ( int x , int y ) {do {double rSquared = ( x−halfL ) * ( x−h a l f L )+(y−h a l f L ) * ( y−h a l f L ) ;int r = 1+( int ) Math . s q r t ( rSquared ) ;i f ( r>maxRadius ) {return true ; // s t a r t new walker}i f ( ( r0)) {numberOfParticles++;s [ x ] [ y ] = 1 ;l a t t i c e F r a m e . setValue ( x , y , Byte .MAX VALUE) ;i f ( r>=s t a r t R a d i u s ) {s t a r t R a d i u s = r +2;}maxRadius = s t a r t R a d i u s+r i n g S i z e ;return f a l s e ; // walk i s f i n i s h e d} else { // t a k e a s t e pswitch ( ( int ) (4*Math . random ( ) ) ) { // s e l e c t d i r e c t i o n randomlycase 0 :x++;break ;case 1 :x−−;break ;case 2 :y++;break ;case 3 :y−−;}} // end e l s e i f} while ( true ) ; // end do l o o p}public s t a t i c void main ( S t r i n g [ ] a r g s ) {

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!