scope()#
functionoav-p5scope(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
| Name | Type | Description |
|---|---|---|
value | Number | Boolean | The 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. |
label | String | The 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 firstlag()is the first lag, the second is the second. Put one inside anif, 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. Outsidedraw()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
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
}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);
}Related
drawTrail()Draws a line throughvalueson the canvas, so it is in the work and in a recording: the oldest atx,loat the bottom of the box,hiat the top.trail()The last few seconds ofvalueas an array, 60 values a second, oldest first and newest last (TouchDesigner's Trail CHOP).lag()Followsvaluesmoothly instead of jumping: up inupseconds, down indownseconds (TouchDesigner's Lag CHOP).scopeWhetherscope()draws its oscilloscope in the corner of the page:onoroff.hints=offturns it off too.hintsWhether oav-p5 shows its explaining cards beside the 🎹 (blocked microphone, no Web MIDI, an error in your callback):onoroff.