Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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.

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