unlight function

void unlight(
  1. Painter p,
  2. num x0,
  3. num y0,
  4. num x1,
  5. num y1,
  6. bool dark(
    1. double x,
    2. double y
    ), [
  7. double keep = 0,
])

Take the light back off every pixel in a local box where dark is true, keeping a share keep (0..1): call it last, so black shapes stay black under every glow, spark and ring drawn before.

Implementation

void unlight(
  Painter p,
  num x0,
  num y0,
  num x1,
  num y1,
  bool Function(double x, double y) dark, [
  double keep = 0,
]) {
  final lBuf = p.frame.light;
  final w = p.w;
  final ox = p.ox;
  final oy = p.oy;
  p.each(x0.toDouble(), y0.toDouble(), x1.toDouble(), y1.toDouble(), (x, y, sx, sy) {
    if (!dark(x, y)) return;
    final i = (sy - oy) * w + (sx - ox);
    final d = lBuf[i];
    if (d == 0) return;
    if (keep <= 0) {
      lBuf[i] = 0;
    } else {
      final r = (((d >> 16) & 255) * keep).toInt();
      final g = (((d >> 8) & 255) * keep).toInt();
      final b = ((d & 255) * keep).toInt();
      lBuf[i] = (255 << 24) | (r << 16) | (g << 8) | b;
    }
  });
}