feat: res
This commit is contained in:
parent
98c3fa22ac
commit
b9a4779a52
|
@ -9,8 +9,8 @@ const Modulator = {
|
|||
return () => 0.5;
|
||||
},
|
||||
|
||||
Random({variance = 0.4} = {}) {
|
||||
return () => Math.abs((Math.random() * (variance + variance) - variance)) % 1;
|
||||
Random() {
|
||||
return () => Math.random();
|
||||
},
|
||||
|
||||
Sawtooth() {
|
||||
|
@ -56,6 +56,7 @@ export default class ModulatedProperty extends decorate(Class) {
|
|||
magnitude,
|
||||
median,
|
||||
modulators,
|
||||
resolution = 0,
|
||||
},
|
||||
) {
|
||||
super();
|
||||
|
@ -73,9 +74,11 @@ export default class ModulatedProperty extends decorate(Class) {
|
|||
this.median = median;
|
||||
this.frequency = frequency;
|
||||
this.location = location;
|
||||
this.interval = 0;
|
||||
this.magnitude = magnitude;
|
||||
this.median = 'undefined' === typeof median ? magnitude / 2 : median;
|
||||
this.min = this.median - (magnitude / 2);
|
||||
this.resolution = resolution;
|
||||
const modulatorFunction = (modulator) => {
|
||||
if ('string' === typeof modulator) {
|
||||
return Modulator[modulator] ? Modulator[modulator] : Modulator.Triangle;
|
||||
|
@ -98,6 +101,13 @@ export default class ModulatedProperty extends decorate(Class) {
|
|||
for (let i = 0; i < this.transitions.length; i++) {
|
||||
this.transitions[i].tick(elapsed);
|
||||
}
|
||||
if (0 !== this.resolution) {
|
||||
this.interval += elapsed;
|
||||
if (this.interval < this.resolution) {
|
||||
return;
|
||||
}
|
||||
this.interval -= this.resolution;
|
||||
}
|
||||
const {frequency} = this;
|
||||
let {location} = this;
|
||||
location += elapsed;
|
||||
|
@ -106,7 +116,7 @@ export default class ModulatedProperty extends decorate(Class) {
|
|||
}
|
||||
this.location = location;
|
||||
const value = this.modulators.reduce(
|
||||
(value, m) => value + m(location / frequency),
|
||||
(value, m) => value + m(location / frequency, this),
|
||||
0,
|
||||
) / this.modulators.length;
|
||||
this.object[this.key] = this.min + this.factor * value * this.magnitude;
|
||||
|
|
Loading…
Reference in New Issue
Block a user