drawCracks function
void
drawCracks(])
Draw cracks grown to g(c) px of their length. heat(d) 0..1 at distance d along a crack lights it from the hot ramp (bright to dark) before it cools to dark; lip is the lit lower edge; k dithers them out.
Implementation
void drawCracks(
Painter p,
List<CrackLine> cracks,
double Function(CrackLine c) g,
double Function(double d) heat,
List<int> hot,
int dark,
int lip, [
double k = 1.0,
]) {
if (k <= 0.0) return;
int col(double d) {
final h = heat(d);
return h > 0.75
? hot[0]
: (h > 0.5
? hot[1]
: (h > 0.3 ? hot[2] : (h > 0.12 ? hot[3] : dark)));
}
for (final c in cracks) {
final G = g(c);
if (G <= 0.0) continue;
for (final path in [c.pts, ...c.kids]) {
for (var i = 1; i < path.length; i++) {
final p0 = path[i - 1];
final p1 = path[i];
if (p0.d >= G) break;
final f = p1.d > G ? (G - p0.d) / (p1.d - p0.d) : 1.0;
final ex = p0.x + (p1.x - p0.x) * f;
final ey = p0.y + (p1.y - p0.y) * f;
p.lineShaded(
p0.x,
p0.y + 1.0,
ex,
ey + 1.0,
color: (_) => lip,
alpha: (u) => rand(
(p0.x + (ex - p0.x) * u + 0.5).floor(),
(p0.y + (ey - p0.y) * u + 0.5).floor(),
5,
) <
0.3
? k * 0.8
: 0.0,
);
p.lineShaded(
p0.x,
p0.y,
ex,
ey,
color: (u) => col(p0.d + (p1.d - p0.d) * f * u),
alpha: (_) => k,
);
final h = heat(p0.d);
if (h > 0.12) {
p.glow(
(p0.x + ex) / 2.0,
(p0.y + ey) / 2.0,
4.0 + h * 4.0,
hot[2],
0.22 * h * k,
);
}
}
}
}
}