open-audiovisual
Search GitHub

oav-p5 reference · Values over time (CHOP)

scope()#

functionoav-p5
scope(value, [label])

Also: OAVp5.chop.scope

Shows value in a small oscilloscope in the corner of the page and gives it back, so you can wrap any expression to watch it.

It is a CHOP's viewer: each label is one line in a small plot across the page from the 🎹, with the last 4 seconds of the value and its number now. Call it twice in a frame with two labels and you get two lines to compare, raw against smoothed. The scale is at least 0 to 1 and grows to hold whatever the values reach.

It lives on the page, not on the canvas: never in a recording or in 📷, and it never takes a click from the sketch. To draw the same line inside the work, use drawTrail().

Before you call it

Only inside draw(): anywhere else it just returns value. ?oav_scope=off hides it, and so does ?oav_hints=off, which is the one thing to know if it does not appear. See scope. The first call loads @openav/chop, which takes a few frames.

Parameters

NameTypeDescription
valueNumber | BooleanThe number to watch. A boolean is drawn as 0 or 1. Anything that is not a finite number is returned as it is and not drawn.
labelStringThe name of this line in the legend. Each label is one line, and a label longer than 9 characters is cut short there. Without one the line is numbered. optional

Returns

Number | Boolean Exactly value, so circle(x, y, scope(lag(micLevel, 0.03, 0.4), 'lag') * 300) works.

Notes

  • Unnamed calls find their memory by their order in draw(): the first lag() is the first lag, the second is the second. Put one inside an if, or in a loop whose length changes, and the order slips: a card says so, and from then on oav-p5 matches each call by the line it is written on. A name at the end is the sure way. Outside draw() an unnamed call has nothing to remember by: it returns what Returns says and a card says so.
  • OAVp5.chop.scope(…) is this function under another name. The lines keep coming from the last second: stop calling it for a second and its line leaves the plot.

Examples

jsOpenProcessing ↗
function setup() {
  createCanvas(400, 300);
}

function draw() {
  background(20);
  const wave = 0.5 + 0.5 * sin(frameCount * 0.05);
  circle(width / 2, height / 2, 40 + scope(wave, 'wave') * 200);   // watch it in the corner
}
The circle breathes, and a small plot in the corner of the page draws the same number as a moving line.
jsOpenProcessing ↗
function setup() {
  createCanvas(400, 300);
}

function draw() {
  background(20);
  const raw = frameCount % 120 < 60 ? 1 : 0;   // a square wave
  scope(raw, 'raw');
  const smooth = scope(lag(raw, 0.3, 0.6), 'lag');
  fill(255, 211, 107);
  circle(width / 2, height / 2, 40 + smooth * 200);
}
The corner plot shows two lines: the square wave and what lag() makes of it, rising in 0.3 seconds and falling in 0.6.

Related

  • drawTrail() Draws a line through values on the canvas, so it is in the work and in a recording: the oldest at x, lo at the bottom of the box, hi at the top.
  • trail() The last few seconds of value as an array, 60 values a second, oldest first and newest last (TouchDesigner's Trail CHOP).
  • lag() Follows value smoothly instead of jumping: up in up seconds, down in down seconds (TouchDesigner's Lag CHOP).
  • scope Whether scope() draws its oscilloscope in the corner of the page: on or off. hints=off turns it off too.
  • hints Whether oav-p5 shows its explaining cards beside the 🎹 (blocked microphone, no Web MIDI, an error in your callback): on or off.

p5/oav-p5.js, line 3101

↑ Back to top · All names