stoneShape function

List<Point2> stoneShape(
  1. Rng r, [
  2. int? n
])

Corners of an irregular stone, unit size, in angular order.

Implementation

List<Point2> stoneShape(Rng r, [int? n]) {
  final count = n ?? r.intRange(5, 7);
  final pts = <Point2>[];
  final a0 = r.range(0, tau);
  final squash = r.range(0.7, 1);
  for (var i = 0; i < count; i++) {
    final a = a0 + ((i + r.range(-0.28, 0.28)) * tau) / count;
    final rad = r.range(0.72, 1.12);
    pts.add((math.cos(a) * rad, math.sin(a) * rad * squash));
  }
  return pts;
}