solution_of_16._regeneration_around_the_mothers
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 ofregeneration()
- 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 fory
withsin()
)
- 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/12/13 09:28 by 127.0.0.1