feat: new LFO waveforms
This commit is contained in:
parent
74cbad6e7d
commit
d27d324f2c
|
@ -9,18 +9,26 @@ const Modulator = {
|
|||
return () => 0.5;
|
||||
},
|
||||
|
||||
Linear() {
|
||||
return (location) => location;
|
||||
},
|
||||
|
||||
Random({variance = 0.4} = {}) {
|
||||
return () => Math.abs((Math.random() * (variance + variance) - variance)) % 1;
|
||||
},
|
||||
|
||||
Sawtooth() {
|
||||
return (location) => location;
|
||||
},
|
||||
|
||||
Sine() {
|
||||
return (location) => 0.5 * (1 + Math.sin(location * Math.PI * 2));
|
||||
},
|
||||
|
||||
Square() {
|
||||
return (location) => (location < 0.5 ? 0 : 1);
|
||||
},
|
||||
|
||||
Triangle() {
|
||||
return (location) => 2 * Math.abs(((location + 0.75) % 1) - 0.5);
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
const decorate = compose(
|
||||
|
@ -55,7 +63,7 @@ export default class ModulatedProperty extends decorate(Class) {
|
|||
this.key = key;
|
||||
if (!modulators) {
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
modulators = [Modulator.Linear];
|
||||
modulators = [Modulator.Triangle];
|
||||
}
|
||||
if (!Array.isArray(modulators)) {
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
|
@ -70,12 +78,12 @@ export default class ModulatedProperty extends decorate(Class) {
|
|||
this.min = this.median - (magnitude / 2);
|
||||
const modulatorFunction = (modulator) => {
|
||||
if ('string' === typeof modulator) {
|
||||
return Modulator[modulator] ? Modulator[modulator] : Modulator.Linear;
|
||||
return Modulator[modulator] ? Modulator[modulator] : Modulator.Triangle;
|
||||
}
|
||||
if ('function' === typeof modulator) {
|
||||
return modulator;
|
||||
}
|
||||
return Modulator.Linear;
|
||||
return Modulator.Triangle;
|
||||
};
|
||||
this.modulators = modulators.map((modulator) => {
|
||||
if ('object' !== typeof modulator) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user