Skip to content

Commit

Permalink
Smoother animation
Browse files Browse the repository at this point in the history
  • Loading branch information
ftripier committed Aug 31, 2018
1 parent 13d5b16 commit 2065bd5
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class Engine {

const canvas = <HTMLCanvasElement>document.getElementById("canvas");
const engine = new Engine(canvas);
const EPSILON = 1e-4;

function getCenter(state: State) {
return [state.width >> 1, state.height >> 1];
Expand Down Expand Up @@ -101,10 +102,10 @@ function update(state: State) {
}
const ballMass = 1;
const rodLength = 1;
const angluarVelocity = Math.PI * (1 / 128);
const angluarVelocity = Math.PI * (1 / 128) * (state.dt / (16 + 2 / 3));

state.system.alpha += angluarVelocity;
if (state.system.alpha == Math.PI * 2) {
if (Math.abs(state.system.alpha - Math.PI * 2) <= EPSILON) {
state.system.alpha = 0;
}
}
Expand Down

0 comments on commit 2065bd5

Please sign in to comment.