This commit is contained in:
root 2025-04-25 08:58:35 +00:00
parent 6cbdb04786
commit c20044c459

View file

@ -1,12 +1,13 @@
let charges = []; let charges = [];
let sphere_mode = 'circles';
let sphere_radius = 200; let sphere_radius = 200;
let physics = false; let physics = false;
let earth = false;
let skeleton = false;
function preload() { function preload() {
earth = loadImage("atlas1.jpg"); earth_image = loadImage("atlas1.jpg");
} }
function setup() { function setup() {
@ -21,10 +22,32 @@ function draw() {
if (physics) { if (physics) {
move_charges(charges); move_charges(charges);
} }
if (skeleton) {
draw_skeleton(sphere_radius);
}
draw_charges(sphere_radius); draw_charges(sphere_radius);
draw_sphere(sphere_radius, 25); draw_sphere(sphere_radius, 25);
} }
function draw_skeleton(radius) {
push();
noStroke();
fill(0xff);
sphere(4);
stroke(0xbf);
for (let charge of charges) {
line(
0,
0,
0,
charge.position.x * radius,
charge.position.y * radius,
charge.position.z * radius,
);
}
pop();
}
function make_charges(n) { function make_charges(n) {
charges = []; charges = [];
for (let i = 0; i < n; i += 1) { for (let i = 0; i < n; i += 1) {
@ -71,7 +94,7 @@ function draw_sphere(radius, n_axis_circles) {
rotateX(TAU / 4); rotateX(TAU / 4);
draw_circles( draw_circles(
radius, radius,
sphere_mode === 'earth' ? 2 : n_axis_circles, earth ? 2 : n_axis_circles,
color(0x00, 0x9f, 0xff), color(0x00, 0x9f, 0xff),
color(0xff, 0x9f, 0x00), color(0xff, 0x9f, 0x00),
); );
@ -80,17 +103,17 @@ function draw_sphere(radius, n_axis_circles) {
rotateY(TAU / 4); rotateY(TAU / 4);
draw_circles( draw_circles(
radius, radius,
sphere_mode === 'earth' ? 2 : n_axis_circles, earth ? 2 : n_axis_circles,
color(0xff, 0x00, 0xff), color(0xff, 0x00, 0xff),
color(0x00, 0xff, 0x00), color(0x00, 0xff, 0x00),
); );
pop(); pop();
if (sphere_mode === 'earth') { if (earth) {
noStroke(); noStroke();
noFill(); noFill();
tint(0xff, 0x9f); tint(0xff, 0x9f);
texture(earth); texture(earth_image);
push(); push();
rotateY(TAU / 4); rotateY(TAU / 4);
sphere(radius); sphere(radius);
@ -127,10 +150,12 @@ function make_lights() {
} }
function keyPressed() { function keyPressed() {
if (key == 'd') { if (key == ' ') {
sphere_mode = sphere_mode === 'earth' ? 'circles' : 'earth';
} else if (key == ' ') {
physics = !physics; physics = !physics;
} else if (key == 'd') {
earth = !earth;
} else if (key == 'f') {
skeleton = !skeleton;
} else if (key >= '0' && key <= '9') { } else if (key >= '0' && key <= '9') {
make_charges(int(key)); make_charges(int(key));
} }