interface: <input type="number"> for particles

This commit is contained in:
root 2025-04-27 10:08:00 +00:00
parent be6d6ba000
commit 9194832b01
2 changed files with 31 additions and 14 deletions

View file

@ -20,6 +20,7 @@ let buttons_surface;
let checkbox_physics;
let checkbox_skeleton;
let checkbox_polytope;
let input_particles;
let aside_size;
@ -52,6 +53,9 @@ function setup() {
document.getElementById("button-surface-earth"),
]
buttons_surface[surface].disabled = true;
input_particles = document.getElementById("input-particles");
input_particles.valueAsNumber = particles.length;
}
function windowResized() {
@ -71,11 +75,15 @@ function draw() {
camera.centerZ = 0;
make_lights();
if (physics) move_particles(particles, 8e-4);
const polytope_is_slow = physics && particles.length > 40 || particles.length > 120;
const polytope_if_fast = polytope && !polytope_is_slow;
if (physics) {
move_particles(particles, 8e-4);
}
draw_particles(sphere_radius);
if (skeleton) draw_skeleton(sphere_radius);
if (polytope) {
if (polytope_if_fast) {
if (physics || faces.length === 0) find_faces();
draw_faces(sphere_radius);
}
@ -185,6 +193,8 @@ function draw_skeleton(radius) {
}
function make_particles(n) {
faces = [];
input_particles.value = `${n}`;
particles = [];
for (let i = 0; i < n; i += 1) {
let position;
@ -295,7 +305,6 @@ function keyPressed() {
toggle_polytope();
} else if (key >= '0' && key <= '9') {
make_particles(int(key));
faces = [];
}
}