### Draw Riso Layers to Screen with drawRiso Source: https://antiboredom.github.io/p5.riso/index Renders all Riso objects and layers onto the canvas. This function should be called at the end of 'setup' or 'draw' functions to preview the intended print output. ```javascript function setup(){ createCanvas(500, 500); let colors = ["red", "blue", "green", "black"]; for (let i = 0; i < colors.length; i++) { let channel = new Riso(colors[i]); //create four color channels from array channel.fill(random(100, 200)); channel.ellipse(random(0, width), random(0, height), 100, 100); //put a random ellipse on each } drawRiso(); //preview on screen } ``` -------------------------------- ### Export Riso Layers with exportRiso Source: https://antiboredom.github.io/p5.riso/index Exports all Riso layers as individual PNG files, suitable for printing with different ink colors. This function is typically called within an event listener (like 'mousePressed') or at the end of the 'setup' function. ```javascript let blue; let red; function setup(){ createCanvas(500, 500); blue = new Riso("blue"); red = new Riso("red"); } function draw() { clearRiso(); //clear screen every loop of draw blue.fill(map(mouseX, 0, width, 0, 255)); //set blue fill by mouse position red.fill(map(mouseY, 0, height, 0, 255)); //set red fill by mouse position blue.ellipse(200, 200, 100, 100); //draw ellipse to blue layer red.ellipse(250, 250, 100, 100); //draw ellipse to red layer } function mousePressed() { //when mouse is pressed exportRiso(); //export red and blue layers as pngs for printing } ``` -------------------------------- ### Set Pixel Density to 1 in p5.js Source: https://antiboredom.github.io/p5.riso/index Sets the pixel density for p5.js sketches to 1. This is crucial for ensuring that exported images from p5.riso have a consistent resolution (72 dpi) regardless of the screen's pixel density, preventing unexpected scaling issues on high-resolution displays. This function should be called within the `setup()` function of your p5.js sketch. ```javascript function setup() { createCanvas(400, 400); pixelDensity(1); } ``` -------------------------------- ### Initialize and Draw with Riso Object (p5.js) Source: https://antiboredom.github.io/p5.riso/index Demonstrates how to initialize a Riso object for a specific color layer, set its opacity, draw shapes to it, and then render all layers to the screen. This is fundamental for creating multi-color risograph prints. ```javascript let blueChannel; function setup(){ createCanvas(500, 500); blueChannel = new Riso("blue"); // instantiate riso object as blue layer blueChannel.fill(128); //set opacity blueChannel.rect(20, 20, 100, 100); //draw rect to blue layer drawRiso(); //draw to screen } ``` -------------------------------- ### Riso Constructor Source: https://antiboredom.github.io/p5.riso/index Initializes a Riso object, which represents a single-color graphics layer for Risograph printing. It can be configured with a specific color and dimensions. ```APIDOC ## new Riso(color, width, height) ### Description The base Riso object is a single-color p5 graphics object. Its constructor can take 3 parameters. ### Method `new Riso()` ### Parameters #### Path Parameters - **color** (string | array) - Required - A string set to a Risograph color name (e.g., "brightred", "blue", "orange") or an array with [r,g,b] values. - **width** (number) - Optional - The width of the riso canvas. Defaults to the width of the sketch. - **height** (number) - Optional - The height of the riso canvas. Defaults to the height of the sketch. ### Request Example ```javascript let blueChannel; //declare riso object function setup(){ createCanvas(500, 500); blueChannel = new Riso("blue"); // instantiate riso object as blue layer blueChannel.fill(128); //set opacity blueChannel.rect(20, 20, 100, 100); //draw rect to blue layer drawRiso(); //draw to screen } ``` ### Response #### Success Response (200) This constructor does not return a value directly, but initializes a Riso graphics object. #### Response Example ```json { "message": "Riso object created successfully" } ``` ### Notes Internally, the riso object extends p5's built-in graphics object. It is used similarly with a few exceptions. Pay attention to the order that you create each Riso object (each color layer). The `drawRiso()` function will display the layers in the order they are created, with the last created layer on top. If the top layer has an opacity of 255, you may not be able to see the layers underneath. Different color combinations may result in different blended colors. The following default colors are available: BLACK BURGUNDY BLUE GREEN MEDIUMBLUE BRIGHTRED RISOFEDERALBLUE PURPLE TEAL FLATGOLD HUNTERGREEN RED BROWN YELLOW MARINERED ORANGE FLUORESCENTPINK LIGHTGRAY METALLICGOLD CRIMSON FLUORESCENTORANGE CORNFLOWER SKYBLUE SEABLUE LAKE INDIGO MIDNIGHT MIST GRANITE CHARCOAL SMOKYTEAL STEEL SLATE TURQUOISE EMERALD GRASS FOREST SPRUCE MOSS SEAFOAM KELLYGREEN LIGHTTEAL IVY PINE LAGOON VIOLET ORCHID PLUM RAISIN GRAPE SCARLET TOMATO CRANBERRY MAROON RASPBERRYRED BRICK LIGHTLIME SUNFLOWER MELON APRICOT PAPRIKA PUMPKIN BRIGHTOLIVEGREEN BRIGHTGOLD COPPER MAHOGANY BISQUE BUBBLEGUM LIGHTMAUVE DARKMAUVE WINE GRAY CORAL WHITE AQUA MINT CLEARMEDIUM FLUORESCENTYELLOW FLUORESCENTRED FLUORESCENTGREEN ``` -------------------------------- ### Apply Halftone Pattern with halftoneImage Source: https://antiboredom.github.io/p5.riso/index Applies a halftone pattern to an image, allowing customization of dot shape, frequency, angle, and intensity. Optional parameters include dot shape ('line', 'square', 'circle', 'ellipse', 'cross'), frequency (lpi), rotation angle, and intensity (threshold). ```javascript let pink; let img; function preload() { img = loadImage('data/monkeys.jpg'); } function setup() { pixelDensity(1); createCanvas(img.width, img.height); pink = new Riso('fluorescentpink'); // create pink layer } function draw() { background(220); clearRiso(); let halftoned = halftoneImage(img, 'line', 3, 45, 90); // pass image to halftone with line dots, frequency of 3, angle of 45, and intensity of 90. pink.image(halftoned, 0, 0); // draw halftoned image drawRiso(); } ``` -------------------------------- ### Map Image Colors to Riso Layers with extractMappedChannels Source: https://antiboredom.github.io/p5.riso/index Maps colors from an input image to Riso color layers. Returns an array of images, each corresponding to a Riso layer. Accepts an optional 'steps' parameter for mapping accuracy (lower is more accurate, but can cause memory issues) and a 'perceptual' boolean to align color matching with human perception. ```javascript let layer1; let layer2; let img; function preload() { img = loadImage("data/no_threat.jpg"); } function setup() { pixelDensity(1); createCanvas(img.width, img.height); layer1 = new Riso("orange"); layer2 = new Riso("green"); let images = extractMappedChannels(img, 0.05); layer1.image(images[0], 0, 0); layer2.image(images[1], 0, 0); drawRiso(); } ``` -------------------------------- ### Riso.image(img, x, y, width, height) - Draw image to Riso layer Source: https://antiboredom.github.io/p5.riso/index Draws a p5.js image, video, or graphics object onto a specified Riso layer. The image is converted to grayscale and its color will match the layer's color. The opacity is controlled by the layer's fill value. Optional width and height parameters can resize the image. ```javascript let img; function preload() { img = loadImage("cat.jpg"); } function setup(){ createCanvas(500, 500); let orange = new Riso("orange"); orange.fill(200); orange.image(img, 0, 0); drawRiso(); } ``` -------------------------------- ### extractRGBChannel(img, channel) - Extract color channels Source: https://antiboredom.github.io/p5.riso/index Extracts a specific color channel (red, green, or blue) from a p5.js image and returns it as a new image. The 'channel' parameter can be the channel name as a string or its corresponding number (0 for red, 1 for green, 2 for blue). ```javascript // convert a color image into a red and blue print let img; function preload() { img = loadImage('cat.jpg') } function setup(){ createCanvas(500, 500); let blue = new Riso("blue"); let red = new Riso("red"); let justBlues = extractRGBChannel(img, "blue"); //extract blue from img and save as new image let justReds = extractRGBChannel(img, "red"); //extract red from img and save as new image blue.image(justBlues, 0, 0); //draw justblues to blue layer red.image(justReds, 0, 0); //draw justred to red layer drawRiso(); } ``` -------------------------------- ### Dither Image to One Color with ditherImage Source: https://antiboredom.github.io/p5.riso/index Reduces an image to a single color using dot patterns to simulate grayscale. Supports dither types: 'atkinson', 'floydsteinberg', 'bayer', or 'none'. The 'threshold' parameter applies only to 'bayer' and 'none' dither types, controlling the conversion point. 'none' simply thresholds pixels to black or clear. ```javascript let black; let img; let ditherType = 'atkinson'; function preload() { img = loadImage('data/no_threat.jpg'); } function setup() { pixelDensity(1); createCanvas(img.width, img.height); black = new Riso('black'); //create black layer } function draw() { background(220); let threshold = map(mouseX, 0, width, 0, 255); //change dither threshold with mouse position clearRiso(); let dithered = ditherImage(img, ditherType, threshold);//pass image to dither black.image(dithered, 0, 0); //draw dithered image drawRiso(); } function keyReleased() { //function to change dither type with a keypress if (key == 1) ditherType = 'atkinson'; else if (key == 2) ditherType = 'floydsteinberg'; else if (key == 3) ditherType = 'bayer'; else if (key == 4) ditherType = 'none'; } ``` -------------------------------- ### extractCMYKChannel(img, channel) - Extract CMYK color channels Source: https://antiboredom.github.io/p5.riso/index Extracts specific CMYK color channels (cyan, magenta, yellow, black) from a p5.js image and returns them as new images. The 'channel' parameter can be a channel name string, its corresponding number (0-3), or a channel set string (e.g., 'cy', 'mk', 'cyk'). ```javascript // convert a color image into a cyan and magenta print let img; function preload() { img = loadImage('cat.jpg') } function setup(){ createCanvas(500, 500); let blue = new Riso("blue"); let red = new Riso("red"); let justCyan = extractCMYKChannel(img, "cyan"); //extract cyan from img let justMagenta = extractCMYKChannel(img, "magenta"); //extract magenta from img blue.image(justCyan, 0, 0); //draw justCyan to blue layer red.image(justMagenta, 0, 0); //draw justMagenta to red layer drawRiso(); } ``` -------------------------------- ### risoNoFill() - Disable fill on all Riso layers Source: https://antiboredom.github.io/p5.riso/index A utility function that disables the fill for all Riso layers. This is a convenience function equivalent to calling noFill() on each Riso layer individually. It does not take any parameters. ```javascript risoNoFill(); ``` -------------------------------- ### Riso.fill(value) - Set fill opacity Source: https://antiboredom.github.io/p5.riso/index Sets the fill opacity for a Riso layer. The value ranges from 0 (transparent) to 255 (opaque). This affects subsequent drawing operations on that layer. Requires a Riso object instance. ```javascript function setup(){ createCanvas(500, 500); let blueChannel = new Riso("blue"); //create riso object, set to blue blueChannel.fill(255); // completely opaque blueChannel.ellipse(0, 0, 100, 100); //draw ellipse on blue layer blueChannel.fill(50); // fairly transparent blueChannel.ellipse(50, 50, 100, 100); blueChannel.fill(3); // almost invisible blueChannel.ellipse(75, 75, 100, 100); drawRiso(); } ``` -------------------------------- ### clearRiso() - Clear all Riso layers Source: https://antiboredom.github.io/p5.riso/index Clears all content from all Riso layers. This function is particularly useful when drawing to Riso layers within the draw() loop, allowing for dynamic updates. It does not take any parameters. ```javascript clearRiso(); ``` -------------------------------- ### risoNoStroke() - Disable stroke on all Riso layers Source: https://antiboredom.github.io/p5.riso/index A utility function that disables the stroke for all Riso layers. This is a convenience function equivalent to calling noStroke() on each Riso layer individually. It does not take any parameters. ```javascript risoNoStroke(); ``` -------------------------------- ### Riso.cutout(p5.Graphic) - Mask areas with another graphic Source: https://antiboredom.github.io/p5.riso/index Removes or masks portions of a Riso layer where it overlaps with another p5.js graphic object. This is useful for creating layered effects where one layer's content should not appear under another. It takes a p5.Graphic object as input. ```javascript function setup(){ createCanvas(500, 500); let blue = new Riso("blue"); //blue layer let red = new Riso("red"); //red layer blue.fill(255); blue.ellipse(130, 130, 100, 100); red.fill(255); red.textSize(100); red.text("hello",50, 170); //completely removes any intersection of red and blue //layers from the blue layer blue.cutout(red); drawRiso(); } ``` -------------------------------- ### Riso.stroke(value) - Set stroke opacity Source: https://antiboredom.github.io/p5.riso/index Sets the stroke opacity for a Riso layer. Similar to fill, the value ranges from 0 (transparent) to 255 (opaque). This affects the opacity of outlines drawn on the layer. Requires a Riso object instance. ```javascript function setup(){ createCanvas(500, 500); let orange = new Riso("orange"); orange.stroke(255); orange.strokeWeight(5); orange.rect(50, 50, 100, 100); drawRiso(); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.