Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/maxwellmatthis/differential-equation-simulator
A small program and framework for visualizing physical objects moving around.
https://github.com/maxwellmatthis/differential-equation-simulator
2d animation differential-equations math physics
Last synced: about 2 months ago
JSON representation
A small program and framework for visualizing physical objects moving around.
- Host: GitHub
- URL: https://github.com/maxwellmatthis/differential-equation-simulator
- Owner: maxwellmatthis
- License: agpl-3.0
- Created: 2023-09-04T18:06:54.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-09-18T10:08:35.000Z (over 1 year ago)
- Last Synced: 2024-01-26T05:42:31.484Z (about 1 year ago)
- Topics: 2d, animation, differential-equations, math, physics
- Language: JavaScript
- Homepage:
- Size: 7.56 MB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# differential-equation-simulator
A small program and framework for visualizing physical objects moving around.
# How to Use - Example
```js
// make sure to update the names of these elements to your own
const engineTime = document.querySelector("span#engine-time");
const realTime = document.querySelector("span#real-time");
const fps = document.querySelector("span#fps");
/** @type {HTMLCanvasElement} */
const canvas = document.querySelector("canvas#view");import { Engine, Rect } from "./lib.js";
class ConstantX extends Rect {
constructor(ix, iy, dt, v = 40) {
super(ix, iy, dt);
this.registerCompute((dt) => {
this.x = this.x + v * dt; // s(t_2) = s(t_1) + s'(t_1) * (t_2 - t_1)
v *= this.verticalEdgeBounceFactor(v); // flips v_x vector when the `Rect` touches the left or right edge
});
}
}const engine = new Engine(canvas, [ new ConstantX(10, 20, 0.01) ]);
engine.registerHTMLComponents(engineTime, realTime, fps);
engine.run(50); // run the engine for 50s
```# Demo
https://github.com/maxwellmatthis/differential-equation-simulator/assets/58150536/de5732c8-a65b-43f0-8666-f14741d02c89