Black hole dynamic

Final Project: Dynamic of 2 supermassive blackhole

Inspiration
This project delves into the intricacies of simulating black holes’ gravitational influence on particles in a 2D space. Inspired by coding train and supermassive black hole and chaos behavior in astronophysic. With the music from rock band supermassive black hole, I would like to make an art with colorful trajectory created by the photons passing black holes

Techniques from decoding nature course
In this project, I use the knowledge I learnt from particle system, force and autonomous agent, as well as object orient programming. And the interaction part lies in the mouseclick and the operation of blackhole class and particle release and music start as the key board press.

Basic Setup
The setup() function initializes the canvas and GUI interface, allowing users to manipulate parameters such as black hole types, gravitational constant, particle count, and reset functionality.

let easycam;
let particles = [];
let blackHoles = [];
let controls = {
  type: 'Cylinder',
  c: 30,
  G: 6,
  m: 5000,
  Reset: function () {
    particles = [];
    blackHoles = [];
    initSketch();
  },
};

let pCount = 4000;
let lastTapTime = 0;
let lastTapPos;
let bgMusic;

Class of blackholes

Utilizing the Blackhole class, we represent black holes on the canvas based on their mass and Schwarzschild radius. The visualization showcases their gravitational influence by affecting the trajectories of nearby particles.

class Blackhole {
  constructor(x, y, m) {
    this.pos = createVector(x, y);
    this.mass = m;
    this.rs = (2 * controls.G * this.mass) / (controls.c * controls.c);
  }

  pull(photon) {
    const force = p5.Vector.sub(this.pos, photon.pos);
    const r = force.mag();
    const fg = (controls.G * this.mass) / (r * r);
    force.setMag(fg);
    photon.vel.add(force);
    photon.vel.setMag(controls.c);

    if (r < this.rs) {
      photon.stop();
    }
  }

 

Particle Behavior:
The Particle class defines particle behavior, including position, velocity, history of movement, and their interaction with black holes. Each particle’s trajectory is influenced by gravitational forces exerted by the black holes, leading to dynamic and visually engaging movements.

class Particle {
  constructor(pos, particleColor) {
    this.pos = pos;
    this.vel = p5.Vector.random2D();
    this.vel.setMag(controls.c);
    this.history = [];
    this.stopped = false;
    this.particleColor = particleColor; // Store the color of the particle
  }

  stop() {
    this.stopped = true;
  }

  update() {
    if (!this.stopped) {
      this.pos.add(this.vel);
      let v = createVector(this.pos.x, this.pos.y);
      this.history.push(v);
      if (this.history.length > 100) {
        this.history.splice(0, 1);
      }
    }
  }

 

Interactive Controls and Rendering:
Our project features an intuitive GUI interface allowing users to dynamically modify parameters, alter particle behavior, and manipulate black hole properties in real-time. This interactivity enhances user engagement and facilitates a deeper understanding of black hole dynamics.

  
  canvas.mouseClicked(addBlackHole);
}
function addBlackHole() {
  const currentTime = millis();
  const mousePos = createVector(mouseX - width / 2, mouseY - height / 2); if (currentTime - lastTapTime < 300 && dist(mousePos.x, mousePos.y, lastTapPos.x, lastTapPos.y) < 50) {
    // Double tap detected within 300ms and close proximity
    particles.push(new Particle(mousePos, color(random(255), random(255), random(255))));
  } else {
    
    blackHoles.push(new Blackhole(mouseX, mouseY, random(5000, 10000)));
  }

  lastTapTime = currentTime;
  lastTapPos = mousePos;
}

 

Physic logic behind particle and blackhole setup
newton second law and relativity

Leave a Reply

Your email address will not be published. Required fields are marked *