0.0.2 • Published 2 years ago

bounded-sine v0.0.2

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

Background

In game dev, generative art, and creative coding, sine is a ubiquitous function that is often used as a spring-like oscillator for a given parameter.

On its own, sine has some undesirable qualities which most developers will encounter and adjust in isolated situations. The purpose of Bounded Sine is to solve these issues up-front in a reusable way:

SineBounded SineBenefits
Period = 2 * PIPeriod = period, which defaults to 1.No longer need to work in radians. Period can be any value.
Is bounded by [-1, 1]Is bounded by [yMin, yMax]Bounds can now match the min/max value of a parameter.
fx(0) = 0fx(0) = yStart where yMin <= yStart <= yMaxStarting value can be set rather than it being fixed.

Here's an example:

const fn = boundedSine({ yStart: 2, yMax: 3, yMin: 0 });

bounded-sine-1

Bounded Sine also takes period and invert parameters:

const fn = boundedSine({ yStart: 2, yMax: 3, yMin: 0, period: 10, invert: true });

bounded-sine-2

API

ParameterDefaultDescription
options{}boundedSine takes a single options object.
options.yStart0The value of fx(0) before translations.
options.yMin-1The minimum y-value before translations.
options.yMax1The maximum y-value before translations.
options.period1The length of one cycle of the curve.
options.translateX0Translation applied in the x-direction.
options.translateY0Translation applied in the y-direction.
options.invertfalseReflect the sine curve around the average y-value.

Installation and Usage

yarn add bounded-sine

import { boundedSine } from "bounded-sine";
const fn = boundedSine({ yStart: 2, yMax: 3, yMin: 0 });
const yStart = fn(0)