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.js | Mustard and Mustard Seeds | R74n |
| rainbow_cursor.js | Makes your cursor multicolored | R74n |
| random_everything.js | Allows every element to be spawned with Random | R74n |
+| rich_grain.js | Changes pixel grain to create richer colors | R74n |
| smooth_water.js | Changes water mechanics so that it flows in one direction until it bounces off of something | R74n |
| souls.js | Human Souls, Ectoplasm, and Tombstones | R74n |
| spring.js | Many nature elements, like sakura trees, butterflies, beehives, and more | R74n |
@@ -430,6 +431,7 @@
| paint_event.js | Random event that randomly paints a circle | Alice |
| rainbow_tests.js | Variants of the rainbow element with different maths | Alice |
| real_light.js | Everything is dark unless hit with a photon (Light) pixel, hot, or glowing | Nekonico |
+| rich_grain.js | Changes pixel grain to create richer colors | R74n |
| shader_by_jayd.js | Glow around light elements | Jayd |
| Shroomboxels.js | Variant of acid_and_shapes.js that uses a different trigonometric function | Alice |
| singleColor.js | Elements pick one color each time they're drawn | stefanblox |
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