-
Notifications
You must be signed in to change notification settings - Fork 0
/
sketch.js
47 lines (37 loc) · 1.01 KB
/
sketch.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
const c = 30;
const G = 3.54;
const dt = 0.1;
let m87;
const particles = [];
let start, end;
let slider;
function setup() {
createCanvas(windowWidth, windowHeight);
slider = createSlider(0, 255, 127);
slider.position(10, 10);
slider.style("width", "80px");
const diffParam = parseFloat(document.location.search.split("sp=")[1]);
const diff = isNaN(diffParam) ? 10 : diffParam;
const massParam = parseFloat(document.location.search.split("m=")[1]);
const mass = isNaN(massParam) ? 6500 : massParam;
m87 = new Blackhole(width / 8, height / 2, mass);
start = height / 2;
end = height / 2 - m87.rs * 2.6;
for (let y = 0; y < windowHeight; y += diff) {
particles.push(new Photon(width - 20, y));
}
}
function draw() {
background(slider.value(), 100);
stroke(0);
strokeWeight(1);
line(0, start, width, start);
line(0, end, width, end);
line(0, windowHeight - end, width, windowHeight - end);
for (let p of particles) {
m87.pull(p);
p.update();
p.show(end);
}
m87.show();
}