draw method

void draw(
  1. Canvas canvas,
  2. Paint paint,
  3. Size size
)

Implementation

void draw(Canvas canvas, Paint paint, Size size) {
	final double cX = size.width;
	final double cY = size.height;

	paint.shader = Utils.createShader(cX, cY, _colors, angle: _angle[0]);

	_path.reset();

	if (_stub) _loadStubWaves();

	if (_animateToAmplitude != _amplitude) {
		_amplitude += _animateAmplitudeDiff * 16;
		if (_animateAmplitudeDiff > 0) {
			if (_amplitude > _animateToAmplitude) {
				_amplitude = _animateToAmplitude;
			}
		} else {
			if (_amplitude < _animateToAmplitude) {
				_amplitude = _animateToAmplitude;
			}
		}
	}

	_update(_amplitude, _stub ? 0.1 : 0.8);

	for (int i = 0; i < N; i++) {
		List<Vector4> pointStart = [];
		List<Vector4> pointEnd = [];

		double progress = _progress[i];
		int nextIndex = i + 1 < N ? i + 1 : 0;
		double progressNext = _progress[nextIndex];
		double r1 = _radius[i] * (1.0 - progress) + _radiusNext[i] * progress;
		double r2 = _radius[nextIndex] * (1.0 - progressNext) +
				_radiusNext[nextIndex] * progressNext;
		double angle1 = _angle[i] * (1.0 - progress) + _angleNext[i] * progress;
		double angle2 = _angle[nextIndex] * (1 - progressNext) +
				_angleNext[nextIndex] * progressNext;

		double l = L * (min(r1, r2) + (max(r1, r2) - min(r1, r2)) / 2.0);

		pointStart.add(Utils.transformPoint(Vector4(cX, cY - r1, 0.0, 1.0), cX, cY, angle1));
		pointStart.add(Utils.transformPoint(Vector4(cX + l, cY - r1, 0.0, 1.0), cX, cY, angle1));

		pointEnd.add(Utils.transformPoint(Vector4(cX, cY - r2, 0.0, 1.0), cX, cY, angle2));
		pointEnd.add(Utils.transformPoint(Vector4(cX - l, cY - r2, 0.0, 1.0), cX, cY, angle2));

		if (i == 0) {
			_path.moveTo(pointStart[0].x, pointStart[0].y);
		}

		_path.cubicTo(
			pointStart[1].x,
			pointStart[1].y,
			pointEnd[1].x,
			pointEnd[1].y,
			pointEnd[0].x,
			pointEnd[0].y,
		);
	}

	canvas.save();
	canvas.translate(cX, cY);
	canvas.scale(_autoScale ? _findWaveScale() : _scale);
	canvas.translate(-cX, -cY);
	canvas.drawPath(_path, paint);
	canvas.restore();
}