pause on import
This commit is contained in:
parent
a6f0f43683
commit
c2806c9ac4
2
deploy
2
deploy
@ -15,4 +15,4 @@ elif [[ $(hostname) == "lentilz" ]]; then
|
||||
fi
|
||||
|
||||
echo >&2
|
||||
echo >&2 "Deployed to https://laddhoffman.com/gravity/"
|
||||
echo >&2 "Deployed to https://gravity.laddhoffman.com"
|
||||
|
||||
@ -31,6 +31,9 @@ export class MassObject {
|
||||
forces = []; // [{x, y}]
|
||||
history = [];
|
||||
alive = true;
|
||||
kineticEnergy = 0;
|
||||
workDoneByPointer = 0;
|
||||
workDoneByForces = 0;
|
||||
|
||||
currentPosition = undefined;
|
||||
currentAcceleration = undefined;
|
||||
@ -56,7 +59,8 @@ export class MassObject {
|
||||
color: this.color,
|
||||
timeCreated: this.timeCreated,
|
||||
alive: this.alive,
|
||||
// TODO: optional export history
|
||||
workDoneByPointer: this.workDoneByPointer,
|
||||
workDoneByForces: this.workDoneByForces,
|
||||
};
|
||||
}
|
||||
|
||||
@ -69,8 +73,9 @@ export class MassObject {
|
||||
this.color = obj.color;
|
||||
this.timeCreated = obj.timeCreated;
|
||||
this.alive = obj.alive;
|
||||
// TODO: optional import history
|
||||
this.history = [];
|
||||
this.workDoneByPointer = obj.workDoneByPointer;
|
||||
this.workDoneByForces = obj.workDoneByForces;
|
||||
}
|
||||
|
||||
get age() {
|
||||
|
||||
@ -30,13 +30,12 @@ export class Panning {
|
||||
toJSON() {
|
||||
return {
|
||||
velocity: this.velocity,
|
||||
paused: this.paused,
|
||||
};
|
||||
}
|
||||
|
||||
fromJSON({velocity, paused}) {
|
||||
fromJSON({velocity}) {
|
||||
this.velocity = copy(velocity);
|
||||
this.paused = paused;
|
||||
this.paused = true;
|
||||
}
|
||||
|
||||
handlePointerDown({x, y}) {
|
||||
|
||||
@ -141,6 +141,7 @@ export class Sim {
|
||||
}
|
||||
|
||||
fromJSON(state) {
|
||||
this.pause();
|
||||
this.system.fromJSON(state.system);
|
||||
this.panning.fromJSON(state.panning);
|
||||
this.display.fromJSON(state.display);
|
||||
|
||||
4
sync
4
sync
@ -16,9 +16,9 @@ do_rsync() {
|
||||
}
|
||||
|
||||
do_rsync ~/code/gravity-dev/ lentilz:code/gravity-dev/
|
||||
do_rsync lentilz:code/gravity-dev/ ~/code/gravity-dev/
|
||||
# do_rsync lentilz:code/gravity-dev/ ~/code/gravity-dev/
|
||||
|
||||
git status
|
||||
|
||||
echo >&2
|
||||
echo >&2 "Synced with https://laddhoffman.com/gravity-dev/"
|
||||
echo >&2 "Synced with https://gravity.dev.laddhoffman.com"
|
||||
|
||||
13
system.js
13
system.js
@ -171,8 +171,8 @@ export class System {
|
||||
const delta = sub(obj.currentPosition, obj.position);
|
||||
const netForce = mult(obj.acceleration, obj.mass);
|
||||
const work = dot(netForce, delta);
|
||||
console.log('work', work);
|
||||
obj.position = obj.currentPosition;
|
||||
obj.workDoneByPointer += work;
|
||||
}
|
||||
|
||||
// Append to object history
|
||||
@ -408,11 +408,20 @@ export class System {
|
||||
// Equal and opposite forces
|
||||
A.forces.push({x: Fx, y: Fy});
|
||||
B.forces.push({x: -Fx, y: -Fy});
|
||||
if (A.currentPosition && B.currentPosition) {
|
||||
A.workDoneByForces += dot({x: Fx, y: Fy}, sub(A.position, A.currentPosition));
|
||||
B.workDoneByForces += dot({x: Fx, y: Fy}, sub(B.position, B.currentPosition));
|
||||
}
|
||||
}, {alive: true, startWith: i + 1});
|
||||
});
|
||||
// Also compute acceleration
|
||||
|
||||
// Additional computations
|
||||
this.forEachObject(obj => {
|
||||
// Acceleration
|
||||
obj.acceleration = obj.getAcceleration();
|
||||
|
||||
// Kinetic Energy
|
||||
obj.kineticEnergy = obj.mass * square(obj.velocity) / 2;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
import {hide, show} from '../helper.js';
|
||||
import {Tool} from '../tool.js';
|
||||
import {add, magnitude, sub} from '../vector.js';
|
||||
|
||||
export class ObjectsTool extends Tool {
|
||||
objects = [];
|
||||
@ -58,17 +57,22 @@ export class ObjectsTool extends Tool {
|
||||
obj.objectsToolEl = objectEl;
|
||||
const {r, g, b} = obj.color;
|
||||
// Distance from center of screen
|
||||
const distance = magnitude(sub(obj.position, add(this.sim.display.viewOrigin, {
|
||||
x: this.sim.display.width / 2,
|
||||
y: this.sim.display.height / 2,
|
||||
})));
|
||||
objectEl.innerHTML = `
|
||||
<span style="background-color: rgb(${r},${g},${b});">` +
|
||||
' </span>' +
|
||||
`${obj.mass.toPrecision(3)} ` +
|
||||
`${distance.toPrecision(3)}`;
|
||||
// const distance = magnitude(sub(obj.position, add(this.sim.display.viewOrigin, {
|
||||
// x: this.sim.display.width / 2,
|
||||
// y: this.sim.display.height / 2,
|
||||
// })));
|
||||
objectEl.innerHTML =
|
||||
`<span style="background-color: rgb(${r},${g},${b});"> </span>` +
|
||||
`E<sub>k</sub>: ${obj.kineticEnergy.toExponential(1)}` +
|
||||
`<br> W<sub>p</sub>: ${obj.workDoneByPointer.toExponential(1)}` +
|
||||
`<br> W<sub>f</sub>: ${obj.workDoneByForces.toExponential(1)}`;
|
||||
|
||||
// `${obj.mass.toPrecision(3)} ` +
|
||||
// `${distance.toPrecision(3)}`;
|
||||
|
||||
// `${magnitude(obj.velocity).toExponential(0)} ` +
|
||||
// `${-degrees(direction(obj.velocity)).toFixed(0)}°`;
|
||||
|
||||
if (!obj.hidden) {
|
||||
show({
|
||||
items: this.objects,
|
||||
|
||||
@ -56,7 +56,6 @@ export class StateTool extends Tool {
|
||||
throw new Error('state query parameter does not match digest query parameter');
|
||||
}
|
||||
// Tools in this system can be very powerful
|
||||
this.sim.pause();
|
||||
this.sim.fromJSON(state);
|
||||
}
|
||||
}
|
||||
@ -99,7 +98,6 @@ export class StateTool extends Tool {
|
||||
load.addEventListener('click', (e) => {
|
||||
e.preventDefault();
|
||||
// Tools in this system can wield great power
|
||||
this.sim.pause();
|
||||
this.sim.fromJSON(state);
|
||||
});
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user