Nilo

Examples5

currents

Brush sweeps laid along a slow flow of noise and painted from one of four ramps, which the token chooses. It is written against all three libraries.

Broad brush sweeps in blues flowing across a pale ground

SourceShips asGzippedTarget
41 lines5,449 bytes2,656 bytessvg
// currents: brush sweeps laid along a slow noise flow, painted from one ramp
plate(1920, 2400)
use noise v1, colour v1, brush v1
random layout, paint, marks

// four ramps, dark to pale; the token takes one
let ramps = [#1d2b3a, #3e5c76, #9fb4c7, #ece6d8, #3b1f1a, #8c3b24, #d98e4a, #f2dfc2,
  #1f2a1d, #4f6b3a, #a9b98a, #ece8d6, #2a1f33, #6b3f6e, #c98fae, #f3e3ea]
let pick = paint.int(0 ..< 4) * 4
let ramp = [ramps[pick], ramps[pick + 1], ramps[pick + 2], ramps[pick + 3]]
let paper = colour.mix(ramp[3], #fbf8f1, 0.6)

// the flow: a turn of the whole plate, bent by layered noise
let field = noise.table(layout)
let scale = layout.float(0.0005 ..< 0.0011)
let turn = layout.float(0 ..< TAU)
let swirl = layout.float(1.5 ..< 3.5)
fn flow(p: vec) = turn + noise.octaves(field, p * scale, count: 3) * swirl

// a path from p along the flow in steps of 12, ending where it leaves the plate
fn follow(p: vec, steps: int): vec[] {
  let path = vec[]
  var q = p
  for k in 0 ..< steps {
    path.add(q)
    q = q + polar(flow(q), 12)
    if q.x < -60 || q.x > 1980 || q.y < -60 || q.y > 2460 { break }
  }
  return path
}

background(paper)
let count = layout.int(110 ..< 170)
for i in 0 ..< count {
  let start = vec(layout.float(-60 ..< 1980), layout.float(-60 ..< 2460))
  let path = follow(start, layout.int(24 ..< 70))
  // broad sweeps first, finer ones over them
  let width = (110 - 70 * i / count) * layout.float(0.7 ..< 1.3)
  if path.len < 6 { continue }
  // its value off a second, broader reading of the noise, its hue nudged
  let v = 0.55 + noise.at(field, start * 0.0004 + vec(40, 0)) * 0.5
  let hue = paint.float(-0.03 ..< 0.03)
  let tone = [colour.shiftHue(colour.at(ramp, v - 0.25), hue), colour.at(ramp, v), colour.at(ramp, v + 0.15)]
  brush.sweep(marks, path, width, tone, opacity: 0.8, body: 0.5)
}