]> git.r.bdr.sh - rbdr/lissajous/blob - lib/systems/frequency_adjuster.js
a3582bb2822e953db413a379747006d95a2a90ab
[rbdr/lissajous] / lib / systems / frequency_adjuster.js
1 import { System } from '@serpentity/serpentity';
2 import Frequent from '../nodes/frequent';
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 FrequencyAdjuster extends System {
14
15 constructor(container) {
16
17 super();
18 this.container = container;
19 }
20
21 added(engine){
22
23 this.nodes = engine.getNodes(Frequent);
24 this.adjusterContainer = settingsContainer({
25 id: 'frequency-adjuster',
26 label: 'Frequency'
27 })
28
29 let i = 0;
30 for (const node of this.nodes) {
31 const nodeElement = settingsContainer({
32 id: `frequency-adjuster-${i}`,
33 label: ${i + 1}`,
34 level: 3
35 });
36
37 ['a', 'b', 'c'].forEach(key => {
38 nodeElement.appendChild(slider({
39 id: `frequency-adjuster-${i}-slider-${key}`,
40 min: '0',
41 max: (2 * Math.PI).toString(),
42 step: '0.05',
43 shiftStep: (Math.PI / 8).toString(),
44 label: internals.symbols[key],
45 className: `frequency`,
46 get: () => node.frequency[key].toString(),
47 set: (value) => (node.frequency[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 };