Skip to content

1681-engine / pixel / swayOffset

Function: swayOffset() ​

ts
function swayOffset(
   tSec, 
   speed, 
   phase, 
   lag, 
   amp, 
   wind, 
   gust, 
   weight, 
   minReach?
): number;

Defined in: src/pixel/swayRig.ts:190

How many whole pixels a strip stands off at tSec: a main swing with a slower second one riding it (so no two trees ever meet in step), leaning a little downwind as the wind rises, scaled by the reach, the wind, the gust and the strip's weight, and rounded — the sway moves in pixel steps, 0 → 1 → 0, never smeared between them.

minReach is the least that reach × wind × gust may come to while any wind blows (a still place's floor, chosen by the game): without it a faint breeze never rounds to a whole pixel and the trees stand dead still, and rounding is the rule, so the floor is what lets the crest of a swing tick one pixel over and back.

Parameters ​

ParameterTypeDefault value
tSecnumberundefined
speednumberundefined
phasenumberundefined
lagnumberundefined
ampnumberundefined
windnumberundefined
gustnumberundefined
weightnumberundefined
minReachnumber0

Returns ​

number

Released under the MIT License.