Example 22 · Anything can be an instrument範例 22 · 什麼都能當樂器

p5 lag: smooth a jumpy valuep5 lag:讓跳動的數值變順

lag(micLevel, 0.03, 0.4) smooths a jumpy value the way TouchDesigner's Lag CHOP does, in the same seconds; scope() plots both in a corner of the page.lag(micLevel, 0.03, 0.4) 把跳動的數值變順,跟 TouchDesigner 的 Lag CHOP 一樣,秒數也一樣。scope() 在網頁角落畫出兩條線。

Try these three things試試這三件事

  1. Allow the microphone and clap: the left circle (micLevel) jumps, the right one (lagged) opens at once and closes slowly, like a VU meter.
  2. Watch the scope in the corner and the strip below: green is micLevel, yellow is lag(micLevel, 0.03, 0.4).
  3. Nothing to hear? 🎹 → 🥁 plays drums through the speakers, and a laptop's own microphone hears them.
  1. 允許麥克風,拍一下手:左邊的圓(micLevel)一抖一抖,右邊的圓(lag 後)立刻撐開、慢慢收,像 VU 表。
  2. 看角落的示波器和下面那一條:綠色是 micLevel,黃色是 lag(micLevel, 0.03, 0.4)。
  3. 身邊沒有聲音?🎹 → 🥁 讓喇叭打鼓,筆電自己的麥克風就聽得到。

Needs: Microphone.需要:麥克風。 No hardware? Use Drum machine.沒有硬體?用鼓機。

Read these lines讀這幾行

  • sketch.js:16–17 One call in draw(), nothing to declare: 0.03 s up, 0.4 s down.draw() 裡一行,不用宣告:上升 0.03 秒、下降 0.4 秒。
  • sketch.js:18–19 scope(value, 'label'): a plot in a corner of the page, never in a recording.scope(value, 'label'):畫在網頁角落,不會錄進影片。
  • sketch.js:35–36 trail() keeps the last 3 seconds and drawTrail() draws them on the canvas, so a recording has them.trail() 留住最近 3 秒,drawTrail() 把它畫在畫布上,錄影也錄得到。

In the docs文件裡: Values over time: lag, env, speed, spring, trail數值隨時間:lag、env、speed、spring、trail

Next: 09 MIDI controllers →下一個:09 MIDI 控制器 → All examples所有範例