Advertisement
BigBlow_

nyancatMusic

Jul 9th, 2025 (edited)
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.29 KB | None | 0 0
  1. -- CONFIGURATION
  2. local speaker = peripheral.find("speaker")
  3. if not speaker then
  4.   print("Error: speaker not found")
  5.   return
  6. end
  7.  
  8. -- Nyan Cat melody: instrument, pitch (in semitones relative to C‑note)
  9. local nyanMelody = {
  10.   {"harp", 0}, {"harp", 2}, {"harp", 4}, {"harp", 5}, {"harp", 7}, {"harp", 5}, {"harp", 4}, {"harp", 2},
  11.   {"harp", 0}, {"harp", 7}, {"harp", 5}, {"harp", 4}, {"harp", 2}, {"harp", 0}, {"harp", -2}, {"harp", -4},
  12.   -- repeat to loop a few times
  13. }
  14.  
  15. -- Harmony track adds richness
  16. local nyanHarmony = {
  17.   {"bell", -12}, {"bell", -10}, {"bell", -8}, {"bell", -7}, {"bell", -5}, {"bell", -7}, {"bell", -8}, {"bell", -10},
  18.   {"bell", -12}, {"bell", -5}, {"bell", -7}, {"bell", -8}, {"bell", -10}, {"bell", -12}, {"bell", -14}, {"bell", -16},
  19. }
  20.  
  21. local noteDuration = 0.2
  22. local loopCount = 4
  23.  
  24. -- Play a full bar of melody + harmony
  25. local function playBar()
  26.   for i = 1, #nyanMelody do
  27.     local instMelody, pitchMelody = table.unpack(nyanMelody[i])
  28.     speaker.playNote(instMelody, 1.0, pitchMelody)
  29.     local instHar, pitchHar = table.unpack(nyanHarmony[i] or {"harp", pitchMelody})
  30.     speaker.playNote(instHar, 0.6, pitchHar)
  31.     sleep(noteDuration)
  32.   end
  33. end
  34.  
  35. -- RUN
  36. print("Playing Nyan Cat...")
  37. for i = 1, loopCount do
  38.   playBar()
  39. end
  40. print("Finished!")
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement