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