xxxxxxxxxx
66
/*
----------------------------------
Based on Photon text motion illustration by Erik Van Blokland:
https://www.youtube.com/watch?v=WFYTGlLeUfY
+ Based on 3D Black Hole by Juan Carlos Ponce Campuzano:
https://github.com/jcponce/jcponce.github.io/tree/master/sketches/blackhole
++ ^Based on the Coding Train Challenge #144:
https://thecodingtrain.com/CodingChallenges/144-black-hole-visualization.html
with The p5.EasyCam library
https://github.com/diwi/p5.EasyCam
----------------------------------
*/
let myText = "Goodbye World"
let pg // offscreen drawing canvas
const c = 30 // "Speed of Light" constant
const G = 6 // "Universal Gravitational" constant
const m = 5000 // "Mass"
let camdist = 350 // Camera distance
let dt = .25 // Delta time step
let photons = []
let m87;
function setup() {
createCanvas(500, 500, WEBGL);
createEasyCam({distance:camdist});
// Set up offscreen text setting
pg = createGraphics(500,500)
pg.textSize(70)
pg.textAlign(CENTER, CENTER)
pg.background(123)
pg.text(myText, width/2, height/2)
// Push a photon if the offscreen pixel has text
// ---------------------------------------------
for (let i = 0; i < pg.width; i++) {
for (let j = 0; j < pg.height; j++) {
let pixRGBA = pg.get(i, j)
if (pixRGBA[0] < 120) {
photons.push(new Photon(i-width/2, j-height/2, camdist*1.25))
}
}
}
}
function draw() {
background(30);
m87 = new Blackhole(0, 0, 0, m);
m87.display();
for (let k = 0; k < photons.length; k++) {
let p = photons[k];
m87.pull(p)
p.update()
p.display()
}
}