xxxxxxxxxx
53
let particles = [];
const vMaxInit = 200;
let dT = 0.00001;
const sc = 180;
let pMax = 100;
const G = 10;
const C = 10000;
let showLines = 0;
function setup() {
createCanvas(400, 400);
for (let p = 0; p < pMax; p++) {
particles.push(new Particle());
}
}
function draw() {
background(220);
//noStroke();
//text(frameRate().toFixed(0),10,20);
translate(width / 2, height / 2);
noStroke();
fill(100);
// ellipse(0,0,2*sc,2*sc);
if (showLines === 1) {
for (let p = 0; p < pMax - 1; p++) {
for (let q = p + 1; q < pMax; q++) {
let d = p5.Vector.sub(particles[p].pos, particles[q].pos).mag();
if (d < 0.5) {
d = d / 0.5;
stroke(0, 255 * (1 - d));
strokeWeight(1);
line(sc * particles[p].pos.x, sc * particles[p].pos.y, sc * particles[q].pos.x, sc * particles[q].pos.y);
}
}
}
}
for (let p = 0; p < pMax; p++) {
particles[p].update(particles);
particles[p].show();
}
}
function keyPressed() {
if (key === 'm') {
dT *= 1.1;
} else if (key === 'n') {
dT /= 1.1;
} else if (key === 'l') {
showLines = (showLines + 1) % 2;
}
}