xxxxxxxxxx
71
let m87
const c = 30
const G = 7
let photons = []
let captiveRange
const dt = 0.1
function setup() {
createCanvas(windowWidth,windowHeight - 50);
m87 = new BlackHole(width / 2, height / 2, 5000)
captiveRange = 12 * m87.radius
// photons.push(new Photon(-5, height/2 + 5.55*m87.radius,c,0))
// photons.push(new Photon(-5, height/2 - 5.55*m87.radius,c,0))
let photonNum = 20
let photonSpacing = 10
for (i = 0; i <= photonNum; i++) {
// if (i % 2 == 0) {
photons.push(new Photon(- 5,height/2 - (i * photonSpacing),c,0,true))
// } else {
// photons.push(new Photon(- 5,height/2 + (i * 2),c,0,false))
// }
}
// for (i = 0; i <= 180; i++) {
// let xSpeed = cos(i) * c
// let ySpeed = sin(i) * c
// photons.push(new Photon(150,height/2 ,xSpeed,ySpeed))
// }
frameRate(60)
}
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.5 * m87.radius < p.position.x) && (p.position.x < (width / 2) + 0.5 * m87.radius) && ((height / 2) - 0.5 * m87.radius < p.position.y) && (p.position.y< (height / 2) + 0.5 * m87.radius)) || (-250 > p.position.x) || (width + 250 < p.position.x) || (-250 > p.position.y) || (height + 250 < p.position.y)) {
p.draw = false
}
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()
}