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
// Simulates simplified nuclear fission with uranium-235, neutrons, and boron control rods.
// === Basic Fission Mod ===
// 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 = {
color: "#4a7023", // dark green (uranium oxide green)
color: "#6faa3d", // Classic green uranium
behavior: behaviors.SOLID,
category: "Energy",
state: "solid",
@ -16,15 +15,20 @@ elements.uranium235 = {
// Remove incoming neutron
deletePixel(otherPixel.x, otherPixel.y);
// Increase heat
// Simulate heat
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;
for(let i = 0; i < count; i++) {
let x = pixel.x + Math.floor(Math.random() * 3) - 1;
let y = pixel.y + Math.floor(Math.random() * 3) - 1;
if(!isEmpty(x, y)) continue;
for (let i = 0; i < count; i++) {
let dx = Math.floor(Math.random() * 3) - 1;
let dy = Math.floor(Math.random() * 3) - 1;
let x = pixel.x + dx;
let y = pixel.y + dy;
if (!isEmpty(x, y)) continue;
createPixel("neutron", x, y);
}
}
@ -32,29 +36,39 @@ elements.uranium235 = {
}
};
// Neutron particle: moves around and disappears after 500 ticks.
elements.neutron = {
color: "#dcdcdc", // light gray / off-white
behavior: [
"M2|M1|M2",
"M1|DL|M1",
"M2|M1|M2"
],
category: "Energy",
state: "gas",
density: 0.001,
temp: 20,
tick: function(pixel) {
pixel._neutronLife = (pixel._neutronLife || 0) + 1;
if(pixel._neutronLife > 500) {
// --- Add to existing neutron, don't replace it ---
if (elements.neutron) {
// Extend tick behavior
let oldTick = elements.neutron.tick;
elements.neutron.tick = function(pixel) {
// Preserve old tick behavior
if (oldTick) oldTick(pixel);
// Lifespan decay (500 ticks)
if (!pixel._ticks) pixel._ticks = 0;
pixel._ticks++;
if (pixel._ticks > 500) {
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 = {
color: "#f5f0a1", // pale yellow
color: "#dcdcdc", // Light gray boron
behavior: behaviors.SOLID,
category: "Solids",
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;
}
}
}
}