1
0
mirror of https://github.com/osmarks/random-stuff synced 2025-09-10 14:26:00 +00:00

changes to things

This commit is contained in:
2023-02-05 21:59:30 +00:00
parent 723eb34e40
commit 307c513a9b
4 changed files with 139 additions and 6 deletions

View File

@@ -9,6 +9,7 @@
const centerY = canv.height / 2
const scale = 0.5
const G = 0.1
const stepsPerSecond = 1000
const vzero = [0, 0]
const vadd = ([a, b], [c, d]) => [a + c, b + d]
@@ -35,18 +36,27 @@
if (!timestamp) {
return
}
const timestep = (timestamp - previousPreviousTimestamp) / 1000
const deltaT = (timestamp - previousPreviousTimestamp) / 1000
const stepCount = Math.min(Math.ceil(deltaT * stepsPerSecond), 20)
const timestep = deltaT / stepCount
console.log(stepCount, deltaT)
for (let j = 0; j < stepCount; j++) {
for (const object of objects) {
object.x = vadd(object.x, vscale(timestep, object.v))
const F = vsum(objects.filter(x => x !== object).map(x =>
vscale(G * (object.m * x.m) * (vmag(vsub(object.x, x.x)) ** 2), vnorm(vsub(object.x, x.x)))
))
object.v = vadd(object.v, vscale(timestep, vscale(1 / object.m, F)))
//console.log(F, object.x, object.v)
}
}
ctx.fillStyle = "black"
ctx.fillRect(0, 0, canv.width, canv.height)
var i = 0
for (const object of objects) {
object.x = vadd(object.x, vscale(timestep, object.v))
const F = vsum(objects.filter(x => x !== object).map(x =>
vscale(G * (object.m * x.m) * (vmag(vsub(object.x, x.x)) ** 2), vnorm(vsub(object.x, x.x)))
))
object.v = vadd(object.v, vscale(timestep, vscale(1 / object.m, F)))
//console.log(F, object.x, object.v)
ctx.beginPath()
const disp = vscale(scale, object.x)