snowflake function
void
snowflake(})
A six-armed snowflake of radius r turned by rot, crisp 1 px lines.
Implementation
void snowflake(
Painter p,
double x,
double y,
double r,
double rot,
FlakeDesign d,
List<int> c, {
double a = 1.0,
double hot = 0.0,
}) {
final n = c.length;
const step = math.pi / 18.0;
rot = (rot / step + 0.5).floor() * step;
if (r < 1.2) {
p.dot(x, y, kWhite, a);
return;
}
if (r < 2.6) {
const sector = math.pi / 3.0;
final pose =
(((rot.remainder(sector) + sector) / (math.pi / 6.0)).floor()) % 2;
const ptsA = [(1, 0), (-1, 0), (0, 1), (0, -1)];
const ptsB = [(1, 1), (-1, -1), (1, -1), (-1, 1)];
for (final (dx, dy) in pose != 0 ? ptsA : ptsB) {
p.dot(x + dx, y + dy, hot > 0.5 ? kWhite : c[n - 3], a);
}
p.dot(x, y, kWhite, a);
p.glow(x, y, 4, c[n - 3], 0.2 * a);
return;
}
final arm = hot > 0.5 ? kWhite : c[n - 2];
final br = hot > 0.5 ? c[n - 2] : c[n - 3];
final big = r >= 7.0;
final branches = r < 4.0
? const <(double, double)>[]
: (big
? (d.branches.length > 2 ? d.branches.sublist(0, 2) : d.branches)
: const [(0.58, 0.36)]);
for (var k = 0; k < 6; k++) {
final g = rot + (k * tau) / 6.0;
final ca = math.cos(g);
final sa = math.sin(g);
p.line(x, y, x + ca * r, y + sa * r, arm, a);
for (final (u, l) in branches) {
final bx = x + ca * r * u;
final by = y + sa * r * u;
final bl = math.max(1.0, r * l);
for (final s in const [-1, 1]) {
p.line(
bx,
by,
bx + math.cos(g + (s * math.pi) / 3.0) * bl,
by + math.sin(g + (s * math.pi) / 3.0) * bl,
br,
a,
);
}
}
if (d.fork && big && !d.plate) {
for (final s in const [-1, 1]) {
p.dot(
x + ca * r + math.cos(g + s * 0.9) * 1.2,
y + sa * r + math.sin(g + s * 0.9) * 1.2,
br,
a,
);
}
}
p.dot(x + ca * r, y + sa * r, kWhite, a);
}
if (d.plate && big) {
final q = r * 0.34;
for (var k = 0; k < 6; k++) {
final g0 = rot + math.pi / 6.0 + (k * tau) / 6.0;
final g1 = g0 + tau / 6.0;
p.line(
x + math.cos(g0) * q,
y + math.sin(g0) * q,
x + math.cos(g1) * q,
y + math.sin(g1) * q,
c[n - 3],
a,
);
}
}
p.px(x, y, kWhite);
p.glow(x, y, 3.0 + r * 1.2, c[n - 4], (0.14 + 0.35 * hot) * a);
if (hot > 0.3) p.glow(x, y, 2.0 + r * 0.5, kWhite, 0.3 * hot * a);
}