]> git.r.bdr.sh - rbdr/lissajous/blob - lib/systems/phase_adjuster.js
120b05d8a854595d0bb36c40159cb8185a6eb3f3
[rbdr/lissajous] / lib / systems / phase_adjuster.js
1 import { System } from '@serpentity/serpentity';
2 import Phased from '../nodes/phased';
3 import { settingsContainer, slider } from '../factories/ui';
4
5 const internals = {
6 symbols: {
7 a: '𝛿',
8 b: '𝜀',
9 c: '𝜂'
10 }
11 };
12
13 export default class PhaseAdjuster extends System {
14
15 constructor(container) {
16
17 super();
18 this.container = container;
19 }
20
21 added(engine){
22
23 this.nodes = engine.getNodes(Phased);
24 this.adjusterContainer = settingsContainer({
25 id: 'phase-adjuster',
26 label: 'Phase'
27 })
28
29 let i = 0;
30 for (const node of this.nodes) {
31 const nodeElement = settingsContainer({
32 id: `phase-adjuster-${i}`,
33 label: ${i + 1}`,
34 level: 3
35 });
36
37 ['a', 'b', 'c'].forEach(key => {
38 nodeElement.appendChild(slider({
39 id: `phase-adjuster-${i}-slider-${key}`,
40 min: '0',
41 max: Math.PI.toString(),
42 step: '0.01',
43 shiftStep: (Math.PI / 8).toString(),
44 label: internals.symbols[key],
45 className: `phase`,
46 get: () => node.phase[key].toString(),
47 set: (value) => (node.phase[key] = parseFloat(value))
48 }));
49 });
50
51 this.adjusterContainer.appendChild(nodeElement);
52 ++i;
53 }
54
55 this.container.appendChild(this.adjusterContainer);
56 }
57
58 removed(){
59
60 this.container.removeChild(this.adjusterContainer);
61 delete this.adjusterContainer;
62 delete this.nodes;
63 }
64
65 update(){}
66 };