From bdaeb77cf546bfb3e9d7aba617a5f285e9a21835 Mon Sep 17 00:00:00 2001 From: slweeb <91897291+slweeb@users.noreply.github.com> Date: Thu, 16 Oct 2025 14:20:17 -0400 Subject: [PATCH] . --- mod-list.html | 2 ++ mods/rich_grain.js | 54 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 mods/rich_grain.js diff --git a/mod-list.html b/mod-list.html index d9ed8b19..754017b0 100644 --- a/mod-list.html +++ b/mod-list.html @@ -147,6 +147,7 @@ mustard.jsMustard and Mustard SeedsR74n rainbow_cursor.jsMakes your cursor multicoloredR74n random_everything.jsAllows every element to be spawned with RandomR74n +rich_grain.jsChanges pixel grain to create richer colorsR74n smooth_water.jsChanges water mechanics so that it flows in one direction until it bounces off of somethingR74n souls.jsHuman Souls, Ectoplasm, and TombstonesR74n spring.jsMany nature elements, like sakura trees, butterflies, beehives, and moreR74n @@ -430,6 +431,7 @@ paint_event.jsRandom event that randomly paints a circleAlice rainbow_tests.jsVariants of the rainbow element with different mathsAlice real_light.jsEverything is dark unless hit with a photon (Light) pixel, hot, or glowingNekonico +rich_grain.jsChanges pixel grain to create richer colorsR74n shader_by_jayd.jsGlow around light elementsJayd Shroomboxels.jsVariant of acid_and_shapes.js that uses a different trigonometric functionAlice singleColor.jsElements pick one color each time they're drawnstefanblox diff --git a/mods/rich_grain.js b/mods/rich_grain.js new file mode 100644 index 00000000..93532af2 --- /dev/null +++ b/mods/rich_grain.js @@ -0,0 +1,54 @@ +pixelColorPick = function(pixel,customColor=null) { + let element = pixel.element; + let elementInfo = elements[element]; + //if (elementInfo.behavior instanceof Array) { + + if (pixel.charge && elementInfo.colorOn) { + customColor = elementInfo.colorOn; + } + let rgb; + if (customColor !== null) { + if (Array.isArray(customColor)) { + customColor = customColor[Math.floor(Math.random() * customColor.length)]; + } + if (customColor.startsWith("#")) { + customColor = hexToRGB(customColor); + } + rgb = customColor; + } + else { + rgb = elements[element].colorObject; // {r, g, b} + // If rgb is an array, choose a random item + if (Array.isArray(rgb)) { + rgb = rgb[Math.floor(Math.random() * rgb.length)]; + } + } + // Randomly darken or lighten the RGB color + let grain = 15; + if (elementInfo.grain !== undefined) { grain = grain * elementInfo.grain } + let coloroffset = Math.floor(Math.random() * (Math.random() > 0.5 ? -1 : 1) * Math.random() * grain); + let r = rgb.r + coloroffset; + let g = rgb.g + coloroffset; + let b = rgb.b + coloroffset; + // better_grain.js changes begin + let hsl = RGBToHSL([r,g,b]); + hsl[0] += coloroffset/1.5/255; + // console.log(hsl) + let rgb2 = HSLtoRGB(hsl); + r = Math.round(rgb2[0]); g = Math.round(rgb2[1]); b = Math.round(rgb2[2]); + // better_grain.js changes end + // Make sure the color is within the RGB range + r = Math.max(0, Math.min(255, r)); + g = Math.max(0, Math.min(255, g)); + b = Math.max(0, Math.min(255, b)); + let color = "rgb("+r+","+g+","+b+")"; + + /*} + else { + var color = elementInfo.color; + if (Array.isArray(color)) { + color = color[Math.floor(Math.random() * color.length)]; + } + }*/ + return color; +} \ No newline at end of file