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 542The following class provides a reasonably efficient simulation of DLA. Walkers begin justoutside a circle of radius startRadius enclosing the existing cluster and centered at the seed site.If the walker moves away from the cluster, the step size for the random walker increases. If thewalker wonders too far away (further than maxRadius), the walk is restarted.Listing 14.5: Class for simulating diffusion limited aggregation.package org . o p e n s o u r c e p h y s i c s . s i p . ch<strong>13</strong> ;import org . o p e n s o u r c e p h y s i c s . c o n t r o l s . * ;import org . o p e n s o u r c e p h y s i c s . frames . LatticeFrame ;import java . awt . Color ;public class DLAApp extends AbstractSimulation {LatticeFrame l a t t i c e F r a m e = new LatticeFrame ( "DLA" ) ;byte s [ ] [ ] ; // l a t t i c e on which c l u s t e r l i v e sint xOccupied [ ] , yOccupied [ ] ; // l o c a t i o n o f occupied s i t e sint L ; // l i n e a r dimension o f l a t t i c eint h a l f L ; // L/2int r i n g S i z e ; // r i n g s i z e in which w a l k e r s can moveint numberOfParticles ; // number o f p a r t i c l e s in c l u s t e rint s t a r t R a d i u s ; // r a d i u s o f c l u s t e r at which w a l k e r s are s t a r t e dint maxRadius ; // maximum r a d i u s walker can go to b e f o r e a new walk i s s t a rpublic void i n i t i a l i z e ( ) {l a t t i c e F r a m e . setMessage ( null ) ;numberOfParticles = 1 ;L = c o n t r o l . g e t I n t ( " lattice size" ) ;s t a r t R a d i u s = 3 ;h a l f L = L/2;r i n g S i z e = L/ 1 0 ;maxRadius = s t a r t R a d i u s+r i n g S i z e ;s = new byte [ L ] [ L ] ;s [ h a l f L ] [ h a l f L ] = Byte .MAX VALUE;l a t t i c e F r a m e . s e t A l l ( s ) ;}public void r e s e t ( ) {l a t t i c e F r a m e . setIndexedColor ( 0 , Color .BLACK) ;c o n t r o l . setValue ( " lattice size" , 3 0 0 ) ;s e t S t e p s P e r D i s p l a y ( 1 0 0 ) ;enableStepsPerDisplay ( true ) ;i n i t i a l i z e ( ) ;}public void stopRunning ( ) {c o n t r o l . p r i n t l n ( "Number of particles = "+numberOfParticles ) ;// add code to compute t h e mass d i s t r i b u t i o n here}public void doStep ( ) {int x = 0 , y = 0 ;

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

Saved successfully!

Ooh no, something went wrong!