xxxxxxxxxx
90
let m87
const c = 30
const G = 7
let photons = []
let captiveRange
let firstTime = true
let massEditor
let photonEditor
let spacingEditor
let trailEditor
const dt = 0.1
function firstSetup() {
let spacingConstant = 60
// massEditor = createSlider(100,10000,5000,100)
// photonEditor = createSlider(5,500,20,1)
// spacingEditor = createSlider(5,20,5,1)
// trailEditor = createSlider(0,1,1,1)
MassEdit()
PhotonEdit(spacingConstant)
SpacingEdit(spacingConstant)
TrailEdit(spacingConstant)
let resetBtn = createButton('Reset')
resetBtn.mousePressed(resetSketch)
resetBtn.position(windowWidth - resetBtn.width,0)
}
function setup() {
if (firstTime) {
firstSetup()
firstTime = false
}
let canvas = createCanvas(windowWidth,windowHeight - 50);
canvas.position(0,massEditor.y + massEditor.height + 5)
m87 = new BlackHole(width / 2, height / 2, int(massEditor.value()))
captiveRange = 12 * m87.radius
let photonNum = photonEditor.value()
let photonSpacing = spacingEditor.value()
let trailFlag = trailEditor.value()
for (i = 0; i <= photonNum; i++) {
photons.push(new Photon(- 5,height/2 - (i * photonSpacing),c,0,trailFlag))
}
}
function draw() {
background(255);
m87.show()
let photonsDone = 0
for (let p of photons) {
if (dist(m87.position.x,m87.position.y,p.position.x,p.position.y) < captiveRange){
let force = m87.pull(p)
}
if ((((width / 2) - 0.25 * m87.radius < p.position.x) && (p.position.x < (width / 2) + 0.25 * m87.radius) && ((height / 2) - 0.25 * m87.radius < p.position.y) && (p.position.y< (height / 2) + 0.25 * m87.radius)) || (-500 > p.position.x) || (width + 500 < p.position.x) || (-500 > p.position.y) || (height + 500 < p.position.y)) {
p.draw = false
p.history.push(m87.position.copy)
}
if (p.draw) {
p.update()
} else {
photonsDone += 1
}
p.show()
}
if (photonsDone == photons.length) {
resetSketch()
}
m87.showEventHorizon()
}
function resetSketch() {
photons.splice(0,photons.length)
setup()
}