drawPetal method

void drawPetal(
  1. Canvas canvas,
  2. double cubicControlPointAngle,
  3. double currentRotateAngleInRad,
  4. int petalNumber,
  5. double scaleFactor,
  6. Paint paint,
)

Implementation

void drawPetal(
    Canvas canvas,
    double cubicControlPointAngle,
    double currentRotateAngleInRad,
    int petalNumber,
    double scaleFactor,
    Paint paint) {
  double outerRadius = petalOuterRadius * scaleFactor;
  double innerRadius = petalInnerRadius * scaleFactor;
  flowerPath.reset();

  flowerPath.moveTo(canvasCx, canvasCy);
  flowerPath.relativeLineTo(outerRadius, 0);
  flowerPath.relativeCubicTo(
    outerRadius * (math.cos(cubicControlPointAngle) - 1),
    outerRadius * math.sin(cubicControlPointAngle),
    outerRadius * (math.cos(2 * cubicControlPointAngle) - 1),
    outerRadius * math.sin(2 * cubicControlPointAngle),
    -outerRadius + innerRadius * math.cos(currentRotateAngleInRad),
    innerRadius * math.sin(currentRotateAngleInRad),
  );
  flowerPath.lineTo(canvasCx, canvasCy);

  canvas.save();
  canvas.translate(canvasCx, canvasCy);
  canvas.rotate(
      (petalNumber * rotateAngle - initialRotateOffset) * DEGREE_IN_RAD);
  canvas.translate(-canvasCx, -canvasCy);
  canvas.drawPath(flowerPath, paint);
  canvas.restore();
}