Common coding terms for JavaScript, p5.js, and p5.riso used in these demos
No terms match your search.
let{} where it's declared.const[] Arraylet colors = ['pink', 'blue', 'yellow']. Items are numbered starting at 0.array[index]colors[0] returns the first item. Index starts at 0, so the last item is at array.length - 1.array.lengthfor (let i = 0; i < array.length; i++).array.push(item)array.map(fn)names.map(n => n.toUpperCase()) returns all names uppercased.array.filter(fn)true. Example: nums.filter(n => n > 10).array.forEach(fn)map, it doesn't return anything — use it for side effects like drawing.array.slice(start, end)arr.slice(0, 3) returns the first 3 items. Used after shuffle() to pick a random subset.array.includes(item)true if the item is found in the array, false otherwise.array.sort()arr.sort((a, b) => a - b).array.reduce(fn)nums.reduce((sum, n) => sum + n, 0).{} Objectlet dot = { x: 100, y: 200, size: 40 }. Used to group related data together.object.propertydot.size returns 40. Can also assign: dot.size = 60.Object.keys(obj)if / elseelse if chains multiple conditions.for loopfor (let i = 0; i < total; i++) { }.for...offor (let item of array) { }.condition ? a : bif/else. Returns a if condition is true, b if false. Example: x > 0 ? 'positive' : 'zero'.function name() { }return).() => { }array.map(item => item * 2).returnfunction double(n) { return n * 2; }.forEach, map, filter, and async operations like loadJSON.Math.random()Math.random() * 360. In p5, use random() instead — it's the same idea with a simpler API.Math.floor(n)floor(n) does the same thing without the Math. prefix. Combine with random() to get a random integer: floor(random(10)).Math.ceil(n)ceil(n). Opposite of Math.floor().Math.round(n)round(n).Math.min() / Math.max()Math.max(5, 3, 9) returns 9. Useful for clamping values. In p5, use constrain() to clamp within a range.parseInt(string)"42" to the integer 42. Returns NaN if the string doesn't start with a valid number.string.split(sep)'a,b,c'.split(',') returns ['a', 'b', 'c']..toUpperCase() / .toLowerCase()Setnew Set([...array]). Check membership with set.has(item).console.log()setup()createCanvas() here along with any one-time initialization code.draw()preload()setup() and waits for all loading to finish. Use it for loadImage(), loadJSON(), and loadTable() so assets are ready when the sketch starts.createCanvas(w, h)setup(). Returns a reference to the canvas element.pixelDensity(1)width / heightbackground(value)draw() to clear the previous frame.frameRate(n)draw() runs per second. Default is 60. Lower values slow down animation; useful for debugging or intentional effects.circle(x, y, d)(x, y) with diameter d. Uses the current fill() and stroke() settings.ellipse(x, y, w, h)(x, y) with width w and height h. If w === h, it's a circle.rect(x, y, w, h)(x, y) is the top-left corner. Add a 5th argument for rounded corners. Change reference point with rectMode(CENTER).line(x1, y1, x2, y2)stroke() and strokeWeight().triangle(x1, y1, x2, y2, x3, y3)fill(r, g, b)color() object. On a Riso layer, the single value controls ink density (0–255), not color.noFill()fill() again.stroke(r, g, b)fill().noStroke()strokeWeight(n)color(r, g, b)let c = riso.channelColor.text(str, x, y)(x, y). Styling is controlled by textSize(), textFont(), and fill().textSize(n)text() calls.textFont(name)loadFont().textAlign(h, v)text(). Horizontal: LEFT, CENTER, RIGHT. Vertical: TOP, CENTER, BOTTOM.textWidth(str)push() / pop()push() and pop() is isolated — changes don't leak out.translate(x, y)(x, y) pixels. Subsequent drawing is offset by this amount. Stack with push()/pop() to scope the effect.rotate(angle)radians(degrees) to convert. Combine with translate() to rotate around a point.rectMode(mode)rect() interprets its position. CORNER (default) uses top-left; CENTER uses the center point. Useful for centering shapes before rotating them.loadImage(path)p5.Image object. Must be called inside preload() so the image is ready before setup() runs.image(img, x, y)(x, y). Optionally pass width and height to resize: image(img, x, y, w, h).img.resize(w, h)p5.Image in place. Pass 0 for either dimension to scale it proportionally: img.resize(400, 0) sets width to 400 and auto-calculates height.filter(GRAY)mouseX / mouseYmousePressed()keyPressed()key variable inside it to see which key was pressed.keyif (key === 's') saveCanvas().noLoop()draw() from repeating — the sketch freezes on the current frame. Use when you want a static output or manual control over redrawing.loop()draw() after it was stopped with noLoop().redraw()draw() once manually. Use with noLoop() to redraw only when something changes — like after a keypress.random(min, max)min and max. Pass just one value for 0 to that value. Pass an array to pick a random element from it: random(['a','b','c']).randomSeed(n)draw() and press space to pick a new seed for a new composition.shuffle(array)randomSeed(). The original array is not modified. Use with slice() to pick a random subset without repeats.map(value, l1, h1, l2, h2)map(temp, 0, 100, 0, width) converts a temperature to a canvas x-position. The workhorse of data-driven design.constrain(value, min, max)min or above max. Prevents values from flying off the canvas or exceeding valid ranges.dist(x1, y1, x2, y2)sin(angle) / cos(angle)noise(x)random(), neighboring values are similar, producing organic textures and flows.loadJSON(url)preload() to ensure data is ready, or pass a callback as the second argument for loading after setup.loadTable(path, 'csv', 'header')p5.Table object. Use in preload(). The 'header' flag tells p5 the first row contains column names.table.getRowCount()table.getRow(i)p5.TableRow object. Then use row.getString(col) or row.getNum(col) to read values.row.getString(col) / row.getNum(col)getString returns text, getNum returns a number. Pass the column name (from the header row) as a string.saveCanvas(name, format)'png' or 'jpg'. Often triggered with a keypress: if (key === 's') saveCanvas('output', 'png').PI / TWO_PI / HALF_PIPI ≈ 3.14159 (half circle), TWO_PI = full circle, HALF_PI = quarter circle. Use with sin(), cos(), and rotate().LEFT / CENTER / RIGHT / TOP / BOTTOMtextAlign() and rectMode(). Written in caps — they're p5.js-specific named values.new Riso('COLOR')let pink = new Riso('FLUORESCENTPINK'). You draw to this object using the same methods as p5.js.clearRiso()draw() call. Must be the first thing in your draw loop — forgetting it causes layers to accumulate and fill solid.drawRiso()exportRiso()Riso.channelslayer.fill(density)layer.stroke(density)layer.fill().layer.noStroke() / layer.noFill()layer.circle() / .rect() / .line() / …drawRiso().layer.image(img, x, y)layer.text(str, x, y)layer.fill() to control ink density and with layer.textSize() and layer.textFont() to style.layer.push() / layer.pop()push()/pop(), but scoped to that layer.layer.translate() / layer.rotate()layer.erase() / layer.noErase()layer.noErase() to return to normal drawing mode.layer.channelColorp5.Color object representing the RGB screen preview color of this Riso layer. Useful for matching label colors, UI elements, or drawing swatches.layer.channelName'FLUORESCENTPINK'). Useful for labeling exports or displaying the active ink names.ditherImage(img, algorithm, threshold)p5.Image — draw it onto a Riso layer with layer.image().'atkinson' — high contrast, clean edges; 'floydsteinberg' — smooth gradients; 'bayer' — ordered grid pattern; 'none' — hard threshold only.halftoneImage(img, shape, freq, angle, intensity)p5.Image to draw onto a Riso layer.'circle', 'square', 'line', 'ellipse', 'cross'.RISOCOLORS.name (string) and a .color (p5.Color). Use random(RISOCOLORS) to pick one at random.RISOCOLORS[i].name / .color.name is the RISO ink name as a string (e.g., 'FLUORESCENTPINK'). .color is the screen-preview RGB color. Pass .name to new Riso() to create a layer in that color.