dustRing function
void
dustRing(})
A soft, lumpy ring of dust round (cx, cy): radius r, w thick (lumps swell it), alpha k, translucent and lit on its upper side.
Implementation
void dustRing(
Painter p,
double cx,
double cy,
double r,
double w,
double k,
int c, {
double sy = 1.0,
double ph = 0.0,
double brk = 0.0,
double lit = 0.35,
double maxY = double.infinity,
int half = 0,
}) {
if (k <= 0.01 || r <= 0.0) return;
final W = w * 1.6;
final lite = mix(c, kWhite, lit);
final yEnd = math.min(maxY - 1.0, (cy + (r + W) * sy).ceilToDouble()).toInt();
for (var y = (cy - (r + W) * sy).floor() - 1; y <= yEnd; y++) {
for (var x = (cx - r - W).floor() - 1; x <= (cx + r + W).ceil() + 1; x++) {
final dx = x + 0.5 - cx;
final dy = (y + 0.5 - cy) / sy;
final d = hypot(dx, dy);
final g = math.atan2(dy, dx);
if ((half < 0 && dy >= 0.0) || (half > 0 && dy < 0.0)) continue;
final lumpy = 0.6 +
0.3 * math.sin(5.0 * g + ph) +
0.18 * math.sin(11.0 * g + ph * 2.1) +
0.12 * math.sin(17.0 * g + ph * 0.7);
final wt = w * lumpy;
final off = (d - r - w * 0.25 * math.sin(7.0 * g + ph)).abs();
if (off >= wt) continue;
final tear = brk > 0.0
? clamp((0.55 + 0.45 * math.sin(6.0 * g + ph * 1.7) - brk) / 0.25)
: 1.0;
final a = k * (1.0 - math.pow(off / wt, 2)) * tear;
if (a > 0.01) {
p.blend(x, y, dy < 0.0 && d > r - wt * 0.3 ? lite : c, a);
}
}
}
}