bubble function

void bubble(
  1. Painter p,
  2. double cx,
  3. double cy,
  4. double r,
  5. List<int> cols, [
  6. double a = 1.0,
  7. double wob = 0.0,
])

Implementation

void bubble(
  Painter p,
  double cx,
  double cy,
  double r,
  List<int> cols, [
  double a = 1.0,
  double wob = 0.0,
]) {
  final hi = cols[0];
  final lit = cols[1];
  final rim = cols[2];
  final shadeCol = cols[3];
  if (r < 0.9) {
    p.dot(cx, cy, r < 0.7 ? rim : lit, a);
    return;
  }
  if (r < 1.5) {
    final px = cx.floor();
    final py = cy.floor();
    p.dot(px, py, hi, a);
    p.dot(px + 1, py, lit, a);
    p.dot(px, py + 1, rim, a);
    p.dot(px + 1, py + 1, shadeCol, a);
    p.glow(cx + 0.5, cy + 0.5, 3, lit, 0.12 * a);
    return;
  }
  final rx = r * (1.0 + wob);
  final ry = r * (1.0 - wob);
  final yEnd = (cy + ry + 1.0).ceil();
  final xStart = (cx - rx - 1.0).floor();
  final xEnd = (cx + rx + 1.0).ceil();
  for (var y = (cy - ry - 1.0).floor(); y <= yEnd; y++) {
    for (var x = xStart; x <= xEnd; x++) {
      final dx = (x + 0.5 - cx) / rx;
      final dy = (y + 0.5 - cy) / ry;
      final d = math.sqrt(dx * dx + dy * dy) * r;
      if (d > r + 0.5) continue;
      final l = (-dx - dy) / math.sqrt2 / math.max(0.01, d / r);
      if (d > r - 0.6) {
        p.dot(x, y, l > 0.45 ? lit : (l < -0.55 ? shadeCol : rim), a);
      }
    }
  }
  final hx = roundJs(cx - rx * 0.45);
  final hy = roundJs(cy - ry * 0.45);
  p.dot(hx, hy, hi, a);
  if (r >= 2.5) {
    p.dot(hx + 1, hy, lit, a);
    p.dot(hx, hy + 1, lit, a);
  }
  if (r >= 2.0) {
    p.dot(roundJs(cx + rx * 0.5), roundJs(cy + ry * 0.5), lit, a);
  }
  p.glow(cx, cy, r * 2.4 + 2.0, rim, 0.14 * a);
}