User Tools

Site Tools


solution_of_16._regeneration_around_the_mothers

The Capsis training online

Back to the table of contents

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

Elements of code to be reused in regenerationAroundMothers() Scene at date 10 with regenerationMax = 10

Back to the table of contents

solution_of_16._regeneration_around_the_mothers.txt · Last modified: 2021/12/13 09:28 by 127.0.0.1