createVMobjectGradient method

CanvasGradient createVMobjectGradient(
  1. VMobject vmob,
  2. List<Color> colors
)

Implementation

CanvasGradient createVMobjectGradient(VMobject vmob, List<Color> colors) {
  var startEnd = vmob.getGradientStartAndEndPoints();
  var points =
      transformPointsPreDisplay(vmob, [startEnd.item1, startEnd.item2]);

  var gradient = ctx.createLinearGradient(
      points[0].x, points[0].y, points[1].x, points[1].y);

  var step = 1 / (colors.length - 1);

  var offsets = arange(start: 0, end: step + 1, step: step).getColumn(0);

  for (var i in range(end: colors.length)) {
    var color = display.applyColorTransformation(colors[i]);
    var offset = offsets[i];

    gradient.addColorStop(offset, color.toRGBAString());
  }

  return gradient;
}