Skip to content

Community Collection

meezwhite edited this page Dec 19, 2022 · 10 revisions

The Community Collection is a collection of OpenSource custom pixel-manipulation functions by the community for the community that you can use in conjunction with tinkerPixels. Below you can find all submitted and accepted custom functions.

To submit your own custom function, create a new discussion in Discussions > Community Collection.

Please make sure to give proper attribution to creators when using their custom functions. 💞


granulateFuzzify

by meezwhite (MIT License)

Fuzzify and granulate by the given amount and fuzziness.

Argument Type Description
amount Number The amount of granularity that should be applied after fuzzifying.
fuzziness Number (optional) The amount of fuzziness that should be applied before granulating. (default: 2)
alpha Boolean (optional) Specifies whether the alpha channel should be granulated. (default: false)

Snippet

/**!
 * p5.grain.granulateFuzzify
 * @license MIT
 * @copyright meezwhite
 */
function granulateFuzzify(amount, fuzziness, alpha) {
    amount = round(Number(amount));
    fuzziness = round(Number(fuzziness)) || 2;
    alpha = Boolean(alpha);
    const modN = (4 * width * pixelDensity()) + (4 * fuzziness);
    tinkerPixels((i) => {
        const iN = i + modN;
        if (pixels[iN]) {
            pixels[i] = round((pixels[i] + pixels[iN])/2);
            pixels[i+1] = round((pixels[i+1] + pixels[iN+1])/2);
            pixels[i+2] = round((pixels[i+2] + pixels[iN+2])/2);
            if (alpha) {
                pixels[i+3] = round((pixels[i+3] + pixels[iN+3])/2);
            }
        }
    });
    granulateChannels(amount, alpha);
}

Usage

granulateFuzzify(42);
// granulateFuzzify(42, 2);
// granulateFuzzify(42, 2, false);

Example: https://editor.p5js.org/meezwhite/sketches/lpCWwo3em


Clone this wiki locally