]> git.r.bdr.sh - rbdr/lissajous/blob - lib/systems/amplitude_adjuster.js
04f271a17275ce288a755e3b0454f6a3455359f7
[rbdr/lissajous] / lib / systems / amplitude_adjuster.js
1 import { System } from '@serpentity/serpentity';
2 import Ample from '../nodes/ample';
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 AmplitudeAdjuster extends System {
14
15 constructor(container) {
16
17 super();
18 this.container = container;
19 }
20
21 added(engine){
22
23 this.nodes = engine.getNodes(Ample);
24 this.adjusterContainer = settingsContainer({
25 id: 'amplitude-adjuster',
26 label: 'Amplitude'
27 });
28
29 let i = 0;
30 for (const node of this.nodes) {
31 const nodeElement = settingsContainer({
32 id: `amplitude-adjuster-${i}`,
33 label: ${i + 1}`,
34 level: 3
35 });
36
37 ['a', 'b', 'c'].forEach(key => {
38 nodeElement.appendChild(slider({
39 id: `amplitude-adjuster-${i}-slider-${key}`,
40 min: '0',
41 max: '1',
42 step: '0.01',
43 label: internals.symbols[key],
44 className: `amplitude`,
45 get: () => node.amplitude[key].toString(),
46 set: (value) => (node.amplitude[key] = parseFloat(value))
47 }));
48 });
49
50 this.adjusterContainer.appendChild(nodeElement);
51 ++i;
52 }
53
54 this.container.appendChild(this.adjusterContainer);
55 }
56
57 removed(){
58
59 this.container.removeChild(this.adjusterContainer);
60 delete this.adjusterContainer;
61 delete this.nodes;
62 }
63
64 update(){}
65 };