Guest User

piano

a guest
Sep 11th, 2012
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.69 KB | None | 0 0
  1. wire="left"
  2.  
  3. function Main()
  4.  
  5.     term.clear()
  6.     term.setCursorPos(1,1)
  7.     print("PIANO! v1.0\nby Jahmaican\n\n| |   |   | | |   |   |   | |   |\n| | w | e | | | t | y | u | |   |\n| |___|___| | |___|___|___| |   |\n| a | s | d | f | g | h | j | k |\n|___|___|___|___|___|___|___|___|\n\n[Press SPACE to exit]")
  8.    
  9.     Keys()
  10. end
  11.  
  12. function Keys()
  13.     local event,p1=nil
  14.     event,p1=os.pullEvent("char")
  15.     rs.setBundledOutput(wire,0)
  16.     if p1=="a" then
  17.         Play("c1")
  18.     elseif p1=="s" then
  19.         Play("d")
  20.     elseif p1=="d" then
  21.         Play("e")
  22.     elseif p1=="f" then
  23.         Play("f")
  24.     elseif p1=="g" then
  25.         Play("g")
  26.     elseif p1=="h" then
  27.         Play("a")
  28.     elseif p1=="j" then
  29.         Play("h")
  30.     elseif p1=="k" then
  31.         Play("c2")
  32.     elseif p1=="w" then
  33.         Play("c1#")
  34.     elseif p1=="e" then
  35.         Play("d#")
  36.     elseif p1=="t" then
  37.         Play("f#")
  38.     elseif p1=="y" then
  39.         Play("g#")
  40.     elseif p1=="u" then
  41.         Play("a#")
  42.     elseif p1==" " then
  43.         Exit()
  44.     else
  45.         Keys()
  46.     end
  47. end
  48.  
  49. function Exit()
  50.     print("Bye!")
  51.     error()
  52. end
  53.  
  54. function Play(note)
  55.     local output=0
  56.     if note=="c1" then
  57.         output=colors.white
  58.     elseif note=="d" then
  59.         output=colors.orange
  60.     elseif note=="e" then
  61.         output=colors.magenta
  62.     elseif note=="f" then
  63.         output=colors.lightBlue
  64.     elseif note=="g" then
  65.         output=colors.yellow
  66.     elseif note=="a" then
  67.         output=colors.lime
  68.     elseif note=="h" then
  69.         output=colors.pink
  70.     elseif note=="c2" then
  71.         output=colors.gray
  72.     elseif note=="c1#" then
  73.         output=colors.lightGray
  74.     elseif note=="d#" then
  75.         output=colors.cyan
  76.     elseif note=="f#" then
  77.         output=colors.purple
  78.     elseif note=="g#" then
  79.         output=colors.blue
  80.     elseif note=="a#" then
  81.         output=colors.brown
  82.     end
  83.     rs.setBundledOutput(wire,output)
  84.      
  85.     Keys()
  86. end
  87.  
  88. Main()
Advertisement
Add Comment
Please, Sign In to add comment