This browser has no WebGPU, so the sketch cannot run here. The program is below, and it runs in a current Chrome, Edge or Safari.
Boats
A population steered across a moving surface, each agent sampling the field beneath it.
// ── main ──
&dim = (512,512,1);
&c2 = 0.25;
&damp = 0.99;
&rad = 0.025;
& = 0.03;
&numBoats = 8;
&dir = nrm(&src);
&ang = atn(&dir.y, &dir.x);
// state
&u = #.r; // current height
&up = #.g; // previous height
// 4-neighbor laplacian
&lap = sub(
add(
#(-1, 0).r,
#( 1, 0).r,
#( 0, -1).r,
#( 0, 1).r
),
mlt(4, &u)
);
// wave equation
&un = add(
mlt(&damp, sub(mlt(2, &u), &up)),
mlt(&c2, &lap),
mlt(#boatsmap, 0.02)
);
#wave{
dim = &dim;
set = (0);
run = (&un, &u, 0);
bound = ZERO;
}
~surface{
dim = &dim;
disp = add(C,(0,0,mlt(#wave.r, 0.1)));
rot = (HALF_PI, 0,0);
col = sub((0,0.3,0.5), #wave.r);
filter = NEAREST;
shade = SMOOTH;
}
~bowies{
dim = (4,4,1);
shape = CONE;
i_pos = (C.x, C.y, mlt(#wave.r, 0.1));
rot = (HALF_PI, 0,0);
i_piv = (0, -0.25, 0);
i_rot = (-HALF_PI, 0,0);
i_scl = (0.05);
col = (1,0,0);
}
~boats{
dim = (&numBoats,1,1);
rot = (HALF_PI, 0,0);
i_pos = (#boats.x, #boats.y, mlt(#wave.r, 0.1));
i_scl = mlt(0.015, &numBoats, (1,2,1));
shape = CONE;
i_rot = aim( sub(#boats, #boatsPrev));
}
{
= (1);
= (0.25);
= (0.7);
}
// ── boatsMap ──
#boats{
dim = (&numBoats,1,1);
run = (
LATT[mlt(add(-230, mlt(C.x, 203), (mlt(step, 0.012))), 0.1)]{dot(nrm(D), R)},
LATT[mlt(add(230, mlt(C.x, 103), (mlt(step, 0.012))), 0.2)]{dot(nrm(D), R)},
0);
coord_dom = UNIT;
}
#boatsPrev{
dim = (&numBoats,1,1);
run = #boats;
coord_dom = UNIT;
}
~boatsmap{
dim = (&numBoats,1,1);
pos = (10, 0,0);
i_pos = #boats;
i_scl = mlt(0.005, &numBoats);
}
#boatsmap{
dim = (256,256,1);
run = ;
}
{
= (10, 0, 2.4142);
= (10, 0,0);
= (0);
= (0.1, 4, 0);
}