splash function

void splash(
  1. Painter q,
  2. double x,
  3. double z,
  4. double age,
  5. double size,
  6. ({int cool, int hot}) c,
  7. double h,
)

Raindrop splash on the floor, age seconds after landing at (x, z).

Implementation

void splash(
  Painter q,
  double x,
  double z,
  double age,
  double size,
  ({int hot, int cool}) c,
  double h,
) {
  final l = 0.3 + 0.12 * size;
  final u = age / l;
  if (u >= 1.0) return;
  if (age < 0.07) {
    q.px(x, z - 1.0, c.hot);
    if (size > 0.3) {
      final dy = age > 0.035 ? 1.0 : 0.0;
      q.px(x - 1.0, z - 1.0 - dy, c.hot);
      q.px(x + 1.0, z - 1.0 - dy, c.hot);
    }
    if (size > 0.65 && age > 0.03) {
      q.px(x - 2.0, z - 2.0, c.cool);
      q.px(x + 2.0, z - 2.0, c.cool);
    }
  }
  final rx = 1.0 + (1.2 + 3.6 * size) * math.sqrt(u);
  final ry = math.max(0.5, rx * 0.26);
  final n = (rx * 6.5).ceil();
  for (var j = 0; j < n; j++) {
    final a = (j / n) * tau;
    final s = math.sin(a);
    if (s < -0.25) continue;
    q.dot(
      x + math.cos(a) * rx,
      z + s * ry,
      u < 0.3 && s > 0.0 ? c.hot : c.cool,
      u < 0.45 ? (s > 0.2 ? 1.0 : 0.7) : (1.0 - u) * 1.6 * (s > 0.2 ? 1.0 : 0.6),
    );
  }
  final nd = size > 0.55 ? 3 : 2;
  final hi = (h * 1e6).floor();
  for (var d = 0; d < nd; d++) {
    final vx = (rand(hi, d, 1) - 0.5) * 2.0 * (25.0 + 35.0 * size);
    final vy = -(55.0 + rand(hi, d, 2) * 70.0 * (0.5 + size));
    final y = z - 1.0 + vy * age + 475.0 * age * age;
    if (y > z - 0.5 || age > 0.34) continue;
    final xx = x + vx * age;
    q.px(xx, y, age < 0.12 ? c.hot : c.cool);
    if (vy + 950.0 * age < -40.0) {
      q.dot(xx - vx * 0.012, y + 1.0, c.cool, 0.7);
    }
  }
}