]>
git.r.bdr.sh - rbdr/lissajous/blob - lib/main.js
60189578f817e292f9d1745c9a8e7ecb60d15607
1 import Serpentity
from '@serpentity/serpentity';
2 import { canvasId
, settingsId
, fps
} from './config';
5 import CameraRotator
from './systems/camera_rotator';
6 import WebGLRenderer
from './systems/webgl_renderer';
7 import LissajousPositionUpdater
from './systems/lissajous_position_updater';
8 import CameraAdjuster
from './systems/camera_adjuster';
9 import FrequencyAdjuster
from './systems/frequency_adjuster';
10 import AmplitudeAdjuster
from './systems/amplitude_adjuster';
11 import GlobalAdjuster
from './systems/global_adjuster';
14 import { lissajousCurve
} from './factories/curves';
15 import { camera
, configuration
} from './factories/global';
27 const engine
= new Serpentity();
30 engine
.addEntity(camera());
31 engine
.addEntity(lissajousCurve());
32 engine
.addEntity(configuration());
35 const canvas
= document
.getElementById(canvasId
);
36 const settings
= document
.getElementById(settingsId
);
39 engine
.addSystem(new CameraRotator());
40 engine
.addSystem(new LissajousPositionUpdater());
41 engine
.addSystem(new WebGLRenderer(canvas
));
43 // IMPROVEMENT NOTE: I believe adjusters can be generalized further.
44 // We could potentially have a factory for this.
45 engine
.addSystem(new GlobalAdjuster(settings
));
46 engine
.addSystem(new CameraAdjuster(settings
));
47 engine
.addSystem(new FrequencyAdjuster(settings
));
48 engine
.addSystem(new AmplitudeAdjuster(settings
));
50 internals
.engine
= engine
;
54 internals
.engine
= null;
59 const delta
= time
- internals
.currentTime
;
60 const interval
= 1000 / fps
;
62 if (delta
>= interval
) {
63 internals
.engine
.update(delta
);
64 internals
.currentTime
= time
;
67 internals
.started
&& window
.requestAnimationFrame(internals
.run
);
71 if (!internals
.started
) {
72 internals
.started
= true;
74 window
.requestAnimationFrame(internals
.run
);
79 if (internals
.started
) {
80 internals
.started
= false;