drawRock function

void drawRock(
  1. Painter p,
  2. ExplosionBit b,
  3. StoneColors st,
  4. List<int> fr,
)

A rock (a Bits CHUNK): a lit side, a shaded side and an outline, turning as it spins.

Implementation

void drawRock(Painter p, ExplosionBit b, StoneColors st, List<int> fr) {
  final r = 0.6 + b.size * 0.75;
  final fade = math.min(1.0, b.life / 0.5);
  final lx = math.cos(b.a) * r * 0.4;
  final ly = math.sin(b.a) * r * 0.4;
  final heat = b.heat;
  p.shade(b.x - r - 1, b.y - r - 1, b.x + r + 1, b.y + r + 1, (x, y, out) {
    final dx = x - b.x;
    final dy = y - b.y;
    final d = hypot(dx * 1.15, dy);
    if (d > r + 0.9) return null;
    out.a = fade;
    if (d > r) return kExplosionOutline;
    final lit = dx * lx + dy * ly;
    if (heat > 0.08) {
      final g = heat * (1.1 - d / (r + 0.5)) + (lit > 0.3 ? heat * 0.45 : 0.0);
      if (g > 0.5) {
        return fr[g > 1.0 ? 1 : (g > 0.8 ? 2 : (g > 0.62 ? 3 : 4))];
      }
      if (g > 0.32) return fr[5];
    }
    return lit < -0.4 ? st.light : (lit > 0.6 ? st.shade : st.body);
  });
  if (heat > 0.05) p.glow(b.x, b.y, r * 2.0 + 3.0, fr[3], 0.32 * heat * fade);
}