lace function

void lace(
  1. Painter p,
  2. double cx,
  3. double cy,
  4. double rx,
  5. double ry,
  6. double k,
  7. List<int> c,
  8. double t, [
  9. int seed = 0,
])

Lacy foam floating on the surface around (cx, cy).

Implementation

void lace(
  Painter p,
  double cx,
  double cy,
  double rx,
  double ry,
  double k,
  List<int> c,
  double t, [
  int seed = 0,
]) {
  if (k <= 0.01 || rx < 1.0) return;
  final sy = ry / rx;
  p.shade(cx - rx, cy - ry, cx + rx, cy + ry, (x, y, _) {
    final dx = (x - cx) / rx;
    final dy = (y - cy) / ry;
    final d = dx * dx + dy * dy;
    if (d > 1.0) return null;
    final u = (x - cx) * 0.36;
    final v = ((y - cy) / sy) * 0.36;
    final n = noise2(u + seed * 7.13, v - t * 0.35, seed);
    final m = noise2(u * 2.2 - t * 0.3, v * 2.2 + seed * 3.1, seed + 9);
    final net = 1.0 - n.abs() * 4.6 + m * 0.3;
    final need = 1.02 - k * (1.15 - d * 0.9);
    if (net < need) return null;
    return net > need + 0.4 ? kWhite : c[6];
  });
}