reeds
A stand of reeds swaying in a loop of eight seconds, with motes drifting among them. Each reed ends in a round tip in one of three colours.
A frame partway through the loop. While it is on screen, the page runs the compiled file live.
| Source | Ships as | Gzipped | Target | Loop |
|---|---|---|---|---|
| 43 lines | 991 bytes | 590 bytes | canvas | 8 seconds |
// reeds: a stand of reeds swaying in an 8 second loop, motes drifting among them.
plate(1920, 2400)
random layout, mark
let ink = #22252b
let tips = [#b5482f, #2f6f8a, #d9a441]
param reedCount = layout.int(60 ..= 140)
param moteCount = mark.int(300 ..= 600)
kind reed { root: vec, h: num, amp: num, ph: num, sways: int, w: num, tipR: num, tip: color }
kind mote { c: vec, r: num, orb: num, ph: num }
let reeds = reed[]
let motes = mote[]
once {
for i in 0 ..< reedCount {
reeds.add(reed(root: vec(layout.float(150 ..= 1770), layout.float(2000 ..= 2250)),
h: layout.float(600 ..= 1500), amp: layout.float(40 ..= 160), ph: layout.unit(),
sways: layout.int(1 ..= 2), w: layout.float(1.5 ..= 4), tipR: layout.float(6 ..= 18),
tip: tips[layout.int(0 ..< 3)]))
}
for i in 0 ..< moteCount {
motes.add(mote(c: vec(mark.float(100 ..= 1820), mark.float(100 ..= 1900)), r: mark.float(1.5 ..= 4),
orb: mark.float(10 ..= 40), ph: mark.unit()))
}
}
// the point a fraction f of the way up a reed, at sway angle a (loop time, in turns)
fn at(root: vec, h: num, amp: num, f: num, a: num) = root + vec(amp * f * f * sin(a + 0.15 * f), -f * h)
frame(t: loop 8s) {
background(#efe9dc)
for m in motes {
circle(m.c + orbit(t + m.ph, m.orb), m.r)
}
fill(ink)
for r in reeds {
move(r.root)
for k in 1 ..= 20 {
to(at(r.root, r.h, r.amp, k / 20, t * r.sways + r.ph))
}
stroke(ink, r.w)
}
for r in reeds {
circle(at(r.root, r.h, r.amp, 1, t * r.sways + r.ph), r.tipR)
fill(r.tip)
}
}