Nilo

Examples6

hills

Ridges drawn as smooth closed curves and filled with gradients, under a gradient sky with a low sun. Each ridge is worked over with brush sweeps that are faded together as one wash and cut to the ridge’s own outline. It uses curves, gradient paint and a clipped group.

Violet ridges receding under a dark sky, a pale sun and its glow above them

SourceShips asGzippedTarget
50 lines7,062 bytes3,153 bytessvg
// hills: ridges of smooth curves under a gradient sky, each worked with brush sweeps cut to its own outline
plate(1920, 2400)
use noise v1, colour v1, brush v1, spline v1
random layout, paint, marks

// three ramps, dark to pale; the token takes one
let ramps = [#1d2b3a, #3e5c76, #9fb4c7, #ece6d8, #3b1f1a, #8c3b24, #d98e4a, #f2dfc2,
  #2a1f33, #6b3f6e, #c98fae, #f3e3ea]
let pick = paint.int(0 ..< 3) * 4
let ramp = [ramps[pick], ramps[pick + 1], ramps[pick + 2], ramps[pick + 3]]
let field = noise.table(layout)

// n points round a circle, the radius wobbling a little
fn blob(c: vec, r: num, n: int): vec[] {
  let out = vec[]
  for i in 0 ..< n { out.add(c + polar(TAU * i / n, r * layout.float(0.95 ..< 1.05))) }
  return out
}

// the sky, and a low sun with its glow
background(linear(vec(0, 0), vec(0, 1700), [colour.darken(ramp[0], 0.35), ramp[1], colour.at(ramp, 0.85)]))
let sun = vec(layout.float(500 ..< 1400), layout.float(900 ..< 1250))
let glow = radial(sun, 700, [rgba(ramp[3], 0.85), rgba(colour.lighten(ramp[2], 0.3), 0.3), rgba(ramp[2], 0)])
curve(blob(sun, 900, 8), closed: true, fill: glow)
curve(blob(sun, 170, 10), closed: true, fill: radial(sun, 170, [#ffffff, colour.lighten(ramp[3], 0.5)]))

// four ridges, far to near, each lower and darker
let ridges = 4
for k in 0 ..< ridges {
  let near = k / (ridges - 1)
  let base = 1250 + near * 900
  let outline = vec[]
  for i in 0 ..= 12 {
    let x = -160 + i * 175
    outline.add(vec(x, base + 340 * noise.octaves(field, vec(x * 0.0011, k * 7 + 3), count: 3) * (1 - near * 0.4)))
  }
  outline.add(vec(2100, 2600))
  outline.add(vec(-200, 2600))
  let shade = 0.78 - near * 0.62
  let ink = colour.mix(colour.at(ramp, shade), ramp[0], near * 0.55)
  let top = base - 380
  // the body: dark at the foot, lit along the crest
  curve(outline, smooth: 0.9, closed: true, fill: linear(vec(0, top), vec(0, top + 900), [colour.lighten(ink, 0.18), ink, colour.darken(ink, 0.4)]))
  // brush sweeps across it, faded together as one wash and cut to the same curve
  place(opacity: 0.55 + near * 0.3, clip: curve(outline, smooth: 0.9, closed: true)) {
    for s in 0 ..< 9 + k * 4 {
      let y = layout.float(top + 100 ..< base + 800)
      let drag = vec[]
      for i in 0 ..= 10 { drag.add(vec(-100 + i * 220, y + 90 * noise.at(field, vec(i * 0.5 + s, y * 0.004 + k)))) }
      let v = colour.mix(ink, colour.at(ramp, layout.unit()), 0.35)
      brush.sweep(marks, spline.sample(drag, 8), layout.float(110 ..< 260), [colour.darken(v, 0.3), v, colour.lighten(v, 0.25)], opacity: 0.8, density: 0.6, body: 0.4)
    }
  }
}