Open as new workspace
Experimenting with Grids from scratch by Ryan

Experimenting with Grids from scratch

View source Pathogen · 48 lines
define ViewBox(0, 0, 13200, 5200);

define default PathLayer('background') ${
  fill: #fff;
}

layer('background').apply {
  rect(0, 0, 13200, 5200);
}

let field = Grid(320, 200, { xDim: 20, yDim: 8, outOfBounds: 'wrap' }) {|g|
  g.fill {|row, col, center|
    return calc(tan(row * 2.8 / g.rows) + atan(col * 3.8 / g.cols));
  };
};

let colorCount = 240;
let colors = Color.palette(oklch(0.6695 0.2483 330.1),
                           oklch(0.8142 0.1571 72.9),
                           colorCount);
let drawingLayerSet = colors.map {|color, index|
  return PathLayer(`drawing-layer-${index}`) ${
    stroke-width: 0.2;
    stroke: color.darken(0.2).alpha(0.48);
    fill: color.alpha(0.325);
  };
};

let itemLength = 480;
for (drawingLayer in drawingLayerSet) {
  let x = randomRange(900, 12000);
  let y = randomRange(1000, 2800);
  let start = Point(x, y);
  let next = start;
  for (k in 1..itemLength) {
    let angle = field.sampleBilinear(start.y, start.x);
    next = start.polarTranslate(angle, 3.6);
    drawingLayer.apply {
      let diameter = calc(k * 1.05);
      if (k > calc(itemLength / 2)) {
        diameter = calc((itemLength - k) * 1.07);
      }
      circle(start.x, start.y, diameter);
    }
    start = next;
  }
}