Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gravity visible #179

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/anybody.js
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,9 @@ export class Anybody extends EventEmitter {
// )
// this.bodies = bodies
// this.missiles = missiles || []
this.bodies = this.forceAccumulator(this.bodies)
const forceResults = this.forceAccumulator(this.bodies)
this.bodies = forceResults.bodies
this.forces = forceResults.forces
var results = this.detectCollision(this.bodies, this.missiles)
this.bodies = results.bodies
this.missiles = results.missiles || []
Expand Down
10 changes: 7 additions & 3 deletions src/calculations.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
export const Calculations = {
forceAccumulator(bodies = this.bodies) {
bodies = this.convertBodiesToBigInts(bodies)
bodies = this.forceAccumulatorBigInts(bodies)
const results = this.forceAccumulatorBigInts(bodies)
bodies = results.bodies
const forces = results.forces
bodies = this.convertBigIntsToBodies(bodies)
return bodies
return { bodies, forces }
},

// async circomStep(bodies, missiles) {
Expand Down Expand Up @@ -94,12 +96,14 @@ export const Calculations = {
for (let i = 0; i < bodies.length; i++) {
accumulativeForces.push([0n, 0n])
}
const forces = {}
const time = BigInt(this.speedFactor)
for (let i = 0; i < bodies.length; i++) {
const body = bodies[i]
for (let j = i + 1; j < bodies.length; j++) {
const otherBody = bodies[j]
const force = this.calculateForceBigInt(body, otherBody)
forces[i + '-' + j] = force
// const bodyVelocity = [
// body.radius == 0n
// ? 0n
Expand Down Expand Up @@ -185,7 +189,7 @@ export const Calculations = {
body.position.y = scaledWindowWidth
}
}
return bodies
return { bodies, forces }
},

calculateBodyFinal() {
Expand Down
1 change: 1 addition & 0 deletions src/nft.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ window.anybody
q5.setup = () => {
window.anybody = new Anybody(q5, {
mode: 'game',
level: 2,
// showLevels: true,
// target: 'inside',
// globalStyle: 'psycho',
Expand Down
27 changes: 27 additions & 0 deletions src/visuals.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ export const Visuals = {
// }
// }

if (this.forces) {
this.drawForces()
}

if (!this.firstFrame) {
this.drawBodies()
}
Expand Down Expand Up @@ -215,6 +219,29 @@ export const Visuals = {
}
this.firstFrame = false
},
drawForces() {
const { forces } = this
this.p.stroke('rgba(255,255,255,0.2)')
this.p.strokeCap(this.p.PROJECT)

for (const [key, value] of Object.entries(forces)) {
// Your code here
console.log({ key })
console.log({ value })
const bodyIndexes = key.split('-')
const body1 = this.bodies[bodyIndexes[0]]
const body2 = this.bodies[bodyIndexes[1]]
const force = Math.abs(parseInt(value[0] + value[1]))
console.log({ force })
this.p.strokeWeight(force)
this.p.line(
body1.position.x,
body1.position.y,
body2.position.x,
body2.position.y
)
}
},
drawPause() {
if (this.paused) {
this.p.fill('white')
Expand Down
3 changes: 2 additions & 1 deletion test/forceAccumulator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ describe('forceAccumulatorMain circuit', () => {
)
// console.dir({ bodies }, { depth: null })

const out_bodies = anybody
const results = anybody
const out_bodies = results.bodies
.forceAccumulatorBigInts(bodies)
.map(anybody.convertScaledBigIntBodyToArray.bind(anybody))
// console.log({ out_bodies })
Expand Down
3 changes: 2 additions & 1 deletion test/nftTest.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ describe.skip('nft circuit', () => {
)
// console.dir({ bodies }, { depth: null })
for (let i = 0; i < steps; i++) {
bodies = anybody.forceAccumulatorBigInts(bodies)
const results = anybody.forceAccumulatorBigInts(bodies)
bodies = results.bodies
}
const out_bodies = bodies.map(
anybody.convertScaledBigIntBodyToArray.bind(anybody)
Expand Down