The Capsis training online

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**

solution_of_16._regeneration_around_the_mothers.txt Â· Last modified: 2021/02/02 16:34 by coligny

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Noncommercial-Share Alike 3.0 Unported