Nilo

Examples7

field

A still plate. A few points each push or pull and turn the space round them, and six thousand faint lines follow that field from random starts until they fall into a point or leave the sheet, so the light builds up where they crowd. Half the tokens are mirrored left to right. The light is one of four hues, which the compiler works out ahead of time and ships as a small table.

Thousands of fine warm lines on a dark ground, rising up the middle and curling round mirrored pairs of bright points

SourceShips asGzippedTarget
49 lines2,036 bytes1,133 bytessvg
// field: fine lines that follow the pull of a few points, some pushing out, some drawing in, some turning
plate(1920, 2400)
use colour v2
random layout, ink

kind charge { at: vec, push: num, spin: num }
let charges = charge[]
let mirrored = layout.chance(0.5)    // half the tokens are mirrored left to right, like a face
for k in 0 ..< layout.int(3 ..< 6) {
  let at = vec(layout.float(250 ..< 1670), layout.float(350 ..< 2050))
  let push = layout.float(-1 ..< 1), spin = layout.float(-0.5 ..< 0.5)
  charges.add(charge(at, push: push, spin: spin))
  if mirrored { charges.add(charge(vec(1920 - at.x, at.y), push: push, spin: -spin)) }
}
// the field's direction at p: each point pushes or pulls, and turns things round it, weaker with distance
fn flow(p: vec): vec {
  var sum = vec(0, 0)
  for c in charges {
    let away = p - c.at
    sum = sum + (away * c.push + perp(away) * c.spin) / dot(away, away)
  }
  return sum / len(sum)
}
fn landed(p: vec): bool {
  for c in charges { if len(p - c.at) < 10 { return true } }
  return p.x < -50 || p.x > 1970 || p.y < -50 || p.y > 2450
}
// from a start, along the field (or against it), until the line falls into a point or leaves the plate
fn trace(start: vec, way: num): vec[] {
  let line = vec[]
  var p = start
  for step in 0 ..< 400 {
    line.add(p)
    p = p + flow(p + flow(p) * way * 4) * way * 8
    if landed(p) { break }
  }
  return line
}
// one light in one of four hues, building up wherever lines crowd; a white heat at each point
let glow = colour.hsl([0.75, 0.08, 0.53, 0.95][ink.int(0 ..< 4)], 0.7, 0.8)
background(colour.mix(glow, toward: #000000, amount: 0.93))
for k in 0 ..< 3000 {
  let start = vec(layout.float(0 ..< 1920), layout.float(0 ..< 2400))
  polyline(trace(start, way: 1), stroke: glow, width: 1.2, opacity: 0.16)
  polyline(trace(start, way: -1), stroke: glow, width: 1.2, opacity: 0.16)
}
for c in charges {
  circle(c.at, 60)
  fill(radial(c.at, 60, [rgba(#ffffff, 1), rgba(glow, 0.5), rgba(glow, 0)]))
}