floorRing function

void floorRing(
  1. Painter p,
  2. double cx,
  3. double cy,
  4. double r,
  5. double sy,
  6. int color(
    1. double ang
    ), [
  7. double alpha(
    1. double ang
    )?,
  8. bool keep(
    1. double ang
    )?,
])

Implementation

void floorRing(
  Painter p,
  double cx,
  double cy,
  double r,
  double sy,
  int Function(double ang) color, [
  double Function(double ang)? alpha,
  bool Function(double ang)? keep,
]) {
  if (r < 0.5) return;
  final ry = r * sy;
  final rySafe = math.max(0.3, ry);
  p.shade(cx - r - 1, cy - ry - 1, cx + r + 1, cy + ry + 1, (x, y, o) {
    final nx = (x - cx) / r;
    final ny = (y - cy) / rySafe;
    final d = hypot(nx, ny);
    if (d < 1e-6) return null;
    final g = hypot(nx / r, ny / rySafe) / d;
    if ((d - 1.0).abs() / g > 0.5) return null;
    final ang = math.atan2(ny, nx);
    if (keep != null && !keep(ang)) return null;
    o.c = color(ang);
    o.a = alpha != null ? alpha(ang) : 1.0;
    return null;
  });
}