drawFractures function

void drawFractures(
  1. Painter p,
  2. List<List<(double, double, double)>> cracks,
  3. double reach,
  4. List<int> c, {
  5. double ox = 0.0,
  6. double oy = 0.0,
  7. bool hot = true,
  8. double a = 1.0,
})

Draw cracks grown out to distance reach from their start.

Implementation

void drawFractures(
  Painter p,
  List<List<(double x, double y, double d)>> cracks,
  double reach,
  List<int> c, {
  double ox = 0.0,
  double oy = 0.0,
  bool hot = true,
  double a = 1.0,
}) {
  final n = c.length;
  ({double x0, double y0, double x1, double y1, bool tip})? segOf(
    List<(double x, double y, double d)> pts,
    int i,
  ) {
    final (x0, y0, d0) = pts[i - 1];
    final (x1, y1, d1) = pts[i];
    if (d0 >= reach) return null;
    final u = math.min(1.0, (reach - d0) / math.max(0.01, d1 - d0));
    return (
      x0: x0 + ox,
      y0: y0 + oy,
      x1: x0 + ox + (x1 - x0) * u,
      y1: y0 + oy + (y1 - y0) * u,
      tip: reach - d1 < 3.0,
    );
  }

  for (final pts in cracks) {
    for (var i = 1; i < pts.length; i++) {
      final s = segOf(pts, i);
      if (s == null) break;
      p.line(s.x0, s.y0 + 1, s.x1, s.y1 + 1, c[math.min(2, n - 1)], a);
    }
  }
  for (final pts in cracks) {
    for (var i = 1; i < pts.length; i++) {
      final s = segOf(pts, i);
      if (s == null) break;
      final tip = hot && s.tip;
      p.line(s.x0, s.y0, s.x1, s.y1, tip ? kWhite : c[n - 2], a);
      if (tip) {
        p.glow(s.x1, s.y1, 5, c[n - 3], 0.5 * a);
      } else if (i.isOdd) {
        p.glow(s.x1, s.y1, 3, c[n - 3], 0.18 * a);
      }
    }
  }
}