sandboxels/mods/nicer_flame.js

49 lines
1.4 KiB
JavaScript
Raw Normal View History

2024-07-14 08:50:12 -04:00
// RedBirdly's mod that makes fire look better with dark red at the top of the flame
2024-05-20 00:36:45 -04:00
2024-07-14 08:50:12 -04:00
var topColor = 'rgb(130, 0, 10)';
var blending = 0.9;
var topColdFireColor = 'rgb(30, 10, 110)';
2024-07-14 08:51:33 -04:00
var coldFireBlending = 0.9;
2024-05-20 00:36:45 -04:00
function cssColorToRGB(color) {
let rgbMatch = color.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
return [parseInt(rgbMatch[1]), parseInt(rgbMatch[2]), parseInt(rgbMatch[3])];
}
function blendColors(color1, color2, weight) {
const [r1, g1, b1] = cssColorToRGB(color1);
const [r2, g2, b2] = cssColorToRGB(color2);
const r = Math.round(r1 * weight + r2 * (1 - weight));
const g = Math.round(g1 * weight + g2 * (1 - weight));
const b = Math.round(b1 * weight + b2 * (1 - weight));
return `rgb(${r}, ${g}, ${b})`;
}
let originalFireTick = elements.fire.tick;
elements.fire.tick = function(pixel) {
// Call the original tick function
originalFireTick(pixel);
2024-07-14 08:50:12 -04:00
if (Math.random()<0.4) {
2024-05-20 00:36:45 -04:00
let originalColor = pixel.color;
pixel.color = blendColors(originalColor, topColor, blending);
}
2024-05-20 21:29:41 -04:00
};
2024-07-14 08:50:12 -04:00
let originalColdFireTick = elements.cold_fire.tick;
elements.cold_fire.tick = function(pixel) {
// Call the original tick function
originalColdFireTick(pixel);
if (Math.random()<0.4) {
let originalColor = pixel.color;
2024-07-14 08:51:33 -04:00
pixel.color = blendColors(originalColor, topColdFireColor, coldFireBlending);
2024-07-14 08:50:12 -04:00
}
};
elements.fire.color = ["#ffcb31","#ffab21","#ff9600"];
elements.cold_fire.color = ["#11ddff","#2288dd"];