apply method
Implementation
@override
void apply(Buffer source, Buffer target, double dt) {
final width = source.width();
final height = source.height();
if (width <= 0 || height <= 0) return;
_ensure(width, height);
final timeStep = dt <= 0 ? 1 / 60 : dt;
_time += timeStep;
for (var y = 0; y < height; y++) {
for (var x = 0; x < width; x++) {
final i = y * width + x;
final nx = math.sin(x * 0.15 + y * 0.07 + _time * 1.3);
final ny = math.cos(y * 0.17 + x * 0.05 + _time * 1.1);
final jitterX = (_rng.nextDouble() * 2 - 1) * noise;
final jitterY = (_rng.nextDouble() * 2 - 1) * noise;
_vx[i] = (_vx[i] * damping) + (nx * flow + jitterX) * timeStep;
_vy[i] = (_vy[i] * damping) + (ny * flow + jitterY) * timeStep;
}
}
for (var y = 0; y < height; y++) {
for (var x = 0; x < width; x++) {
final i = y * width + x;
final dx = _vx[i] * strength;
final dy = _vy[i] * strength;
final sx = (x + dx).round().clamp(0, width - 1);
final sy = (y + dy).round().clamp(0, height - 1);
final cell = source.cellAt(sx, sy);
if (cell == null || cell.width == 0) {
target.setCell(x, y, Cell.emptyCell());
} else {
target.setCell(x, y, cell);
}
}
}
}