This commit is contained in:
slweeb 2025-10-16 14:20:17 -04:00
parent 60a6eb3c7d
commit bdaeb77cf5
2 changed files with 56 additions and 0 deletions

View File

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

54
mods/rich_grain.js Normal file
View File

@ -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;
}