AMAPstudio

### Sidebar

The Capsis training online

# Solution: 16. Regeneration around the mothers

Try to work with the helping elements before looking at the solutionâ€¦

Helping elements

• we work in TraModel
• make a new method regenerationAroundMothers(TraScene newScene) and call it instead of regeneration()
• loop on the trees, like in processEvolution () for the growth
• consider only tree with getAge () > 20
• calculate double maxDistance = mother.getHeight () / 2d;
• you can get the mother's coordinates with something like this: x0 = mother.getX ()
• for each new tree, distance to mother can be calculated like this: distance = random.nextDouble () * maxDistance;
• find an alpha angle (radians) around the mother: alpha = random.nextDouble () * 2 * Math.PI;
• calculate x and y according to distance and alpha: x = x0 + Math.cos (alpha) * distance; (same for y with sin())
• create the tree (like in the original regeneration () method) and add it in the scene

A possible solution