moddable views, black holes are no longer affected by maxSize

This commit is contained in:
An Orbit 2024-06-25 20:11:50 -04:00 committed by GitHub
parent 94bf5e9cea
commit 0446d3178b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 231 additions and 184 deletions

View File

@ -3249,6 +3249,36 @@ color1 and color2 spread through striped paint like dye does with itself. <u>col
return coords
};
function mouseLikeRange(x,y,size,shape="square",skipEmpties=false) {
var coords = [];
var offset = Math.trunc(size/2);
var topLeft = [x-offset,y-offset];
var bottomRight = [x+offset,y+offset];
if(size % 2 == 0) {
bottomRight[0]--;
bottomRight[1]--;
};
var exclusionFunction = shapeExclusionConditions[shape] ?? null;
if((shape !== "square") && (exclusionFunction == null)) {
logMessage(`Shape ${shape} not recognized!`)
return []
};
// Starting at the top left, go through each pixel
for (var _x = topLeft[0]; _x <= bottomRight[0]; _x++) {
for (var _y = topLeft[1]; _y <= bottomRight[1]; _y++) {
if(skipEmpties && isEmpty(_x,_y,true)) {
continue
};
if((shape !== "square") && exclusionFunction?.(_x,_y,size,x,y,topLeft,bottomRight)) {
continue
};
coords.push([_x,_y]);
}
};
return coords
};
//this part defines basically all of the keybinds
function addKeyboardListeners() {
document.addEventListener("keydown", function(e) {
@ -5117,84 +5147,19 @@ color1 and color2 spread through striped paint like dye does with itself. <u>col
//I hate overwriting drawPixels
tempScale = 1;
tempScaleOffset = 20;
runAfterAutogen(function() {
//rAA because velocity.js already puts its redef in a rAL and rAA comes after that
drawPixels = function(forceTick=false) {
// Draw the current pixels
var canvas = document.getElementById("game");
var ctx = canvas.getContext("2d");
// newCurrentPixels = shuffled currentPixels
var newCurrentPixels = currentPixels.slice();
var pixelsFirst = [];
var pixelsLast = [];
if (!paused || forceTick) {
shuffleArray(newCurrentPixels);
}
/*{newCurrentPixels.sort(function(p) { // shuffle the pixels but keep elements[p.element].isGas last
return 0.5 - Math.random();
})} // shuffle the pixels if not paused*/
for (var i = 0; i < newCurrentPixels.length; i++) {
pixel = newCurrentPixels[i];
if(typeof(elements[pixel.element]) == "undefined") { continue };
if(typeof(pixel) == "undefined") { continue };
//if (pixelMap[pixel.x][pixel.y] == undefined || currentPixels.indexOf(pixel) == -1) {continue}
if (pixel.del) {continue}
if (!paused || forceTick) {
if(typeof(elements[pixel.element]) == "undefined") { continue };
doVelocity(pixel);
if (elements[pixel.element].tick) { // Run tick function if it exists
elements[pixel.element].tick(pixel);
}
if (pixel.del) {continue}
if (elements[pixel.element].behavior) { // Parse behavior if it exists
pixelTick(pixel);
}
};
if (elements[pixel.element].isGas) {
pixelsLast.push(pixel);
}
else {
pixelsFirst.push(pixel);
}
}
ctx.clearRect(0, 0, canvas.width, canvas.height);
if (!settings["bg"]) {ctx.clearRect(0, 0, canvas.width, canvas.height)}
else {
if(settings["bg"] instanceof Array) {
settings.bgAngle ??= 90;
var angle = (settings.bgAngle) * Math.PI / 180;
ctx.fillStyle = ctx.createLinearGradient(
0,
0,
canvas.width * Math.cos(angle) + 0,
canvas.height * Math.sin(angle)
);
var colors = settings["bg"];
for(i = 0; i < colors.length; i++) {
var color = colors[i];
var position = i / (colors.length - 1);
ctx.fillStyle.addColorStop(position,color);
};
} else {
ctx.fillStyle = settings["bg"];
};
ctx.fillRect(0, 0, canvas.width, canvas.height);
}
var pixelDrawList = pixelsFirst.concat(pixelsLast);
for (var i = 0; i < pixelDrawList.length; i++) {
var pixel = pixelDrawList[i];
if (pixelMap[pixel.x][pixel.y] == undefined) {continue}
if (pixel.con) { pixel = pixel.con }
if (view===null || view===3) {
normalColorFunction = function(pixel) {
var colorOut = pixel.color;
for(var sry4thelag in specialProperties) {
if(pixel[sry4thelag] !== undefined && specialProperties[sry4thelag].specialColorFunction) {
colorOut = specialProperties[sry4thelag].specialColorFunction(pixel,oldColor=colorOut)
}
}
ctx.fillStyle = colorOut;
return colorOut;
}
else if (view === 2) { // thermal view
viewColorFunctions = { //PENIS
2: function(pixel) {
// set the color to pixel.temp, from hottest at -66 (294.1875) hue to coldest 265 hue, with the minimum being -273, max being 7755
var a0 = (settings.abszero ?? -273.15);
var temp = ((pixel.temp - tempScaleOffset) * tempScale) - tempScaleOffset;
@ -5259,9 +5224,9 @@ color1 and color2 spread through striped paint like dye does with itself. <u>col
sat = 20 + (12 * Math.log10(temp / 55530));
lig = 50 + (4 * Math.log10(temp / 55530));
};
ctx.fillStyle = "hsl("+hue+","+sat+"%,"+lig+"%)";
}
else if (view === 4) { // smooth view, average of surrounding pixels
return "hsl("+hue+","+sat+"%,"+lig+"%)";
},
4: function(pixel) { // smooth view, average of surrounding pixels
// E/N: i'm too scared to do smooth view
var colorlist = [];
// check adjacent coords on the pixelMap, add the color to the list if the pixel is not empty and the color indexOf "rgb" is not -1
@ -5275,13 +5240,13 @@ color1 and color2 spread through striped paint like dye does with itself. <u>col
}
}
if (colorlist.length === 0) {
ctx.fillStyle = pixel.color;
return pixel.color;
}
else {
ctx.fillStyle = averageRGB(colorlist);
return averageRGB(colorlist);
}
}
else if (view === 5) { // velocity view
},
5: function(pixel) { // velocity view
var data = elements[pixel.element];
var vx = pixel.vx ?? 0;
var vy = pixel.vy ?? 0;
@ -5352,7 +5317,7 @@ color1 and color2 spread through striped paint like dye does with itself. <u>col
};
*/
if(vx === 0 && vy === 0) {
ctx.fillStyle = "rgb(15,15,15)"
return "rgb(15,15,15)"
} else {
var magnitude = Math.sqrt ((vx ** 2) + (vy ** 2));
var direction = Math.atan2(pixel.vy ?? 0,pixel.vx ?? 0)*180/Math.PI;
@ -5360,9 +5325,89 @@ color1 and color2 spread through striped paint like dye does with itself. <u>col
hue = direction;
sat = 100;
lig = bound(scale(magnitude,0,100,10,100),0,100);
ctx.fillStyle = "hsl("+hue+","+sat+"%,"+lig+"%)";
return "hsl("+hue+","+sat+"%,"+lig+"%)";
}
},
6: function(pixel) {
var data = elements[pixel.element] ?? elements.unknown;
var originalColor = data.colorObject;
if(Array.isArray(originalColor)) {
originalColor = randomChoice(originalColor)
};
return convertColorFormats(originalColor,"rgb");
}
};
runAfterAutogen(function() {
//rAA because velocity.js already puts its redef in a rAL and rAA comes after that
drawPixels = function(forceTick=false) {
// Draw the current pixels
var canvas = document.getElementById("game");
var ctx = canvas.getContext("2d");
// newCurrentPixels = shuffled currentPixels
var newCurrentPixels = currentPixels.slice();
var pixelsFirst = [];
var pixelsLast = [];
if (!paused || forceTick) {
shuffleArray(newCurrentPixels);
}
/*{newCurrentPixels.sort(function(p) { // shuffle the pixels but keep elements[p.element].isGas last
return 0.5 - Math.random();
})} // shuffle the pixels if not paused*/
for (var i = 0; i < newCurrentPixels.length; i++) {
pixel = newCurrentPixels[i];
if(typeof(elements[pixel.element]) == "undefined") { continue };
if(typeof(pixel) == "undefined") { continue };
//if (pixelMap[pixel.x][pixel.y] == undefined || currentPixels.indexOf(pixel) == -1) {continue}
if (pixel.del) {continue}
if (!paused || forceTick) {
if(typeof(elements[pixel.element]) == "undefined") { continue };
doVelocity(pixel);
if (elements[pixel.element].tick) { // Run tick function if it exists
elements[pixel.element].tick(pixel);
}
if (pixel.del) {continue}
if (elements[pixel.element].behavior) { // Parse behavior if it exists
pixelTick(pixel);
}
};
if (elements[pixel.element].isGas) {
pixelsLast.push(pixel);
}
else {
pixelsFirst.push(pixel);
}
}
ctx.clearRect(0, 0, canvas.width, canvas.height);
if (!settings["bg"]) {ctx.clearRect(0, 0, canvas.width, canvas.height)}
else {
if(settings["bg"] instanceof Array) {
settings.bgAngle ??= 90;
var angle = (settings.bgAngle) * Math.PI / 180;
ctx.fillStyle = ctx.createLinearGradient(
0,
0,
canvas.width * Math.cos(angle) + 0,
canvas.height * Math.sin(angle)
);
var colors = settings["bg"];
for(i = 0; i < colors.length; i++) {
var color = colors[i];
var position = i / (colors.length - 1);
ctx.fillStyle.addColorStop(position,color);
};
} else {
ctx.fillStyle = settings["bg"];
};
ctx.fillRect(0, 0, canvas.width, canvas.height);
}
var pixelDrawList = pixelsFirst.concat(pixelsLast);
for (var i = 0; i < pixelDrawList.length; i++) {
var pixel = pixelDrawList[i];
if (pixelMap[pixel.x][pixel.y] == undefined) {continue}
if (pixel.con) { pixel = pixel.con }
var colorFunction = viewColorFunctions[view] ?? normalColorFunction;
ctx.fillStyle = colorFunction(pixel);
if(find) { //if find and matching, override fill style with the find coloration
if(findElement instanceof Array ? findElement.includes(pixel.element) : pixel.element === findElement) {
ctx.fillStyle = "rgb(255," + marasi(findColorPulseTimer / 10) + ",0)";
@ -5385,7 +5430,7 @@ color1 and color2 spread through striped paint like dye does with itself. <u>col
acidOffset2 = 0
};
if ((view === null || view === 4) && elements[pixel.element].isGas) {
//gas rendering
//gas rendering //PENIS
switch(mode) {
case "circles":
ctx.globalAlpha = 0.66;
@ -5517,7 +5562,8 @@ color1 and color2 spread through striped paint like dye does with itself. <u>col
2: "thermal",
3: "basic",
4: "smooth",
5: "velocity"
5: "velocity",
6: "element"
};
function setView(n) {
if (viewKey[n]) { // range of number keys with valid views
@ -8640,7 +8686,7 @@ color1 and color2 spread through striped paint like dye does with itself. <u>col
pixel.range ??= 15;
if(pixel.range <= 0) { deletePixel(pixel.x,pixel.y); return };
var range = (pixel.range ?? 15) * 2;
var targets = mouseRange(pixel.x,pixel.y,range,"circle",true);
var targets = mouseLikeRange(pixel.x,pixel.y,range,"circle",true);
shuffleArray(targets);
for (var i = 0; i < targets.length; i++) {
var newPixel = pixelMap[targets[i][0]]?.[targets[i][1]];
@ -8673,6 +8719,7 @@ color1 and color2 spread through striped paint like dye does with itself. <u>col
}
if (best) {
tryMove(newPixel, x + best[0], y + best[1], undefined, true);
if(haseuliteSpreadWhitelist.includes(newPixel.element)) { newPixel.value += ((15 + (distanceComplement / (distanceProportion ** 2))) * 3) };
heatNeighbors(newPixel,20);
pixel.temp += 20;
}
@ -8718,7 +8765,7 @@ color1 and color2 spread through striped paint like dye does with itself. <u>col
pixel.range ??= 15;
if(pixel.range <= 0) { deletePixel(pixel.x,pixel.y); return };
var range = (pixel.range ?? 30) * 2;
var targets = mouseRange(pixel.x,pixel.y,range,"circle",true);
var targets = mouseLikeRange(pixel.x,pixel.y,range,"circle",true);
shuffleArray(targets);
for (var i = 0; i < targets.length; i++) {
var newPixel = pixelMap[targets[i][0]]?.[targets[i][1]];
@ -18447,7 +18494,7 @@ Pixel size (rendering only): <input id="pixelSize"> (Use if the save looks cut o
if(pixel.oldColor === null) { pixel.oldColor = pixel.color };
if(isNaN(pixel.value)) { pixel.value = 0 };
pixel.color = lightenColor(pixel.oldColor,pixel.value / 3);
var mVal = elements[pixel.element].haseulitoidMaxValue ?? 800;
var mVal = elements[pixel.element].haseulitoidMaxValue ?? 350;
if(pixel.value >= mVal) {
var coldBoomChance = Math.max(0.008 * ((pixel.value - mVal) / (mVal * 2/7)), 0.001);
if(Math.random() < coldBoomChance) {
@ -37747,7 +37794,7 @@ Make sure to save your command in a file if you want to add this preset again.`
if(pixel.oldColor === undefined) { pixel.oldColor = pixelColorPick(pixel) };
if(pixel.oldColor === null) { pixel.oldColor = pixel.color };
pixel.color = lightenColor(pixel.oldColor,pixel.value / 3);
var mVal = elements[pixel.element].haseulitoidMaxValue ?? 350;
var mVal = elements[pixel.element].haseulitoidMaxValue ?? 800;
if(pixel.value >= mVal) {
var coldBoomChance = Math.max(0.006 * ((pixel.value - mVal) / (400/3)), 0.000075);
if(Math.random() < coldBoomChance) {