From dca8b46abffeb056b3c17a6c26f66835f01aff60 Mon Sep 17 00:00:00 2001 From: alex Date: Sat, 16 Apr 2022 11:40:47 +0100 Subject: [PATCH] add `degrade`/`degradeBy` --- packages/core/signal.mjs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/packages/core/signal.mjs b/packages/core/signal.mjs index a2f0e4e4..a6868937 100644 --- a/packages/core/signal.mjs +++ b/packages/core/signal.mjs @@ -88,3 +88,17 @@ export const perlinWith = (pat) => { }; export const perlin = perlinWith(time); + +Pattern.prototype._degradeByWith = function (withPat, x) { + return this.fmap((a) => (_) => a).appLeft(withPat._filterValues((v) => v > x)); +}; + +Pattern.prototype._degradeBy = function (x) { + return this._degradeByWith(rand, x); +}; + +Pattern.prototype._degrade = function () { + return this._degradeBy(0.5); +}; + +Pattern.prototype.patternified.push('degradeBy', 'degrade');