mini changes

This commit is contained in:
root 2025-04-26 12:31:25 +00:00
parent eeb1beaea3
commit 2655d15bc9
2 changed files with 5 additions and 11 deletions

View file

@ -118,8 +118,8 @@ function draw_faces(radius) {
push(); push();
strokeWeight(2); strokeWeight(2);
stroke(0x00); stroke(0x00);
fill(0xbf, 0x7f);
for ([p1, p2, p3] of faces) { for ([p1, p2, p3] of faces) {
fill(0xbf, 0x7f);
beginShape(TRIANGLES); beginShape(TRIANGLES);
vertex(p1.x * radius, p1.y * radius, p1.z * radius); vertex(p1.x * radius, p1.y * radius, p1.z * radius);
vertex(p2.x * radius, p2.y * radius, p2.z * radius); vertex(p2.x * radius, p2.y * radius, p2.z * radius);
@ -155,13 +155,7 @@ function make_charges(n) {
if (i === 0) { if (i === 0) {
position = createVector(0, -1, 0); position = createVector(0, -1, 0);
} else { } else {
const lat = random(-TAU / 4, TAU / 4); position = p5.Vector.random3D();
const lon = random(0, TAU);
position = createVector(
cos(lat) * cos(lon),
sin(lat),
cos(lat) * sin(lon),
);
} }
charges.push({ charges.push({
position: position, position: position,

View file

@ -11,11 +11,11 @@ function move_charges(charges) {
let acceleration_mag = 1 / displacement.mag() * 0.001; let acceleration_mag = 1 / displacement.mag() * 0.001;
let ai; let ai;
if (acceleration_mag === Infinity) { if (acceleration_mag === Infinity) {
ai = createVector(random(-1, 1), random(-1, 1), random(-1, 1)); ai = p5.Vector.random3D();
} else { } else {
ai = displacement.copy(); ai = displacement.copy().normalize();
} }
ai = ai.normalize().mult(acceleration_mag); ai.mult(acceleration_mag);
let aj = p5.Vector.mult(ai, -1); let aj = p5.Vector.mult(ai, -1);
project_onto_plane(ai, charges[i].position); project_onto_plane(ai, charges[i].position);
project_onto_plane(aj, charges[j].position); project_onto_plane(aj, charges[j].position);