Physics Engine
Interactive WebGL simulation and source code analysis.
The Laboratory
Where logic meets runtime behavior.
Source Code
ParticleSystem.ts
class Particle {
constructor(x, y) {
this.pos = new Vector2(x, y);
this.vel = new Vector2(Math.random(), Math.random());
}
update() {
this.pos.add(this.vel);
if (this.pos.x > width || this.pos.x < 0) this.vel.x _= -1;
if (this.pos.y > height || this.pos.y < 0) this.vel.y _= -1;
}
} Runtime simulation
WebGL Particle Emitter
[WebGL Context Active]