sandboxels/mods/heatglow.js

118 lines
4.7 KiB
JavaScript
Raw Normal View History

2024-03-17 12:51:06 -04:00
function weightedAverage(num1, num2, weight){
return ((weight * num1)+((1-weight)*num2))
}
2023-12-15 17:03:13 -05:00
const heatfunc = function(pixel){
2024-04-21 15:50:13 -04:00
if (pixel.element != "metal_scrap" || eLists.metals.includes(pixel.scrapType) || !pixel.scrapType){{
if (pixel.ogR == null || pixel.ogG == null || pixel.ogB == null || (pixel.element != pixel.ogElement && pixel.element == "metal_scrap") || (pixel.element != "metal_scrap" && pixel.ogElement == "metal_scrap")){
2023-12-15 17:03:13 -05:00
pixel.ogR = parseInt(pixel.color.slice(4, pixel.color.indexOf(',')), 10)
pixel.ogG = parseInt(pixel.color.slice(pixel.color.indexOf(',') + 1, pixel.color.lastIndexOf(',')), 10)
pixel.ogB = parseInt(pixel.color.slice(pixel.color.lastIndexOf(',') + 1, -1), 10)
2023-12-25 15:41:37 -05:00
pixel.ogElement = pixel.element
2024-04-21 15:50:13 -04:00
}
var gethigh = 1000
var ctemp = 0
var ogR = 0
var ogG = 0
var ogB = 0
if (elements[pixel.element].tempHigh){
gethigh = elements[pixel.element].tempHigh
} else if (pixel.scrapType) {
gethigh = elements[pixel.scrapType].tempHigh
}
2024-03-17 13:06:51 -04:00
var halftemp = ((20+gethigh)/2)
if (pixel.temp <= (gethigh) - halftemp){
2024-04-21 15:50:13 -04:00
ctemp = 0;
2024-03-17 13:06:51 -04:00
} else if (pixel.temp > (gethigh)-halftemp && pixel.temp <= gethigh){
2024-04-21 15:50:13 -04:00
ctemp = ((1/halftemp)*pixel.temp)-(((gethigh)-halftemp)/halftemp)
2023-12-15 17:03:13 -05:00
}
2024-03-17 13:06:51 -04:00
if (ctemp <= 0.5){
2024-04-21 15:50:13 -04:00
newR = (((510-(2*pixel.ogR))*ctemp)+pixel.ogR);
newG = ((0-((2*pixel.ogG)*ctemp))+pixel.ogG);
newB = ((0-((2*pixel.ogB)*ctemp))+pixel.ogB);
2024-03-17 13:06:51 -04:00
}else if (ctemp > 0.5){
2024-04-21 15:50:13 -04:00
newR = 255;
newG = ((510*ctemp)-255);
newB= ((280*ctemp)-140);
2023-12-15 17:03:13 -05:00
}
2024-03-17 13:06:51 -04:00
let weight = (1-(ctemp/1.3))
pixel.color = "rgb(" + weightedAverage(pixel.ogR, newR, weight) + "," + weightedAverage(pixel.ogG, newG, weight) + "," + weightedAverage(pixel.ogB, newB, weight) + ")";
2024-04-21 15:50:13 -04:00
}}};
2023-12-15 23:09:23 -05:00
if (!eLists.metals) { eLists.metals = [] }
2023-12-25 15:41:37 -05:00
eLists.metals = eLists.metals.concat(["iron", "glass", "copper", "gold", "brass","steel","nickel","zinc","silver","aluminum","bronze","metal_scrap","oxidized_copper","tin","lead", "rose_gold"])
2023-12-15 23:09:23 -05:00
eLists.metals.forEach(metal => {
2023-12-15 17:03:13 -05:00
const prefunc = elements[metal].tick;
if (!prefunc){
elements[metal].tick = heatfunc;
}else{
const modfunc = function(pixel){
heatfunc(pixel);
2024-04-21 15:50:13 -04:00
prefunc(pixel);
2023-12-15 17:03:13 -05:00
};
elements[metal].tick = modfunc;
}
2023-12-16 20:44:09 -05:00
if (elements[metal].behavior == behaviors.WALL){
elements[metal].movable = false;
}
2023-12-15 17:03:13 -05:00
});
2023-12-15 22:17:21 -05:00
elements.color_baker = {
color: "#F61212",
tool: function(pixel) {
pixel.ogR = parseInt(pixel.color.slice(4, pixel.color.indexOf(',')), 10)
pixel.ogG = parseInt(pixel.color.slice(pixel.color.indexOf(',') + 1, pixel.color.lastIndexOf(',')), 10)
pixel.ogB = parseInt(pixel.color.slice(pixel.color.lastIndexOf(',') + 1, -1), 10)
},
category: "tools",
excludeRandom: true,
desc: "Use to bake a metals paint color into its 'true' color, for heating purposes.",
}
2024-01-28 18:52:41 -05:00
/*
const plantfunc = function(pixel){
if (pixel.ogR == null || pixel.ogG == null || pixel.ogB == null){
pixel.ogR = parseInt(pixel.color.slice(4, pixel.color.indexOf(',')), 10)
pixel.ogG = parseInt(pixel.color.slice(pixel.color.indexOf(',') + 1, pixel.color.lastIndexOf(',')), 10)
pixel.ogB = parseInt(pixel.color.slice(pixel.color.lastIndexOf(',') + 1, -1), 10)
var deadR = 130;
var deadG = 103;
var deadB = 40;
var burnR = 30;
var burnG = 30;
var burnB = 30;
var newR = pixel.ogR;
var newG = pixel.ogG;
var newB = pixel.ogB;
}else{
var gethigh = (elements[pixel.element].tempHigh)
var halftemp = ((20+gethigh)/2)
if (pixel.temp > halftemp){
var ctemp = ((1/halftemp)*pixel.temp)-(((gethigh)-halftemp)/halftemp);
} else (ctemp = 0)
if (ctemp <= 0.5 && ctemp > 0){
newR = weightedAverage(deadR, pixel.ogR, 2*ctemp);
newG = weightedAverage(deadG, pixel.ogG, 2*ctemp);
newB = weightedAverage(deadB, pixel.ogB, 2*ctemp);
}else if (ctemp > 0.5){
var modctemp = 2*(ctemp%0.5)
newR = weightedAverage(burnR, deadR, 2*modctemp);
newG = weightedAverage(burnG, deadG, 2*modctemp);
newB = weightedAverage(burnB, deadB, 2*modctemp);
}
if (!ctemp == 0){
pixel.color = "rgb(" + newR + "," + newG + "," + newB + ")";
} else {pixel.color = "rgb(" + pixel.ogR + "," + pixel.ogG + "," + pixel.ogB + ")"}
}
};
if (!eLists.burnplants) { eLists.burnplants = [] }
eLists.burnplants = eLists.burnplants.concat(["plant","dead_plant","grass","algae","sapling","evergreen","cactus","seeds","grass_seed","wheat_seed","flower_seed","pistil","petal","tree_branch","bamboo_plant","mushroom_spore","mushroom_stalk","mushroom_gill","mushroom_cap","hyphae","pumpkin_seed","pumpkin","corn","corn_seed","potato","potato_seed","root"])
eLists.burnplants.forEach(plant => {
const prefunc = elements[plant].tick;
if (!prefunc){
elements[plant].tick = plantfunc;
}else{
const modfunc = function(pixel){
prefunc(pixel);
plantfunc(pixel);
};
elements[plant].tick = modfunc;
}
});
*/