ring function

void ring(
  1. Painter p,
  2. double cx,
  3. double cy,
  4. double r,
  5. double sy,
  6. double k,
  7. List<int> c, {
  8. int n = 2,
  9. double gap = 3.0,
  10. int half = 0,
  11. bool hot = false,
  12. double glint = 0.0,
  13. int seed = 0,
  14. double wob = 0.0,
})

A ripple on a surface seen at a low angle.

Implementation

void ring(
  Painter p,
  double cx,
  double cy,
  double r,
  double sy,
  double k,
  List<int> c, {
  int n = 2,
  double gap = 3.0,
  int half = 0,
  bool hot = false,
  double glint = 0.0,
  int seed = 0,
  double wob = 0.0,
}) {
  if (k <= 0.02 || r < 0.5) return;
  for (var j = 0; j < n; j++) {
    final rr = r - j * gap;
    if (rr < 0.6) break;
    final kj = k * (1.0 - j * 0.42);
    final m = math.max(6, (rr * tau * 1.3).ceil());
    final need = 1.15 - 2.3 * math.min(1.0, kj * 1.25);
    for (var i = 0; i < m; i++) {
      final a = (i / m) * tau;
      final s = math.sin(a);
      final near = s > 0.0;
      if ((half > 0 && !near) || (half < 0 && near)) continue;
      if (noise(a * 4.7 + seed * 13.1 + j * 5.3, seed) * 0.65 +
              noise(a * 11.3 + seed * 7.7, seed + 3) * 0.35 <
          need) {
        continue;
      }
      final lit = kj * (near ? 1.0 : 0.7) * (0.88 - 0.12 * math.cos(a));
      final col = hot && near && j == 0
          ? kWhite
          : c[lit > 0.7 ? 6 : (lit > 0.38 ? 5 : 4)];
      final ra = wob != 0.0
          ? rr + wob * noise(a * 2.6 + seed * 1.9 + j, seed + 11)
          : rr;
      final x = cx + math.cos(a) * ra;
      final y = cy + s * ra * sy;
      p.dot(x, y, col);
      if (j == 0) p.light(x, y, c[4], 0.3 * lit);
    }
  }
  if (glint > 0.0 && half >= 0) {
    final x = cx + math.cos(2.05) * r;
    final y = cy + math.sin(2.05) * r * sy;
    p.px(x, y, kWhite);
    p.glow(x, y, 3.0 + glint * 2.0, c[5], 0.35 * glint);
  }
}