From 2b9badac1345c865c34097bc5d1699329b53fdc8 Mon Sep 17 00:00:00 2001 From: Ruben Beltran del Rio Date: Wed, 8 May 2024 17:58:05 +0200 Subject: Add phase --- lib/systems/lissajous_position_updater.js | 6 +-- lib/systems/phase_adjuster.js | 66 +++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 lib/systems/phase_adjuster.js (limited to 'lib/systems') diff --git a/lib/systems/lissajous_position_updater.js b/lib/systems/lissajous_position_updater.js index 39b151a..da90fb2 100644 --- a/lib/systems/lissajous_position_updater.js +++ b/lib/systems/lissajous_position_updater.js @@ -30,9 +30,9 @@ export default class WebGLRenderer extends System { this.time = (this.time + dt / 500) % internals.kPeriod; for (const curve of this.curves) { - curve.position.x = this._getPosition(curve.amplitude.a, curve.frequency.a, this.time, 0); - curve.position.y = this._getPosition(curve.amplitude.b, curve.frequency.b, this.time, 0); - curve.position.z = this._getPosition(curve.amplitude.c, curve.frequency.c, this.time, 0); + curve.position.x = this._getPosition(curve.amplitude.a, curve.frequency.a, this.time, curve.phase.a); + curve.position.y = this._getPosition(curve.amplitude.b, curve.frequency.b, this.time, curve.phase.b); + curve.position.z = this._getPosition(curve.amplitude.c, curve.frequency.c, this.time, curve.phase.c); } } diff --git a/lib/systems/phase_adjuster.js b/lib/systems/phase_adjuster.js new file mode 100644 index 0000000..120b05d --- /dev/null +++ b/lib/systems/phase_adjuster.js @@ -0,0 +1,66 @@ +import { System } from '@serpentity/serpentity'; +import Phased from '../nodes/phased'; +import { settingsContainer, slider } from '../factories/ui'; + +const internals = { + symbols: { + a: '𝛿', + b: '𝜀', + c: '𝜂' + } +}; + +export default class PhaseAdjuster extends System { + + constructor(container) { + + super(); + this.container = container; + } + + added(engine){ + + this.nodes = engine.getNodes(Phased); + this.adjusterContainer = settingsContainer({ + id: 'phase-adjuster', + label: 'Phase' + }) + + let i = 0; + for (const node of this.nodes) { + const nodeElement = settingsContainer({ + id: `phase-adjuster-${i}`, + label: `ɣ${i + 1}`, + level: 3 + }); + + ['a', 'b', 'c'].forEach(key => { + nodeElement.appendChild(slider({ + id: `phase-adjuster-${i}-slider-${key}`, + min: '0', + max: Math.PI.toString(), + step: '0.01', + shiftStep: (Math.PI / 8).toString(), + label: internals.symbols[key], + className: `phase`, + get: () => node.phase[key].toString(), + set: (value) => (node.phase[key] = parseFloat(value)) + })); + }); + + this.adjusterContainer.appendChild(nodeElement); + ++i; + } + + this.container.appendChild(this.adjusterContainer); + } + + removed(){ + + this.container.removeChild(this.adjusterContainer); + delete this.adjusterContainer; + delete this.nodes; + } + + update(){} +}; -- cgit