alignColors method

void alignColors(
  1. VMobject vmob
)

Implementation

void alignColors(VMobject vmob) {
  List<Color> getAttr(String attr, VMobject vmob) {
    switch (attr) {
      case 'fillColors':
        return vmob.getFillColors();
      case 'strokeColors':
        return vmob.getStrokeColors();
      case 'backgroundStrokeColors':
        return vmob.getStrokeColors(background: false);
      default:
        throw 'No color list in VMobject with attribute name $attr';
    }
  }

  void setAttr(String attr, VMobject vmob, List<Color> value) {
    switch (attr) {
      case 'fillColors':
        vmob.fillColors = value;
        break;
      case 'strokeColors':
        vmob.strokeColors = value;
        break;
      case 'backgroundStrokeColors':
        vmob.backgroundStrokeColors = value;
        break;
      default:
        throw 'No color list in VMobject with attribute name $attr';
    }
  }

  for (var attr in ['fillColors', 'strokeColors', 'backgroundStrokeColors']) {
    var a1 = getAttr(attr, this);
    var a2 = getAttr(attr, vmob);

    if (a1.length > a2.length) {
      var newA2 = stretchListToLength(a2, a1.length);
      setAttr(attr, vmob, newA2);
    } else if (a2.length > a1.length) {
      var newA1 = stretchListToLength(a1, a2.length);
      setAttr(attr, this, newA1);
    }
  }
}