Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- CONFIGURATION
- local speaker = peripheral.find("speaker")
- if not speaker then
- print("Error: speaker not found")
- return
- end
- -- Nyan Cat melody: instrument, pitch (in semitones relative to C‑note)
- local nyanMelody = {
- {"harp", 0}, {"harp", 2}, {"harp", 4}, {"harp", 5}, {"harp", 7}, {"harp", 5}, {"harp", 4}, {"harp", 2},
- {"harp", 0}, {"harp", 7}, {"harp", 5}, {"harp", 4}, {"harp", 2}, {"harp", 0}, {"harp", -2}, {"harp", -4},
- -- repeat to loop a few times
- }
- -- Harmony track adds richness
- local nyanHarmony = {
- {"bell", -12}, {"bell", -10}, {"bell", -8}, {"bell", -7}, {"bell", -5}, {"bell", -7}, {"bell", -8}, {"bell", -10},
- {"bell", -12}, {"bell", -5}, {"bell", -7}, {"bell", -8}, {"bell", -10}, {"bell", -12}, {"bell", -14}, {"bell", -16},
- }
- local noteDuration = 0.2
- local loopCount = 4
- -- Play a full bar of melody + harmony
- local function playBar()
- for i = 1, #nyanMelody do
- local instMelody, pitchMelody = table.unpack(nyanMelody[i])
- speaker.playNote(instMelody, 1.0, pitchMelody)
- local instHar, pitchHar = table.unpack(nyanHarmony[i] or {"harp", pitchMelody})
- speaker.playNote(instHar, 0.6, pitchHar)
- sleep(noteDuration)
- end
- end
- -- RUN
- print("Playing Nyan Cat...")
- for i = 1, loopCount do
- playBar()
- end
- print("Finished!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement