addNMoreSubmobjects method

void addNMoreSubmobjects(
  1. int n
)

Implementation

void addNMoreSubmobjects(int n) {
  if (n == 0) {
    return;
  }

  var current = length;
  if (current == 0) {
    submobjects = [for (var _ in range(end: n)) getPointMobject()];
  }

  var target = current + n;
  var repeatIndices = [
    for (var elem in range(end: target)) elem * current ~/ target
  ];
  var splitFactors = [
    for (var i in range(end: current))
      sum([
        for (var j in repeatIndices)
          if (i == j) 1 else 0
      ])
  ];

  var newSubmobs = <Mobject>[];

  for (var data in IterableZip([submobjects, splitFactors])) {
    var submob = data[0] as Mobject;
    var sf = data[1] as int;

    newSubmobs.add(submob);

    for (var _ in range(start: 1, end: sf)) {
      var copy = submob.copy();
      copy.fade(darkness: 1);
      newSubmobs.add(copy);
    }
  }

  submobjects = newSubmobs;
}