From 2655d15bc94a2ca340ec211340d031de8770e661 Mon Sep 17 00:00:00 2001
From: root <>
Date: Sat, 26 Apr 2025 12:31:25 +0000
Subject: [PATCH 1/5] mini changes
---
sketch.js | 10 ++--------
thomson-problem.js | 6 +++---
2 files changed, 5 insertions(+), 11 deletions(-)
diff --git a/sketch.js b/sketch.js
index 1d3cb0a..3abce52 100644
--- a/sketch.js
+++ b/sketch.js
@@ -118,8 +118,8 @@ function draw_faces(radius) {
push();
strokeWeight(2);
stroke(0x00);
+ fill(0xbf, 0x7f);
for ([p1, p2, p3] of faces) {
- fill(0xbf, 0x7f);
beginShape(TRIANGLES);
vertex(p1.x * radius, p1.y * radius, p1.z * radius);
vertex(p2.x * radius, p2.y * radius, p2.z * radius);
@@ -155,13 +155,7 @@ function make_charges(n) {
if (i === 0) {
position = createVector(0, -1, 0);
} else {
- const lat = random(-TAU / 4, TAU / 4);
- const lon = random(0, TAU);
- position = createVector(
- cos(lat) * cos(lon),
- sin(lat),
- cos(lat) * sin(lon),
- );
+ position = p5.Vector.random3D();
}
charges.push({
position: position,
diff --git a/thomson-problem.js b/thomson-problem.js
index 0cbbdaa..8b8245c 100644
--- a/thomson-problem.js
+++ b/thomson-problem.js
@@ -11,11 +11,11 @@ function move_charges(charges) {
let acceleration_mag = 1 / displacement.mag() * 0.001;
let ai;
if (acceleration_mag === Infinity) {
- ai = createVector(random(-1, 1), random(-1, 1), random(-1, 1));
+ ai = p5.Vector.random3D();
} 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);
project_onto_plane(ai, charges[i].position);
project_onto_plane(aj, charges[j].position);
From 769043c5cb9b1531bbd24ecfcf3bc89fb089c5a2 Mon Sep 17 00:00:00 2001
From: root <>
Date: Sat, 26 Apr 2025 12:32:59 +0000
Subject: [PATCH 2/5] nicer sphere_radius on mobile
---
index.html | 3 +++
sketch.js | 22 ++++++++++++++++++----
2 files changed, 21 insertions(+), 4 deletions(-)
diff --git a/index.html b/index.html
index ff66bc9..dbaf619 100644
--- a/index.html
+++ b/index.html
@@ -6,6 +6,9 @@
p5.js
+
diff --git a/sketch.js b/sketch.js
index 238d16d..a04f4ac 100644
--- a/sketch.js
+++ b/sketch.js
@@ -15,6 +15,11 @@ let physics = false;
let skeleton = false;
let polytope = false;
+let buttons_surface;
+let checkbox_physics;
+let checkbox_skeleton;
+let checkbox_polytope;
+
let aside_size;
@@ -30,6 +35,22 @@ function setup() {
camera = createCamera();
red = color(0xbf, 0x00, 0x00);
sphere_radius = min(250, min(width, height) / 2 * 0.8);
+
+ checkbox_physics = document.getElementById("checkbox-physics");
+ checkbox_physics.checked = physics;
+
+ checkbox_skeleton = document.getElementById("checkbox-skeleton");
+ checkbox_skeleton.checked = skeleton;
+
+ checkbox_polytope = document.getElementById("checkbox-polytope");
+ checkbox_polytope.checked = polytope;
+
+ buttons_surface = [
+ document.getElementById("button-surface-none"),
+ document.getElementById("button-surface-circles"),
+ document.getElementById("button-surface-earth"),
+ ]
+ buttons_surface[surface].disabled = true;
}
function windowResized() {
@@ -263,15 +284,36 @@ function make_lights() {
function keyPressed() {
if (key == ' ') {
- physics = !physics;
+ toggle_physics();
} else if (key == 'd') {
- surface = (surface + 1) % 3;
+ set_surface((surface + 1) % 3);
} else if (key == 'f') {
- skeleton = !skeleton;
+ toggle_skeleton();
} else if (key == 'g') {
- polytope = !polytope;
+ toggle_polytope();
} else if (key >= '0' && key <= '9') {
make_charges(int(key));
faces = [];
}
}
+
+function toggle_physics() {
+ physics = !physics;
+ checkbox_physics.checked = physics;
+}
+
+function set_surface(value) {
+ surface = value;
+ for (let button of buttons_surface) button.disabled = false;
+ buttons_surface[value].disabled = true;
+}
+
+function toggle_skeleton() {
+ skeleton = !skeleton;
+ checkbox_skeleton.checked = skeleton;
+}
+
+function toggle_polytope() {
+ polytope = !polytope;
+ checkbox_polytope.checked = polytope;
+}
From 33aab6af5ca04ef675791539e211e744651a7830 Mon Sep 17 00:00:00 2001
From: root <>
Date: Sat, 26 Apr 2025 12:59:48 +0000
Subject: [PATCH 5/5] interface: noscript notice
---
index.html | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
diff --git a/index.html b/index.html
index ac7a1cb..45e21e7 100644
--- a/index.html
+++ b/index.html
@@ -9,6 +9,15 @@
:root {
--aside-size: 218px;
}
+.js {
+ display: none;
+}
+noscript {
+ padding: 10px;
+}
+a {
+ color: cornflowerblue;
+}
body {
padding: 0;
margin: 0;
@@ -57,7 +66,7 @@ aside > container > div {
-