Advertisement
jille_Jr

CC: Dull Darude

Apr 7th, 2019
5,646
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.63 KB | None | 0 0
  1.  
  2. local speaker = peripheral.wrap("left")
  3.  
  4. local notes = {
  5.     ["F#1"]=0,    ["F#2"]=12,
  6.     ["Gb1"]=0,    ["Gb2"]=12,
  7.     ["G1"]=1,     ["G2"]=13,
  8.     ["G#1"]=2,    ["G#2"]=14,
  9.     ["Ab1"]=2,    ["Ab2"]=14,
  10.     ["A1"]=3,     ["A2"]=15,
  11.     ["A#1"]=4,    ["A#2"]=16,
  12.     ["Bb1"]=4,    ["Bb2"]=16,
  13.     ["B1"]=5,     ["B2"]=17,
  14.     ["C1"]=6,     ["C2"]=18,
  15.     ["C#1"]=7,    ["C#2"]=19,
  16.     ["Db1"]=7,    ["Db2"]=19,
  17.     ["D1"]=8,     ["D2"]=20,
  18.     ["D#1"]=9,    ["D#2"]=21,
  19.     ["Eb1"]=9,    ["Eb2"]=21,
  20.     ["E1"]=10,    ["E2"]=22,
  21.     ["F1"]=11,    ["F2"]=23,
  22.                   ["F#3"]=24,
  23.                   ["Gb3"]=24,
  24. }
  25.  
  26. local function playNote(instrument,note,volume)
  27.     volume = volume or 1
  28.     speaker.playNote(instrument,volume,notes[note])
  29. end
  30.  
  31. local function harp(note,volume)
  32.     playNote("harp",note,volume)
  33. end
  34.  
  35. --test
  36. local function a1()
  37.     harp "E1"
  38.     harp "G2"
  39.     harp "B2"
  40. end
  41.  
  42. local function a2()
  43.     harp "G2"
  44.     harp "C2"
  45.     harp "E2"
  46. end
  47.  
  48. local function a3()
  49.     harp "G2"
  50.     harp "B2"
  51.     harp "D2"
  52. end
  53.  
  54. local function a4()
  55.     harp "D1"
  56.     harp "F#2"
  57.     harp "A2"
  58. end
  59.  
  60. --[[
  61. --local bpm = 136
  62. --local bps = bpm / 60
  63. --local spb = 1 / bps
  64. --local quarter = spb / 4
  65. --]]
  66.  
  67. local function a(f,...)
  68.     local t={...}
  69.     for _,s in ipairs(t) do
  70.         if s > 0 then
  71.             f()
  72.             sleep(0.15 * s)
  73.         else
  74.             sleep(-0.15 * s)
  75.         end
  76.     end
  77. end
  78.  
  79. local function song()
  80.  
  81.     a(a1, 2,2,1,2,2)
  82.     a(a2, 1,2,2)
  83.     a(a3, 1,2,2)
  84.     a(a4, 1)
  85.  
  86.     a(a1, 2,2,1,2,2)
  87.     a(a2, 1)
  88.     a(a1, 2,2,1,2,2)
  89.     a(a2, 1)
  90.     a(a1, 2,2,1,2,2)
  91.  
  92.     a(a2, 1,2,2)
  93.     a(a3, 1,2,2)
  94.     a(a4, 1)
  95.  
  96.     a(a1, 2,2,1,2,2)
  97.     a(a2, 1)
  98.     a(a1, 2,2,1,2,2)
  99.     a(a2, 1)
  100.  
  101.     local t1 = 1/3
  102.     local t2 = 2/3
  103.     parallel.waitForAll(
  104.         function() a(a1, 2,2,1,2,2) end,
  105.         function() a(function()harp "B2" end, -t1,t1,t2,t2) end
  106.     )
  107.  
  108.     a(a2, 1,2,2)
  109.     a(a3, 1,2,2)
  110.     a(a4, 1)
  111.  
  112.     parallel.waitForAll(
  113.         function() a(a1, 2,2,1,2,2) end,
  114.         function() a(function()harp "B2" end, -t1,t1,t2,t2) end
  115.     )
  116.  
  117.     a(a2, 1)
  118.     a(a1, 2,2,1,2,2)
  119.     a(a2, 1)
  120.  
  121.     for i=1,4 do
  122.         parallel.waitForAll(
  123.             function() a(a1, 2,2,1) end,
  124.             function() a(function()harp "B2" end, -t1,t1,t2,t2) end
  125.         )
  126.     end
  127.  
  128.     for i=1,3 do
  129.         parallel.waitForAll(
  130.             function() a(a1, 2,2,1) end,
  131.             function() a(function()harp "B2" end, -t1,t1,t2,t1,t1) end
  132.         )
  133.     end
  134.  
  135.     parallel.waitForAll(
  136.         function() a(a1, 2,2,1) end,
  137.         function() a(function()harp "B2" end, -t1,t1,t2) end
  138.     )
  139.  
  140.     for j=1,3 do
  141.         a(a1, .5,.5,.5,.5,1)
  142.         a(a1, .5,.5,.5,.5,.5,.5,1)
  143.         a(a2, .5,.5,.5,.5,.5,.5,1)
  144.         a(a3, .5,.5,.5,.5,.5,.5,1)
  145.         a(a4, .5,.5)
  146.        
  147.         for i=1,3 do
  148.             a(a1, .5,.5,.5,.5,1)
  149.             a(a1, .5,.5,.5,.5,.5,.5,1)
  150.             a(a2, .5,.5)
  151.         end
  152.        
  153.         a(a2, .5,.5,.5,.5,1)
  154.         a(a3, .5,.5,.5,.5,.5,.5,1)
  155.         a(a4, .5,.5)
  156.     end
  157.  
  158. end
  159.  
  160. local function scrollWrite(text)
  161.     local w,h = term.getSize()
  162.    
  163.     text = string.rep(" ", w) .. text
  164.     term.clear()
  165.    
  166.     while #text > 0 do
  167.         sleep(0.5,text)
  168.         term.setCursorPos(1,h)
  169.         term.clearLine()
  170.         term.write(text)
  171.        
  172.         text = text:sub(2)
  173.     end
  174.     term.clear()
  175. end
  176.  
  177. local monitor = peripheral.wrap("bottom")
  178. term.redirect(monitor)
  179.  
  180. parallel.waitForAll(
  181.     function() scrollWrite("What's the song at 00:06?") end,
  182.     song
  183. )
  184.  
  185. term.redirect(term.native())
  186.  
  187. --eof
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement