]> git.r.bdr.sh - rbdr/lissajous/blob - lib/systems/amplitude_adjuster.js
71f72779b13fec0fd7497c39ca7dfdec8e82575d
[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 min: '0',
40 max: '1',
41 step: '0.01',
42 label: internals.symbols[key],
43 className: `amplitude`,
44 get: () => node.amplitude[key].toString(),
45 set: (value) => (node.amplitude[key] = parseFloat(value))
46 }));
47 });
48
49 this.adjusterContainer.appendChild(nodeElement);
50 ++i;
51 }
52
53 this.container.appendChild(this.adjusterContainer);
54 }
55
56 removed(){
57
58 this.container.removeChild(this.adjusterContainer);
59 delete this.adjusterContainer;
60 delete this.nodes;
61 }
62
63 update(){}
64 };