shaped function

IconMask shaped(
  1. bool f(
    1. double u,
    2. double v
    ),
  2. double s, [
  3. double ang = 0.0
])

IconMask for a shape given in its own unit space by f(u, v).

Implementation

IconMask shaped(
  bool Function(double u, double v) f,
  double s, [
  double ang = 0.0,
]) {
  final c = math.cos(ang);
  final n = math.sin(ang);
  return (int dx, int dy) {
    final x = dx + 0.5;
    final y = dy + 0.5;
    return f((x * c + y * n) / s, (-x * n + y * c) / s) ? '#' : '';
  };
}