coin function

void coin(
  1. SpriteLayer l,
  2. Painter p,
  3. double x,
  4. double y,
  5. double r,
  6. double ax,
  7. double spin,
  8. List<int> c, {
  9. bool white = false,
  10. double a = 1.0,
  11. bool snap = true,
})

Implementation

void coin(
  SpriteLayer l,
  Painter p,
  double x,
  double y,
  double r,
  double ax,
  double spin,
  List<int> c, {
  bool white = false,
  double a = 1.0,
  bool snap = true,
}) {
  final xx = snap ? (x + 0.5).floorToDouble() : x;
  final yy = snap ? (y + 0.5).floorToDouble() : y;
  final cs = math.cos(spin);
  final sn = math.sin(spin);
  final b = math.max(0.5, r * cs.abs());
  final th = 1.2 * sn * (cs == 0.0 ? 1.0 : cs.sign);
  final ca = math.cos(ax);
  final sa = math.sin(ax);
  final face = cs.abs();
  final rad = r.ceil() + 2;
  l.begin(xx.floor() - rad, yy.floor() - rad);
  l.fill(xx.floor() - rad, yy.floor() - rad, xx.floor() + rad, yy.floor() + rad,
      (px, py) {
    final dx = px - xx;
    final dy = py - yy;
    final u = dx * ca + dy * sa;
    final w = -dx * sa + dy * ca;
    final ef = hypot(u / r, w / b);
    final er = hypot(u / r, (w - th) / b);
    if (white && (ef <= 1.0 || er <= 1.0)) return kWhite;
    if (ef <= 1.0) {
      final lit = -(dx * 0.62 + dy * 0.78) / math.max(1.0, hypot(dx, dy));
      final dim = face < 0.45 ? 1 : 0;
      if (b < 1.1) return lit > 0.0 ? c[6] : c[4];
      if (ef > 0.72) {
        return c[(lit > 0.3 ? 6 : (lit > -0.35 ? 5 : 3)) - dim];
      }
      if (b > 2.2 && ef > 0.42) return c[(lit > 0.2 ? 4 : 5) - dim];
      if (face > 0.6 && lit > 0.5) return c[7];
      return c[5 - dim];
    }
    if (er <= 1.0) return (w - th).abs() < w.abs() ? c[2] : c[3];
    return 0;
  });
  l.outline(c[1]).draw(p, 0, 0, a);
}