Merge branch 'main' of https://github.com/JustAGenericUsername/sandboxelsmodding
This commit is contained in:
commit
bda8202e92
|
|
@ -11,9 +11,11 @@ cc_settingsTab.registerSettings("OverHeating", cc_setting1);
|
|||
//cc_settingsTab.registerSettings("Setting 2", cc_setting2);
|
||||
settingsManager.registerTab(cc_settingsTab);
|
||||
|
||||
var dataVisualizationPalette16 = [
|
||||
"#000000", "#ff0000", "#ff7700", "#ffff00", "#00ff00", "#00ffff", "#0000ff", "#ff00ff",
|
||||
"#777777", "#770000", "#773300", "#777700", "#007700", "#007777", "#000077", "#770077",
|
||||
var colorPalette_4bit = [
|
||||
"#101820", "#37175F", "#5F1717", "#6F175F",
|
||||
"#005F00", "#1563BF", "#7F401A", "#525252",
|
||||
"#8F8F8F", "#EE8822", "#FF3027", "#FF47FF",
|
||||
"#58E618", "#27FFDF", "#FFFF27", "#FFFFFF"
|
||||
];
|
||||
|
||||
function hueLerp(value) {
|
||||
|
|
@ -217,6 +219,61 @@ function setPin(pixel, pins, index, value, rotation=pixel.circuitRotation) {
|
|||
}
|
||||
|
||||
// Circuits
|
||||
elements.four_bit_selector_circuit = {
|
||||
cc_stableTick: function(pixel) {
|
||||
var pins = [
|
||||
// First 4-bit input (A)
|
||||
[-1, -2, true], // A0
|
||||
[-3, -2, true], // A1
|
||||
[-5, -2, true], // A2
|
||||
[-7, -2, true], // A3
|
||||
|
||||
// Second 4-bit input (B)
|
||||
[7, -2, true], // B0
|
||||
[5, -2, true], // B1
|
||||
[3, -2, true], // B2
|
||||
[1, -2, true], // B3
|
||||
|
||||
// Selection pin (Sel)
|
||||
[9, 0, true], // Selection (Sel)
|
||||
|
||||
// Output (O)
|
||||
[-3, 2, false], // O0 (centered)
|
||||
[-1, 2, false], // O1 (centered)
|
||||
[1, 2, false], // O2 (centered)
|
||||
[3, 2, false], // O3 (centered)
|
||||
];
|
||||
|
||||
initializeCircuit(pixel, pins, 17, 3);
|
||||
|
||||
// Read inputs
|
||||
var A = [
|
||||
checkPin(pixel, pins, 0),
|
||||
checkPin(pixel, pins, 1),
|
||||
checkPin(pixel, pins, 2),
|
||||
checkPin(pixel, pins, 3)
|
||||
];
|
||||
|
||||
var B = [
|
||||
checkPin(pixel, pins, 4),
|
||||
checkPin(pixel, pins, 5),
|
||||
checkPin(pixel, pins, 6),
|
||||
checkPin(pixel, pins, 7)
|
||||
];
|
||||
|
||||
var Sel = checkPin(pixel, pins, 8); // Selection pin
|
||||
|
||||
// Select between A and B based on Sel
|
||||
var output = Sel ? B : A;
|
||||
|
||||
// Output the selected 4-bit value
|
||||
setPin(pixel, pins, 9, output[0]); // O0
|
||||
setPin(pixel, pins, 10, output[1]); // O1
|
||||
setPin(pixel, pins, 11, output[2]); // O2
|
||||
setPin(pixel, pins, 12, output[3]); // O3
|
||||
}
|
||||
};
|
||||
|
||||
elements.four_bit_enabler_circuit = {
|
||||
centered: true,
|
||||
cc_stableTick: function(pixel) {
|
||||
|
|
@ -442,9 +499,9 @@ elements.temperature_sensor = {
|
|||
var cellData = pixel.romData[cellAddress];
|
||||
if (!(0 <= px && px < width && 0 <= py && py < height)) {continue;}
|
||||
|
||||
if (pixelMap[px][py] && pixelMap[px][py].element == "art") {
|
||||
if (pixelMap[px][py] && pixelMap[px][py].element == "displayPixel") {
|
||||
// if (address == cellAddress) {}
|
||||
pixelMap[px][py].color = dataVisualizationPalette16[binaryArrayToNumber(cellData)];
|
||||
pixelMap[px][py].color = colorPalette_4bit[binaryArrayToNumber(cellData)];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1277,6 +1334,70 @@ elements.four_bit_adder_circuit = {
|
|||
}
|
||||
};
|
||||
|
||||
elements.four_bit_subtractor_circuit = {
|
||||
cc_stableTick: function(pixel) {
|
||||
var pins = [
|
||||
// First 4-bit number (A)
|
||||
[-1, -2, true], // A3
|
||||
[-3, -2, true], // A2
|
||||
[-5, -2, true], // A1
|
||||
[-7, -2, true], // A0
|
||||
|
||||
// Second 4-bit number (B)
|
||||
[7, -2, true], // B3
|
||||
[5, -2, true], // B2
|
||||
[3, -2, true], // B1
|
||||
[1, -2, true], // B0
|
||||
|
||||
// Borrow-in (B_in)
|
||||
[9, 0, true], // Borrow-in (B_in)
|
||||
|
||||
// Output difference (D)
|
||||
[-1, 2, false], // D3
|
||||
[-3, 2, false], // D2
|
||||
[-5, 2, false], // D1
|
||||
[-7, 2, false], // D0
|
||||
[1, 2, false], // Borrow Out (B4)
|
||||
];
|
||||
|
||||
initializeCircuit(pixel, pins, 17, 3);
|
||||
|
||||
// Read inputs
|
||||
var A = [
|
||||
checkPin(pixel, pins, 0),
|
||||
checkPin(pixel, pins, 1),
|
||||
checkPin(pixel, pins, 2),
|
||||
checkPin(pixel, pins, 3)
|
||||
];
|
||||
|
||||
var B = [
|
||||
checkPin(pixel, pins, 4),
|
||||
checkPin(pixel, pins, 5),
|
||||
checkPin(pixel, pins, 6),
|
||||
checkPin(pixel, pins, 7)
|
||||
];
|
||||
|
||||
var B_in = checkPin(pixel, pins, 8); // Borrow-in
|
||||
|
||||
// Calculate the difference and borrow
|
||||
var difference = [];
|
||||
var borrow = B_in;
|
||||
|
||||
for (var i = 0; i < 4; i++) {
|
||||
var bitDifference = A[i] - B[i] - borrow;
|
||||
difference[i] = (bitDifference + 2) % 2; // Current bit difference
|
||||
borrow = bitDifference < 0 ? 1 : 0; // Borrow for next bit
|
||||
}
|
||||
|
||||
// Output the difference
|
||||
setPin(pixel, pins, 9, difference[0]); // D0
|
||||
setPin(pixel, pins, 10, difference[1]); // D1
|
||||
setPin(pixel, pins, 11, difference[2]); // D2
|
||||
setPin(pixel, pins, 12, difference[3]); // D3
|
||||
setPin(pixel, pins, 13, borrow); // Borrow Out (B4)
|
||||
}
|
||||
};
|
||||
|
||||
function general_clock(speed, s2) {
|
||||
return function(pixel){
|
||||
for (var i = 0; i < adjacentCoords.length; i++) {
|
||||
|
|
@ -1343,6 +1464,7 @@ elements.custom_RGB_led = {
|
|||
];
|
||||
|
||||
var color = { color: cc_scaleList([(l[0] * 2) + l[1], (l[2] * 2) + l[3], (l[4] * 2) + l[5]], (255 / 3) * 10) };
|
||||
if (color.color.some(value => isNaN(value))) {return;}
|
||||
|
||||
if (lightmapEnabled && color.color[0] && color.color[1], color.color[2]) {
|
||||
lightmap[Math.floor(pixel.y / lightmapScale)][Math.floor(pixel.x / lightmapScale)] = color;
|
||||
|
|
@ -1372,7 +1494,7 @@ var addDisplayCallback = function(pixel, pins, w, h) {
|
|||
if (!(0 <= px && px < width && 0 <= py && py < height)) {continue;}
|
||||
|
||||
deletePixel(px, py);
|
||||
createPixel("art", px, py);
|
||||
createPixel("displayPixel", px, py);
|
||||
pixelMap[px][py].color = "rgb(16, 24, 32)";
|
||||
}
|
||||
}
|
||||
|
|
@ -1408,7 +1530,7 @@ elements.simple_seven_segment_display = {
|
|||
var px = pixel.x + x;
|
||||
var py = pixel.y + y;
|
||||
|
||||
if (pixelMap[px][py] && pixelMap[px][py].element == "art") {
|
||||
if (pixelMap[px][py] && pixelMap[px][py].element == "displayPixel") {
|
||||
if (hexGrid[y - 2][x - 1]) {
|
||||
pixelMap[px][py].color = "rgb(16, 230, 120)";
|
||||
} else {
|
||||
|
|
@ -1460,7 +1582,7 @@ elements.simple_double_seven_segment_display = {
|
|||
var px = pixel.x + x;
|
||||
var py = pixel.y + y;
|
||||
|
||||
if (pixelMap[px][py] && pixelMap[px][py].element == "art") {
|
||||
if (pixelMap[px][py] && pixelMap[px][py].element == "displayPixel") {
|
||||
if (hexGrid[y - 2][x - 1]) {
|
||||
pixelMap[px][py].color = "rgb(16, 230, 120)";
|
||||
} else {
|
||||
|
|
@ -1476,7 +1598,7 @@ elements.simple_double_seven_segment_display = {
|
|||
var px = pixel.x + x;
|
||||
var py = pixel.y + y;
|
||||
|
||||
if (pixelMap[px][py] && pixelMap[px][py].element == "art") {
|
||||
if (pixelMap[px][py] && pixelMap[px][py].element == "displayPixel") {
|
||||
if (hexGrid2[y - 2][x - 5]) {
|
||||
pixelMap[px][py].color = "rgb(16, 230, 120)";
|
||||
} else {
|
||||
|
|
@ -1488,117 +1610,6 @@ elements.simple_double_seven_segment_display = {
|
|||
}
|
||||
};
|
||||
|
||||
function general_display(w, h) {
|
||||
return function(pixel) {
|
||||
var pins = [];
|
||||
|
||||
// X input (X0-Xn)
|
||||
for (var i = 0; i < Math.ceil(Math.log2(w)); i++) {
|
||||
pins.push([-1, (Math.ceil(Math.log2(w)) - i) * 2 - 1, true]);
|
||||
}
|
||||
|
||||
// Y input (Y0-Yn)
|
||||
for (var i = 0; i < Math.ceil(Math.log2(h)); i++) {
|
||||
pins.push([(Math.ceil(Math.log2(h)) - i) * 2 - 1, -1, true]);
|
||||
}
|
||||
|
||||
// Color input
|
||||
pins.push([11, -1, true]);
|
||||
|
||||
// Reset pin
|
||||
pins.push([13, -1, true]);
|
||||
|
||||
// Clock input
|
||||
pins.push([15, -1, true]);
|
||||
|
||||
// Initialize the circuit with the necessary pins
|
||||
initializeCircuit(pixel, pins, w + 2, h + 2, false, pixel.circuitRotation, addDisplayCallback);
|
||||
|
||||
// Read inputs
|
||||
var X = [];
|
||||
for (var i = 0; i < Math.ceil(Math.log2(w)); i++) {
|
||||
X.push(checkPin(pixel, pins, i));
|
||||
}
|
||||
|
||||
var Y = [];
|
||||
for (var i = 0; i < Math.ceil(Math.log2(h)); i++) {
|
||||
Y.push(checkPin(pixel, pins, Math.ceil(Math.log2(w)) + i));
|
||||
}
|
||||
|
||||
var color = checkPin(pixel, pins, pins.length - 3);
|
||||
var reset = checkPin(pixel, pins, pins.length - 2);
|
||||
var clock = checkPin(pixel, pins, pins.length - 1);
|
||||
|
||||
// Decode X and Y inputs to determine the pixel position
|
||||
var x_pos = 0;
|
||||
for (var i = 0; i < X.length; i++) {
|
||||
x_pos += (X[i] ? 1 : 0) << i;
|
||||
}
|
||||
|
||||
var y_pos = 0;
|
||||
for (var i = 0; i < Y.length; i++) {
|
||||
y_pos += (Y[i] ? 1 : 0) << i;
|
||||
}
|
||||
|
||||
// Display dimension check
|
||||
if (x_pos >= w || y_pos >= h) return;
|
||||
|
||||
var px = pixel.x + 1 + x_pos; // Adjust for the display position
|
||||
var py = pixel.y + 1 + y_pos;
|
||||
|
||||
// Handle reset functionality
|
||||
if (reset) {
|
||||
for (var y = 1; y <= h; y++) {
|
||||
for (var x = 1; x <= w; x++) {
|
||||
var reset_px = pixel.x + x;
|
||||
var reset_py = pixel.y + y;
|
||||
if (pixelMap[reset_px] && pixelMap[reset_px][reset_py] && pixelMap[reset_px][reset_py].element == "art") {
|
||||
pixelMap[reset_px][reset_py].color = "rgb(16, 230, 120)";
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Update display on clock pulse
|
||||
if (clock) {
|
||||
if (pixelMap[px] && pixelMap[px][py] && pixelMap[px][py].element == "art") {
|
||||
// Set the pixel color
|
||||
pixelMap[px][py].color = color ? "rgb(16, 230, 120)" : "rgb(16, 230, 120)";
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
elements.basic_mono_display_8x8 = {
|
||||
cc_stableTick: general_display(8, 8),
|
||||
};
|
||||
|
||||
elements.basic_mono_display_16x8 = {
|
||||
cc_stableTick: general_display(16, 8),
|
||||
};
|
||||
|
||||
elements.basic_mono_display_16x16 = {
|
||||
cc_stableTick: general_display(16, 16),
|
||||
};
|
||||
|
||||
elements.basic_mono_display_32x16 = {
|
||||
cc_stableTick: general_display(32, 16),
|
||||
};
|
||||
|
||||
elements.basic_mono_display_32x32 = {
|
||||
cc_stableTick: general_display(32, 32),
|
||||
};
|
||||
|
||||
elements.basic_mono_display_64x32 = {
|
||||
cc_stableTick: general_display(64, 32),
|
||||
};
|
||||
|
||||
elements.basic_mono_display_64x64 = {
|
||||
cc_stableTick: general_display(64, 64),
|
||||
};
|
||||
|
||||
|
||||
function malfunction_chip(pixel) {
|
||||
var emptySpaces = [];
|
||||
|
||||
|
|
@ -1629,18 +1640,23 @@ function malfunction_chip(pixel) {
|
|||
}
|
||||
}
|
||||
|
||||
//elements.display = {
|
||||
// color: "#444444",
|
||||
// category: "logic",
|
||||
// state: "solid",
|
||||
// behavior: behaviors.WALL,
|
||||
// hoverStat: function(pixel) {
|
||||
// return `Circuit: ${pixel.corePosition}`;
|
||||
// },
|
||||
// cc_stableTick: function(pixel) {
|
||||
//
|
||||
// }
|
||||
//};
|
||||
elements.displayPixel = {
|
||||
color: "#000000",
|
||||
category: "logic",
|
||||
state: "solid",
|
||||
behavior: behaviors.WALL,
|
||||
tick: function(pixel) {
|
||||
if (pixel.start == pixelTicks) {
|
||||
pixel.color = "rgb(16, 24, 32)";
|
||||
}
|
||||
|
||||
if (lightmapEnabled && pixel.color) {
|
||||
var x = Math.floor(pixel.x / lightmapScale);
|
||||
var y = Math.floor(pixel.y / lightmapScale);
|
||||
lightmap[y][x] = { color: scaleList(rgbToArray(pixel.color), 0.2) };
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
elements.circuit_material = {
|
||||
color: "#444444",
|
||||
|
|
@ -1777,13 +1793,24 @@ elements.logic_corrupter_machine = {
|
|||
},
|
||||
}
|
||||
|
||||
elements.circuitCoreTutorial = {
|
||||
color: "#33FF66",
|
||||
category: "logic",
|
||||
onSelect: function() {
|
||||
window.open("https://redbirdly.github.io/circuitcore_tutorial.html");
|
||||
},
|
||||
}
|
||||
// Create a new anchor element
|
||||
var tutorialLink = document.createElement("a");
|
||||
|
||||
// Set the link's text content
|
||||
tutorialLink.textContent = "CircuitCore Tutorial";
|
||||
|
||||
// Set the link's href attribute to point to the tutorial
|
||||
tutorialLink.href = "https://redbirdly.github.io/circuitcore_tutorial.html";
|
||||
|
||||
// Set the link to open in a new tab
|
||||
tutorialLink.target = "_blank";
|
||||
|
||||
// Style the link (optional)
|
||||
tutorialLink.style.color = "#33FF66"; // Set the color of the link
|
||||
tutorialLink.style.fontSize = "14px"; // Set the font size
|
||||
|
||||
// Append the link to the body of the webpage
|
||||
document.body.appendChild(tutorialLink);
|
||||
|
||||
// cc_ is circuit core prefix
|
||||
const cc_BROWN = "#773317";
|
||||
|
|
@ -1800,6 +1827,7 @@ const cc_WHITE = "#DDDDDD";
|
|||
|
||||
var circuits = [
|
||||
// Misc and I/O: brown
|
||||
{ circuit: elements.four_bit_selector_circuit, color: cc_BROWN, size: [17, 3, true] },
|
||||
{ circuit: elements.four_bit_enabler_circuit, color: cc_BROWN, size: [9, 3, true] },
|
||||
{ circuit: elements.randomizer, color: cc_BROWN },
|
||||
{ circuit: elements.four_bit_randomizer_circuit, color: cc_BROWN, size: [9, 3, true] },
|
||||
|
|
@ -1841,6 +1869,7 @@ var circuits = [
|
|||
{ circuit: elements.four_bit_D_flip_flop_circuit, color: cc_LIGHT_BLUE, size: [9, 3, true] },
|
||||
// Addition/subtraction arithmetic: blue
|
||||
{ circuit: elements.four_bit_adder_circuit, color: cc_BLUE, size: [17, 3, true] },
|
||||
{ circuit: elements.four_bit_subtractor_circuit, color: cc_BLUE, size: [17, 3, true] },
|
||||
{ circuit: elements.four_bit_incrementer_circuit, color: cc_BLUE, size: [9, 3, true] },
|
||||
// Complex circuits: lavender
|
||||
// Clocks: pink
|
||||
|
|
@ -1852,13 +1881,6 @@ var circuits = [
|
|||
{ circuit: elements.simple_seven_segment_display, color: cc_WHITE, size: [5, 9, false] },
|
||||
{ circuit: elements.simple_double_seven_segment_display, color: cc_WHITE, size: [9, 9, false] },
|
||||
{ circuit: elements.custom_RGB_led, color: cc_WHITE, size: [3, 3, true] },
|
||||
{ circuit: elements.basic_mono_display_8x8, color: cc_WHITE, size: [10, 10, false] },
|
||||
{ circuit: elements.basic_mono_display_16x8, color: cc_WHITE, size: [18, 10, false] },
|
||||
{ circuit: elements.basic_mono_display_16x16, color: cc_WHITE, size: [18, 18, false] },
|
||||
{ circuit: elements.basic_mono_display_32x16, color: cc_WHITE, size: [34, 18, false] },
|
||||
{ circuit: elements.basic_mono_display_32x32, color: cc_WHITE, size: [34, 34, false] },
|
||||
{ circuit: elements.basic_mono_display_64x32, color: cc_WHITE, size: [66, 34, false] },
|
||||
{ circuit: elements.basic_mono_display_64x64, color: cc_WHITE, size: [66, 66, false] },
|
||||
];
|
||||
|
||||
circuits.forEach(circuitInfo => {
|
||||
|
|
@ -1947,15 +1969,28 @@ function drawCircuitExtras() {
|
|||
}
|
||||
|
||||
function runLogicTick() {
|
||||
for (var i = 0;i < currentPixels.length;i++) {
|
||||
var pixel = currentPixels[i];
|
||||
if (elements[pixel.element].category == "logic") {
|
||||
if (elements[pixel.element].cc_stableTick) {
|
||||
elements[pixel.element].cc_stableTick(pixel);
|
||||
if (paused) {return;}
|
||||
for (var j = 0;j < 1;j++) {
|
||||
for (var i = 0;i < currentPixels.length;i++) {
|
||||
var pixel = currentPixels[i];
|
||||
if (elements[pixel.element].category == "logic") {
|
||||
if (elements[pixel.element].cc_stableTick) {
|
||||
elements[pixel.element].cc_stableTick(pixel);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function stabilizeLogicGates() {
|
||||
var logicgatesElements = ["output","logic_wire","not_gate","and_gate","xor_gate","or_gate","nand_gate","nor_gate","nxor_gate","E2L_lever","E2L_button","L2E_constant","logic_transmitter","logic_receiver","logic_shock","logic_unshock"]
|
||||
|
||||
for (var i = 0;i < logicgatesElements.length;i++) {
|
||||
elements[logicgatesElements[i]].cc_stableTick = elements[logicgatesElements[i]].tick;
|
||||
elements[logicgatesElements[i]].tick = null;
|
||||
}
|
||||
}
|
||||
|
||||
renderPostPixel(drawCircuitExtras);
|
||||
runEveryTick(runLogicTick);
|
||||
runAfterLoad(stabilizeLogicGates);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,146 @@
|
|||
if (!enabledMods.includes("mods/circuitcore.js")) { enabledMods.unshift("mods/circuitcore.js"); localStorage.setItem("enabledMods", JSON.stringify(enabledMods)); window.location.reload() };
|
||||
var lightmapEnabled = enabledMods.includes("mods/lightmap.js") || enabledMods.includes("mods/fast_lightmap.js");
|
||||
|
||||
function general_display(w, h, colorMode) { // colorMode: 0 for monochrome, 1 for 3-bit, 2 for 4-bit
|
||||
return function(pixel) {
|
||||
var pins = [];
|
||||
|
||||
// X input (expands right)
|
||||
for (var i = 0; i < Math.ceil(Math.log2(w)); i++) {
|
||||
pins.push([-1, (i * 2) + 1, true]);
|
||||
}
|
||||
|
||||
// Y input (expands downward)
|
||||
for (var i = 0; i < Math.ceil(Math.log2(h)); i++) {
|
||||
pins.push([(i * 2) + 1, -1, true]);
|
||||
}
|
||||
|
||||
if (colorMode === 1) { // 3-bit color
|
||||
pins.push([-1, 11, true]); // Red
|
||||
pins.push([-1, 13, true]); // Green
|
||||
pins.push([-1, 15, true]); // Blue
|
||||
} else if (colorMode === 2) { // 4-bit color
|
||||
for (var i = 0; i < 4; i++) {
|
||||
pins.push([-1, 11 + (i * 2), true]); // 4-bit color input
|
||||
}
|
||||
} else { // Monochrome
|
||||
pins.push([w - 4, -1, true]);
|
||||
}
|
||||
|
||||
// Reset pin
|
||||
pins.push([w - 2, -1, true]);
|
||||
|
||||
// Clock input
|
||||
pins.push([w, -1, true]);
|
||||
|
||||
initializeCircuit(pixel, pins, w + 2, h + 2, false, pixel.circuitRotation, addDisplayCallback);
|
||||
|
||||
var X = [];
|
||||
for (var i = 0; i < Math.ceil(Math.log2(w)); i++) {
|
||||
X.push(checkPin(pixel, pins, i));
|
||||
}
|
||||
|
||||
var Y = [];
|
||||
for (var i = 0; i < Math.ceil(Math.log2(h)); i++) {
|
||||
Y.push(checkPin(pixel, pins, Math.ceil(Math.log2(w)) + i));
|
||||
}
|
||||
|
||||
var color;
|
||||
if (colorMode === 1) {
|
||||
var red = checkPin(pixel, pins, Math.ceil(Math.log2(w)) + Math.ceil(Math.log2(h)));
|
||||
var green = checkPin(pixel, pins, Math.ceil(Math.log2(w)) + Math.ceil(Math.log2(h)) + 1);
|
||||
var blue = checkPin(pixel, pins, Math.ceil(Math.log2(w)) + Math.ceil(Math.log2(h)) + 2);
|
||||
color = `rgb(${red ? 255 : 0}, ${green ? 255 : 0}, ${blue ? 255 : 0})`;
|
||||
} else if (colorMode === 2) {
|
||||
var colorIndex = 0;
|
||||
for (var i = 0; i < 4; i++) {
|
||||
colorIndex += checkPin(pixel, pins, Math.ceil(Math.log2(w)) + Math.ceil(Math.log2(h)) + i) ? Math.pow(2, i) : 0;
|
||||
}
|
||||
color = colorPalette_4bit[colorIndex];
|
||||
} else {
|
||||
color = checkPin(pixel, pins, Math.ceil(Math.log2(w)) + Math.ceil(Math.log2(h))) ? "rgb(16, 230, 120)" : "rgb(16, 24, 32)";
|
||||
}
|
||||
|
||||
var reset = checkPin(pixel, pins, Math.ceil(Math.log2(w)) + Math.ceil(Math.log2(h)) + (colorMode === 1 ? 3 : (colorMode === 2 ? 4 : 1)));
|
||||
var clock = checkPin(pixel, pins, Math.ceil(Math.log2(w)) + Math.ceil(Math.log2(h)) + (colorMode === 1 ? 4 : (colorMode === 2 ? 5 : 2)));
|
||||
|
||||
var x_pos = 0;
|
||||
for (var i = 0; i < X.length; i++) {
|
||||
x_pos += X[i] ? Math.pow(2, (X.length - 1) - i) : 0;
|
||||
}
|
||||
|
||||
var y_pos = 0;
|
||||
for (var i = 0; i < Y.length; i++) {
|
||||
y_pos += Y[i] ? Math.pow(2, (Y.length - 1) - i) : 0;
|
||||
}
|
||||
|
||||
if (x_pos >= w || y_pos >= h) return;
|
||||
|
||||
var px = pixel.x + 1 + x_pos;
|
||||
var py = pixel.y + 1 + y_pos;
|
||||
|
||||
if (reset) {
|
||||
for (var y = 1; y <= h; y++) {
|
||||
for (var x = 1; x <= w; x++) {
|
||||
var reset_px = pixel.x + x;
|
||||
var reset_py = pixel.y + y;
|
||||
if (pixelMap[reset_px] && pixelMap[reset_px][reset_py] && pixelMap[reset_px][reset_py].element == "displayPixel") {
|
||||
pixelMap[reset_px][reset_py].color = "rgb(16, 24, 32)";
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (clock) {
|
||||
if (pixelMap[px] && pixelMap[px][py] && pixelMap[px][py].element == "displayPixel") {
|
||||
pixelMap[px][py].color = color;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
elements.gridDisplay = {
|
||||
color: "#33FF66",
|
||||
category: "logic",
|
||||
maxSize: 1,
|
||||
onSelect: function() {
|
||||
// Prompt the user for display width, height, and color depth
|
||||
var width = parseInt(prompt("Enter the display width (e.g., 16, 32, 64):", "16"));
|
||||
var height = parseInt(prompt("Enter the display height (e.g., 16, 32, 64):", "16"));
|
||||
var colorDepth = parseInt(prompt("Enter the color depth (1 for monochrome, 3 for 3-bit, 4 for 4-bit):", "4"));
|
||||
|
||||
// Set these values for the pixel
|
||||
elements.gridDisplay.displayWidth = width;
|
||||
elements.gridDisplay.displayHeight = height;
|
||||
elements.gridDisplay.displayColorDepth = colorDepth;
|
||||
},
|
||||
cc_stableTick: function(pixel) {
|
||||
// Get the display properties
|
||||
var width = elements.gridDisplay.displayWidth || 16;
|
||||
var height = elements.gridDisplay.displayHeight || 16;
|
||||
var colorDepth = elements.gridDisplay.displayColorDepth || 4;
|
||||
|
||||
// Call general_display with the appropriate parameters
|
||||
var displayFunction = general_display(width, height, colorDepth === 1 ? 0 : (colorDepth === 3 ? 1 : 2));
|
||||
displayFunction(pixel);
|
||||
}
|
||||
};
|
||||
|
||||
elements.displayPixel = {
|
||||
color: "#000000",
|
||||
category: "logic",
|
||||
state: "solid",
|
||||
behavior: behaviors.WALL,
|
||||
tick: function(pixel) {
|
||||
if (pixel.start == pixelTicks) {
|
||||
pixel.color = "rgb(16, 24, 32)";
|
||||
}
|
||||
|
||||
// if (lightmapEnabled && pixel.color) {
|
||||
// var x = Math.floor(pixel.x / lightmapScale);
|
||||
// var y = Math.floor(pixel.y / lightmapScale);
|
||||
// lightmap[y][x] = { color: scaleList(rgbToArray(pixel.color), 2) };
|
||||
// }
|
||||
}
|
||||
};
|
||||
|
|
@ -0,0 +1,179 @@
|
|||
|
||||
// created by Rain :o 20/8 2024
|
||||
|
||||
elements.car = {
|
||||
//color: ["#E37F6F", "#B075DF", "#4F8FEF"],
|
||||
color: ["#ee70aa", "#ab33ef", "#5e6eee"],
|
||||
category: "special",
|
||||
density: 10000,
|
||||
state: "solid",
|
||||
tempHigh: 400,
|
||||
stateHigh: ["steel", "molten_plastic", "glass"],
|
||||
breakInto: ["steel", "plastic", "glass_shard"],
|
||||
reactions: {
|
||||
"water": { elem1: "rust", chance: 0.003 },
|
||||
"dirty_water": { elem1: "rust", chance: 0.003 },
|
||||
"salt_water": { elem1: "rust", chance: 0.006 },
|
||||
"grape": { elem2: "juice", chance: 0.1, color2: "#291824" },
|
||||
"tomato": { elem2: "sauce", chance: 0.1 },
|
||||
"egg": { elem2: "yolk", chance: 0.1 },
|
||||
"malware": {elem1: "explosion"},
|
||||
},
|
||||
flippableX: true,
|
||||
tick: function (pixel) {
|
||||
|
||||
if (pixel.carFlip === undefined) {
|
||||
pixel.carFlip = 1; //it's the "pixel." that gives the variable to each car instance, very important :)
|
||||
}
|
||||
tryMove(pixel, pixel.x, pixel.y + 1); //try to move down (fall)
|
||||
if (!isEmpty(pixel.x, pixel.y + 1)) { //if it didn't work (if the car is on the ground):
|
||||
|
||||
if (isEmpty(pixel.x + pixel.carFlip, pixel.y + 1)) {
|
||||
tryMove(pixel, pixel.x + pixel.carFlip, pixel.y + 1); // move diagonally down to avoid falling when going downhill
|
||||
}
|
||||
else if (isEmpty(pixel.x + pixel.carFlip, pixel.y)) {
|
||||
tryMove(pixel, pixel.x + pixel.carFlip, pixel.y); //move to the side (which side is derived from current carFlip state)
|
||||
|
||||
} else if (isEmpty(pixel.x + pixel.carFlip, pixel.y - 1)) {
|
||||
tryMove(pixel, pixel.x + pixel.carFlip, pixel.y - 1); //move diagonally up the hill
|
||||
|
||||
} else { //if no movement possible (like when hitting a wall):
|
||||
pixel.carFlip = pixel.carFlip * -1; // Update carFlip for this car instance
|
||||
}
|
||||
|
||||
doDefaults(pixel);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
elements.tram = {
|
||||
color: "#93E493",
|
||||
conduct: 1,
|
||||
category: "special",
|
||||
density: 10000,
|
||||
state: "solid",
|
||||
tempHigh: 400,
|
||||
stateHigh: ["molten_aluminum", "molten_plastic", "glass"],
|
||||
breakInto: ["aluminum", "plastic", "glass_shard"],
|
||||
flippableX: true,
|
||||
desc: "Powered by electricity. Can hang on conductive materials for suspension railway",
|
||||
reactions: {
|
||||
"malware": { elem2: "electric" },
|
||||
},
|
||||
tick: function (pixel) {
|
||||
|
||||
if (pixel.tramFlip === undefined) {
|
||||
pixel.tramFlip = 1; //tramFlip works like carFlip for the car
|
||||
}
|
||||
|
||||
if (pixel.charge > 0) { //only if powered by electricity
|
||||
|
||||
if (isEmpty(pixel.x + 1 * pixel.tramFlip, pixel.y - 1) && !isEmpty(pixel.x + 1 * pixel.tramFlip, pixel.y - 2)) {
|
||||
var diUpPixel = pixelMap[pixel.x + 1 * pixel.tramFlip][pixel.y - 2] //establishes the variable. Must be down here because it would crash if there is no diUpPixel
|
||||
if (elements[diUpPixel.element].conduct && diUpPixel.element !== "tram") { //^ is also the reason this is a seperate if statement
|
||||
tryMove(pixel, pixel.x + 1 * pixel.tramFlip, pixel.y - 1); //move diagonally upwards if there is support
|
||||
}
|
||||
else {
|
||||
pixel.tramFlip = pixel.tramFlip * -1;
|
||||
}
|
||||
}
|
||||
else if (isEmpty(pixel.x + 1 * pixel.tramFlip, pixel.y) && !isEmpty(pixel.x + 1 * pixel.tramFlip, pixel.y - 1)) {
|
||||
var sidePixel = pixelMap[pixel.x + 1 * pixel.tramFlip][pixel.y - 1]
|
||||
if (elements[sidePixel.element].conduct && sidePixel.element !== "tram") {
|
||||
tryMove(pixel, pixel.x + 1 * pixel.tramFlip, pixel.y); //move to the side if there is support
|
||||
}
|
||||
else {
|
||||
pixel.tramFlip = pixel.tramFlip * -1;
|
||||
}
|
||||
}
|
||||
else if (isEmpty(pixel.x + 1 * pixel.tramFlip, pixel.y + 1) && !isEmpty(pixel.x + 1 * pixel.tramFlip, pixel.y)) {
|
||||
var diDownPixel = pixelMap[pixel.x + 1 * pixel.tramFlip][pixel.y]
|
||||
if (elements[diDownPixel.element].conduct && diDownPixel.element !== "tram") {
|
||||
tryMove(pixel, pixel.x + 1 * pixel.tramFlip, pixel.y + 1); //move diagonally downwards if there is support
|
||||
}
|
||||
else {
|
||||
pixel.tramFlip = pixel.tramFlip * -1;
|
||||
}
|
||||
}
|
||||
|
||||
else if (isEmpty(pixel.x + 1 * pixel.tramFlip, pixel.y + 1) && isEmpty(pixel.x + 1 * pixel.tramFlip, pixel.y)) {
|
||||
tryMove(pixel, pixel.x + 1 * pixel.tramFlip, pixel.y + 1); //move diagonally downwards if there isn't support
|
||||
}
|
||||
else if (isEmpty(pixel.x + 1 * pixel.tramFlip, pixel.y) && isEmpty(pixel.x + 1 * pixel.tramFlip, pixel.y - 1)) {
|
||||
tryMove(pixel, pixel.x + 1 * pixel.tramFlip, pixel.y); //move to the side if there isn't support
|
||||
}
|
||||
else if (isEmpty(pixel.x + 1 * pixel.tramFlip, pixel.y - 1) && isEmpty(pixel.x + 1 * pixel.tramFlip, pixel.y - 2)) {
|
||||
tryMove(pixel, pixel.x + 1 * pixel.tramFlip, pixel.y - 1); //move diagonally upwards if there isn't support (uphill)
|
||||
}
|
||||
else {
|
||||
pixel.tramFlip = pixel.tramFlip * -1;
|
||||
}
|
||||
|
||||
}
|
||||
else { //if not powered
|
||||
if (!isEmpty(pixel.x, pixel.y - 1)) {
|
||||
var upPixel = pixelMap[pixel.x][pixel.y - 1] //looks at the properties of the pixel above
|
||||
if (elements[upPixel.element].conduct > 0.1 && upPixel.element !== "tram") { //if the pixel above is conductive but not tram
|
||||
//nothing happens ie it doesn't fall
|
||||
}
|
||||
else {
|
||||
tryMove(pixel, pixel.x, pixel.y + 1); //it falls down
|
||||
}
|
||||
}
|
||||
else {
|
||||
tryMove(pixel, pixel.x, pixel.y + 1); //it falls down (same as above)
|
||||
}
|
||||
|
||||
}
|
||||
doDefaults(pixel)
|
||||
},
|
||||
};
|
||||
elements.bouncy_ball = {
|
||||
color: "#e35693",
|
||||
behavior: behaviors.WALL,
|
||||
tempHigh: 250,
|
||||
stateHigh: ["borax", "glue"],
|
||||
category: "special",
|
||||
conduct: 1,
|
||||
tick: function (pixel) {
|
||||
if (pixel.fallDist === undefined) {
|
||||
pixel.fallDist = 0;
|
||||
}
|
||||
if (pixel.isFalling === undefined) {
|
||||
pixel.isFalling = true;
|
||||
}
|
||||
|
||||
if (pixel.isFalling) { //main loop of a bouncy ball. Functions are defined below
|
||||
falling()
|
||||
} else {
|
||||
rising()
|
||||
}
|
||||
if (pixel.charge > 0) { //will bounce on electricity (doesn't work on real bouncy balls :/)
|
||||
pixel.fallDist = (pixel.fallDist + 1)
|
||||
rising()
|
||||
}
|
||||
|
||||
function falling() {
|
||||
|
||||
if (isEmpty(pixel.x, pixel.y + 1)) {
|
||||
tryMove(pixel, pixel.x, pixel.y + 1)
|
||||
pixel.fallDist += 1; //counts how many pixels the ball has fallen so far
|
||||
} else { //if it touched the ground
|
||||
pixel.isFalling = false; //will change the outcome of the main if statement and make ball start rising
|
||||
pixel.fallDist = pixel.fallDist * 3 / 4; //dynamically decreases bounce height based on how high it is, instead of constant 1 per bounce
|
||||
}
|
||||
}
|
||||
function rising() {
|
||||
if (pixel.fallDist > 0) {
|
||||
tryMove(pixel, pixel.x, pixel.y - 1)
|
||||
pixel.fallDist -= 1
|
||||
} else {
|
||||
pixel.isFalling = true;
|
||||
pixel.fallDist -= 1 //makes the ball lose 1 pixel height each bounce, useful at the end when * 3/4 only results in fractions
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
elements.borax.reactions.slime = { elem1: "bouncy_ball", elem2: null};
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
|
||||
// created by Rain :o 20/8 2024
|
||||
|
||||
elements.glycerol = {
|
||||
color: "#eeeeee",
|
||||
behavior: behaviors.LIQUID,
|
||||
viscosity: 1412,
|
||||
category: "liquids",
|
||||
state: "liquid",
|
||||
density: 1261,
|
||||
tempLow: 18,
|
||||
tempHigh: 290,
|
||||
tick: function (pixel) {
|
||||
pixel.color = "rgba(250, 250, 250, 0.7)";
|
||||
},
|
||||
reactions: {
|
||||
},
|
||||
burn: 5,
|
||||
burnTime: 40,
|
||||
};
|
||||
|
||||
elements.nitro.tempHigh = 218; //More accurate detonation temperature
|
||||
elements.salt_water.tempLow = -20; //melting point depression
|
||||
|
||||
elements.nitro.tick = function (pixel) { // Exothermic decomposition of nitroglycerin when above 60°
|
||||
if (pixel.temp > 60) {
|
||||
pixel.temp += 1;
|
||||
if (Math.random() > 0.999) {
|
||||
var possibleElements = ["oxygen", "nitrogen", "nitrogen", "steam", "steam", "steam", "carbon_dioxide", "carbon_dioxide", "carbon_dioxide"]; //array of possibilities for changing the nitroglycerin pixel
|
||||
|
||||
var randomElement = possibleElements[Math.floor(Math.random() * possibleElements.length)]; //randomly selecting an element from the array
|
||||
|
||||
changePixel(pixel, randomElement); // Change the pixel to the randomly selected element
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (enabledMods.includes("mods/chem.js")) {
|
||||
runAfterLoad(function () {
|
||||
elements.glycerol.reactions.nitric_acid = { elem1: "nitro", chance: 0.05, temp1: 70 }; //nitric acid nitrates glycerol to make nitroglycerin
|
||||
elements.nitric_acid.ignore.push("glycerol", "nitro") //added my glycerol and nitro to allow for making nitroglycerin
|
||||
|
||||
elements.copper.reactions.sulfuric_acid = { elem1: "copper_sulfate", elem2: null, chance: 0.1 }; //this is how you can actually make CuSO4
|
||||
elements.sulfuric_acid.ignore.push("copper_sulfate")
|
||||
|
||||
elements.grease.reactions.sodium_hydroxide = { elem1: "soap", elem2: "null", chance: 0.04, tempMin: 40 };
|
||||
elements.sodium_hydroxide.ignore.push("grease", "soap", "fat");
|
||||
|
||||
|
||||
});
|
||||
} else {
|
||||
elements.glycerol.reactions.acid = { elem1: "nitro", chance: 0.05, temp1: 70 }; //if we don't have nitric acid from chem.js, "acid" is a good approximation
|
||||
elements.acid.ignore.push("glycerol", "nitro")
|
||||
}
|
||||
|
|
@ -0,0 +1,93 @@
|
|||
|
||||
// created by Rain :o 20/8 2024
|
||||
|
||||
elements.water_bottle = {
|
||||
color: "#a8d2e3",
|
||||
behavior: behaviors.STURDYPOWDER,
|
||||
category: "powders",
|
||||
state: "solid",
|
||||
density: 800,
|
||||
breakInto: ["water_everywhere", "water_everywhere", "water_everywhere", "water_everywhere", "microplastic"],
|
||||
tempHigh: 250,
|
||||
stateHigh: ["molten_plastic", "water_everywhere", "water_everywhere"],
|
||||
};
|
||||
elements.head.reactions.water_bottle = { elem2: ["plastic", "water", null, null, null], chance: 0.1 };
|
||||
elements.body.reactions.water_bottle = { elem2: ["plastic", "water", null, null, null], chance: 0.1 };
|
||||
|
||||
elements.water_everywhere = {
|
||||
color: "#8882e3",
|
||||
behavior: [
|
||||
"CR:water_everywhere%20 AND CR:water|CR:water_everywhere%20 AND CR:water|CR:water_everywhere%20 AND CR:water",
|
||||
"CR:water_everywhere%20 AND CR:water|XX%20 AND CH:water|CR:water_everywhere%20 AND CR:water",
|
||||
"CR:water_everywhere%20 AND CR:water|CR:water_everywhere%20 AND CR:water|CR:water_everywhere%20 AND CR:water",
|
||||
],
|
||||
category: "liquids",
|
||||
state: "solid",
|
||||
density: 800,
|
||||
hidden: true,
|
||||
};
|
||||
elements.microplastic = {
|
||||
color: ["#adc7c9", "#cadadb", "#6cbda8", "#62d5d4", "#b3b47b"],
|
||||
behavior: [
|
||||
"XX|XX|XX",
|
||||
"XX|XX|XX",
|
||||
"M2%25|M1%50|M2%25",
|
||||
],
|
||||
category: "powders",
|
||||
state: "solid",
|
||||
density: 700,
|
||||
tempHigh: 250,
|
||||
stateHigh: "molten_plastic",
|
||||
reactions: {
|
||||
"fish": { elem1: null, elem2: "meat", chance: 0.01 },
|
||||
"glue": { elem1: "bead", elem2: null, chance: 0.03 },
|
||||
},
|
||||
};
|
||||
elements.plastic.breakInto = "microplastic";
|
||||
|
||||
elements.cellulose.reactions.vinegar = { elem1: "bioplastic", elem2: null, tempMin: 40, chance: 0.1};
|
||||
|
||||
elements.bioplastic = {
|
||||
color: "#eeeeaa",
|
||||
behavior: behaviors.WALL,
|
||||
category: "solids",
|
||||
tempHigh: 180,
|
||||
stateHigh: "molten_bioplastic",
|
||||
breakInto: "bioplastic_crumbs",
|
||||
alias: "Cellulose acetate",
|
||||
desc: "It's biodegradable :)",
|
||||
};
|
||||
elements.bioplastic_crumbs = {
|
||||
color: ["#dfd499", "#c0e8a0", "#dfab87"],
|
||||
hidden: true,
|
||||
behavior: behaviors.POWDER,
|
||||
category: "powders",
|
||||
tempHigh: 180,
|
||||
stateHigh: "molten_bioplastic",
|
||||
desc: "small pieces of cellulose acetate"
|
||||
};
|
||||
|
||||
elements.worm.reactions.bioplastic = { elem2: ["carbon_dioxide", null, null], chance: 0.05, func: behaviors.FEEDPIXEL };
|
||||
elements.worm.reactions.bioplastic_crumbs = { elem2: ["carbon_dioxide", null, null], chance: 0.05, func: behaviors.FEEDPIXEL };
|
||||
elements.worm.behavior = [
|
||||
"SW:dirt,sand,gravel,ash,mycelium,mud,wet_sand,clay_soil,water,salt_water,dirty_water,primordial_soup,blood,infection,color_sand,bioplastic%3|XX|SW:dirt,sand,gravel,ash,mycelium,mud,wet_sand,clay_soil,water,salt_water,dirty_water,primordial_soup,blood,infection,color_sand,bioplastic,bioplastic_crumbs%3",
|
||||
"M2%10|XX|M2%10",
|
||||
"SW:dirt,sand,gravel,ash,mycelium,mud,wet_sand,clay_soil,water,salt_water,dirty_water,primordial_soup,blood,infection,color_sand,bioplastic%3|M1|SW:dirt,sand,gravel,ash,mycelium,mud,wet_sand,clay_soil,water,salt_water,dirty_water,primordial_soup,blood,infection,color_sand,bioplastic,bioplastic_crumbs%3",
|
||||
];
|
||||
elements.cell.reactions.bioplastic = { elem2: ["carbon_dioxide", null, null], chance: 0.02, func: behaviors.FEEDPIXEL };
|
||||
elements.cell.reactions.bioplastic_crumbs = { elem2: ["carbon_dioxide", null, null], chance: 0.02, func: behaviors.FEEDPIXEL };
|
||||
|
||||
elements.molten_bioplastic = {
|
||||
color: "#ccccac",
|
||||
behavior: behaviors.LIQUID,
|
||||
viscosity: 300,
|
||||
category: "states",
|
||||
state: "liquid",
|
||||
tempLow: 150,
|
||||
stateLow: "bioplastic",
|
||||
temp: 160,
|
||||
density: 1300,
|
||||
hidden: true,
|
||||
};
|
||||
|
||||
|
||||
Loading…
Reference in New Issue