protected boolean place ( final Word word , final Point start ) { final Graphics graphics = this . bufferedImage . getGraphics ( ) ; final int maxRadius = computeRadius ( dimension , start ) ; final Point position = word . getPosition ( ) ; for ( int r = 0 ; r < maxRadius ; r += 2 ) { for ( int x = Math . max ( - start . x , - r ) ; x <= Math . min ( r , dimension . width - start . x - 1 ) ; x ++ ) { position . x = start . x + x ; final int offset = ( int ) Math . sqrt ( r * r - x * x ) ; // try positive root position . y = start . y + offset ; if ( position . y >= 0 && position . y < dimension . height && canPlace ( word ) ) { collisionRaster . mask ( word . getCollisionRaster ( ) , position ) ; graphics . drawImage ( word . getBufferedImage ( ) , position . x , position . y , null ) ; return true ; } // try negative root (if offset != 0) position . y = start . y - offset ; if ( offset != 0 && position . y >= 0 && position . y < dimension . height && canPlace ( word ) ) { collisionRaster . mask ( word . getCollisionRaster ( ) , position ) ; graphics . drawImage ( word . getBufferedImage ( ) , position . x , position . y , null ) ; return true ; } } } return false ; }
try to place in center build out in a spiral trying to place words for N steps