Example 19 · Run a show範例 19 · 演出控制

p5 one line of rhythmp5 一行節奏

startDrums("bd*4, [~ sd]*2, hh*8") writes the drums as one line of rhythm; drumPhase and beatPhase turn a hand once a bar and swell a circle on every beat.startDrums("bd*4, [~ sd]*2, hh*8") 用一行字寫鼓,drumPhase、beatPhase 讓指針一小節轉一圈、圓在每一拍鼓起來。

Try these three things試試這三件事

  1. Click the page once to hear it. The card at the top shows the line, and the word that sounds lights up.
  2. Click the line on the card and change hh*8 to hh*16, or bd*4 to bd(3,8): pause, and it plays.
  3. Make a typo: the word turns red, a card says what is wrong, and the last line that worked keeps playing.
  1. 點一下畫面就有聲音。上方的卡片顯示那一行,正在響的字會亮。
  2. 點卡片上那一行,把 hh*8 改成 hh*16,或把 bd*4 改成 bd(3,8):停手就換。
  3. 故意打錯一個字:那個字變紅,卡片說哪裡錯,鼓機繼續打上一個能用的版本。

No hardware needed. Drum machine.不需要硬體。鼓機。

Read these lines讀這幾行

  • sketch.js:7 The rhythm is one line: bd kick, sd snare, hh hat, ~ a rest, *n n times, and a comma starts another layer.節奏就是一行字:bd 大鼓、sd 小鼓、hh 鈸、~ 休息、*n 打 n 下,逗號後面是疊上去的另一層。
  • sketch.js:26 drumPhase: how far through the bar, 0 to 1, smooth. The hand turns once a bar.drumPhase:這一小節走到哪,0 到 1,連續的。指針一小節轉一圈。
  • sketch.js:35 1 - beatPhase is largest as each beat starts and shrinks towards the next.1 - beatPhase 在每一拍開頭最大,慢慢縮到下一拍。

In the docs文件裡: One line of rhythm一行節奏

Next: 20 p5 rhythm you can see →下一個:20 p5 看得見的節奏 → All examples所有範例