simple-circuit-engine 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,6 +1,86 @@
1
1
  # Simple Circuit Engine
2
2
 
3
- A simple electronic circuit edition and simulation engine written in typescript.
4
- Core module provides circuit data structure and simulation algorithms and scene module provides Three.js circuit scene creation and controls.
3
+ [![NPM Package][npm]][npm-url]
5
4
 
6
- TODO : complete the README.md
5
+ #### JavaScript Educational Electronic circuit library
6
+
7
+ The aim of the project is to provide a simple and easy to use electronic circuit simulation engine for educational purposes.
8
+ It allows users to create, edit and simulate electronic circuits in a web environment using [three.js](https://threejs.org/) for 3D rendering.
9
+
10
+ ![cover](docs/project-cover.png)
11
+
12
+ Visit the [Demo page](https://demo.beyondtheswitch.net/) to see the library in action.
13
+
14
+ ### Usage
15
+
16
+ In addition to `simple-circuit-engine` you must import the `three` and `lil-gui` libraries in your project to use Simple Circuit Engine.
17
+ This code set up the main CircuitEngine instance in edit mode on a new Circuit, handles THREE.js objects creation and rendering/animation in the canva-container HTML element.
18
+
19
+ ```javascript
20
+ import { WebGLRenderer } from 'three';
21
+
22
+ import {
23
+ Circuit,
24
+ BehaviorRegistry,
25
+ registerBasicComponentsBehaviors,
26
+ } from 'simple-circuit-engine/core';
27
+ import {
28
+ CircuitEngine,
29
+ FactoryRegistry,
30
+ DefaultVisualFactory,
31
+ registerBasicComponentsFactories,
32
+ } from 'simple-circuit-engine/scene';
33
+
34
+ // Initialize CircuitEngine
35
+ // It creates THREE.js scene, camera, controls, lights, etc
36
+ // and the interactive controllers (edit and simulation) of simple-circuit-engine
37
+ const width = window.innerWidth, height = window.innerHeight;
38
+
39
+ // Create component factory registry with all basic visual factories (for scene objects creation - rendering
40
+ const componentsFactoryRegistry = new FactoryRegistry(new DefaultVisualFactory());
41
+ registerBasicComponentsFactories(componentsFactoryRegistry);
42
+ // Create behavior registry with all basic component behaviors (for simulation)
43
+ const behaviorRegistry = new BehaviorRegistry();
44
+ registerBasicComponentsBehaviors(behaviorRegistry);
45
+ // Initialize CircuitEngine
46
+ const container = document.getElementById('canva-container')!;
47
+ const engine = new CircuitEngine(componentsFactoryRegistry, behaviorRegistry);
48
+ engine.initialize(container, {
49
+ initialMode: 'edit',
50
+ controllerOptions: {},
51
+ });
52
+ // set engine circuit to a new empty circuit
53
+ engine.setCircuit(new Circuit());
54
+
55
+ // THREE.js/WebGL standard rendering setup
56
+ // Create WebGL renderer
57
+ const renderer = new WebGLRenderer({ antialias: true, alpha: false });
58
+ renderer.setClearColor(0x1a1a2e);
59
+ // Setup WebGL renderer
60
+ renderer.setSize(container.clientWidth, container.clientHeight);
61
+ renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
62
+ // Append renderer to DOM
63
+ container.appendChild(renderer.domElement);
64
+ // Animation loop
65
+ function animate() {
66
+ requestAnimationFrame(animate);
67
+ engine.getControls().update();
68
+ renderer.render(engine.getScene(), engine.getCamera());
69
+ }
70
+ animate();
71
+ ```
72
+
73
+ If this goes well, you should see a 10\*10 3D grid with some lights and camera mapControls in the canvas container.
74
+
75
+ ### Contributing
76
+
77
+ Feel free to open issues or submit pull requests for bug fixes, improvements, or new features.
78
+ Particularly, since this project is at early stage issues reports and discussions about desired features are very welcome!
79
+ If you're interested in contributing, please read the [CONTRIBUTING](CONTRIBUTING.md) guide for more information.
80
+
81
+ ### License
82
+
83
+ This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
84
+
85
+ [npm]: https://img.shields.io/npm/v/simple-circuit-engine
86
+ [npm-url]: https://www.npmjs.com/package/simple-circuit-engine