Update fission_physics.js

new version from senseiollie
This commit is contained in:
pennylicker6 2025-08-04 16:41:07 -08:00 committed by GitHub
parent bb862f8889
commit dcb6488352
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 43 additions and 53 deletions

View File

@ -1,9 +1,8 @@
// Basic Fission Mod for Sandboxels // === Basic Fission Mod ===
// Simulates simplified nuclear fission with uranium-235, neutrons, and boron control rods.
// Uranium-235: emits 2-3 neutrons when hit by a neutron, heats up, no byproducts. this is by senseiollie. the creator // --- Fissionable Uranium-235 ---
elements.uranium235 = { elements.uranium235 = {
color: "#4a7023", // dark green (uranium oxide green) color: "#6faa3d", // Classic green uranium
behavior: behaviors.SOLID, behavior: behaviors.SOLID,
category: "Energy", category: "Energy",
state: "solid", state: "solid",
@ -16,15 +15,20 @@ elements.uranium235 = {
// Remove incoming neutron // Remove incoming neutron
deletePixel(otherPixel.x, otherPixel.y); deletePixel(otherPixel.x, otherPixel.y);
// Increase heat // Simulate heat
pixel.temp += 200 + Math.random() * 100; pixel.temp += 200 + Math.random() * 100;
// Emit 2-3 new neutrons nearby // Optional: transform uranium
changePixel(pixel, "lead");
// Emit 23 new neutrons
let count = Math.floor(Math.random() * 2) + 2; let count = Math.floor(Math.random() * 2) + 2;
for(let i = 0; i < count; i++) { for (let i = 0; i < count; i++) {
let x = pixel.x + Math.floor(Math.random() * 3) - 1; let dx = Math.floor(Math.random() * 3) - 1;
let y = pixel.y + Math.floor(Math.random() * 3) - 1; let dy = Math.floor(Math.random() * 3) - 1;
if(!isEmpty(x, y)) continue; let x = pixel.x + dx;
let y = pixel.y + dy;
if (!isEmpty(x, y)) continue;
createPixel("neutron", x, y); createPixel("neutron", x, y);
} }
} }
@ -32,29 +36,39 @@ elements.uranium235 = {
} }
}; };
// Neutron particle: moves around and disappears after 500 ticks. // --- Add to existing neutron, don't replace it ---
elements.neutron = { if (elements.neutron) {
color: "#dcdcdc", // light gray / off-white // Extend tick behavior
behavior: [ let oldTick = elements.neutron.tick;
"M2|M1|M2", elements.neutron.tick = function(pixel) {
"M1|DL|M1", // Preserve old tick behavior
"M2|M1|M2" if (oldTick) oldTick(pixel);
],
category: "Energy", // Lifespan decay (500 ticks)
state: "gas", if (!pixel._ticks) pixel._ticks = 0;
density: 0.001, pixel._ticks++;
temp: 20, if (pixel._ticks > 500) {
tick: function(pixel) {
pixel._neutronLife = (pixel._neutronLife || 0) + 1;
if(pixel._neutronLife > 500) {
deletePixel(pixel.x, pixel.y); deletePixel(pixel.x, pixel.y);
} }
} };
};
// Boron: solid that absorbs neutrons and heats up slightly. // Let neutron pass slower through water
elements.neutron.customTick = function(pixel) {
let dirs = [[0,1],[0,-1],[1,0],[-1,0]];
for (let dir of dirs) {
let x = pixel.x + dir[0];
let y = pixel.y + dir[1];
let other = pixelMap[x]?.[y];
if (other && other.element === "water" && Math.random() < 0.2) {
return; // Skip tick 20% of the time near water
}
}
};
}
// --- Boron absorbs neutrons ---
elements.boron = { elements.boron = {
color: "#f5f0a1", // pale yellow color: "#dcdcdc", // Light gray boron
behavior: behaviors.SOLID, behavior: behaviors.SOLID,
category: "Solids", category: "Solids",
state: "solid", state: "solid",
@ -70,27 +84,3 @@ elements.boron = {
} }
}; };
// Slow neutrons and some particles passing through water by 20%.
const slowThroughWater = ["neutron", "proton", "photon"];
for(let elem of slowThroughWater) {
if(elements[elem]) {
elements[elem].customTick = function(pixel) {
let waterNearby = false;
let dirs = [[0,1],[0,-1],[1,0],[-1,0]];
for(let dir of dirs) {
let x = pixel.x + dir[0];
let y = pixel.y + dir[1];
let other = pixelMap[x]?.[y];
if(other && other.element === "water") {
waterNearby = true;
break;
}
}
if(waterNearby && Math.random() < 0.2) {
// Skip tick to slow particle
return;
}
}
}
}