bead function
void
bead(])
A droplet at (x, y) moving at (vx, vy) px/s: s 1 is a pixel, 2 a shaded 2x2,
3 a round bead with a highlight; a tail trails back along its motion, longer the faster it goes.
Implementation
void bead(
Painter p,
double x,
double y,
double vx,
double vy,
int s,
List<int> c, [
double a = 1.0,
]) {
final spRaw = hypot(vx, vy);
final sp = spRaw == 0.0 ? 1.0 : spRaw;
final ux = vx / sp;
final uy = vy / sp;
final tail = math.min(5.0, sp * 0.011);
if (tail >= 1.0) {
p.lineShaded(
x - ux * (tail + 1.0),
y - uy * (tail + 1.0),
x - ux * 1.2,
y - uy * 1.2,
color: (u) => u < 0.45 ? c[3] : (s > 1 ? c[5] : c[4]),
alpha: (_) => a,
);
}
if (s >= 3) {
p.circle(x, y, 1.75, c[4], a);
p.circle(x - 0.25, y - 0.25, 1.15, c[6], a);
p.dot(x - 0.7, y - 0.7, kWhite, a);
} else if (s >= 2) {
final xi = x.floor();
final yi = y.floor();
p.dot(xi, yi, kWhite, a);
p.dot(xi + 1, yi, c[6], a);
p.dot(xi, yi + 1, c[5], a);
p.dot(xi + 1, yi + 1, c[4], a);
} else {
p.dot(x, y, sp > 160.0 ? c[6] : c[5], a);
}
}