aboutsummaryrefslogtreecommitdiff
path: root/lib/systems
diff options
context:
space:
mode:
authorRuben Beltran del Rio <git@r.bdr.sh>2024-05-08 17:58:05 +0200
committerRuben Beltran del Rio <git@r.bdr.sh>2024-05-08 17:58:05 +0200
commit2b9badac1345c865c34097bc5d1699329b53fdc8 (patch)
treee9db2b722d116b937330eb02056901226e987a61 /lib/systems
parent3a88e11079e5e331a10ed35ffdd67d8f3a790d23 (diff)
Add phase
Diffstat (limited to 'lib/systems')
-rw-r--r--lib/systems/lissajous_position_updater.js6
-rw-r--r--lib/systems/phase_adjuster.js66
2 files changed, 69 insertions, 3 deletions
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(){}
+};