Posted 08 May 2013 - 04:43 AM
A little piano, you just have to build a 8*2 advanced screen, put a advanced computer on it and an iron bloc note on the computer then type :
pastebin get d4qjQGxA piano
Code :
pastebin get d4qjQGxA piano
Code :
Spoiler
--DETECTION INFOS MONITOR NOTEBLOC
function detectm()
print("DETECTM")
side = {"top","bottom","left","back","right","front"}
for i=1,#side do
m = peripheral.getType(side[i])
if m == "monitor" then
print("Monitor detected on " .. side[i] )
monitor = side[i]
elseif m == "note" then
print("Note bloc detected on " .. side[i] )
noteb = side[i]
end
end
if monitor and noteb then
m = peripheral.wrap(monitor)
notebox = peripheral.wrap(noteb)
m.clear()
m.setTextScale(0.5)
xs,ys = m.getSize()
if xs < 128 then
print("Your Monitor is too small (width: 6 monitor min)")
end
if ys < 20 then
print("Your monitor is too small (height: 2 monitor min)")
end
else
print("error, check that you have a 6x2(min) monitor and a Iron note box connected")
return error
end
end
--DRAW WHITE
function blanches()
print("BLANCHES")
x = (xs - 128) /2
y = ys - 20 - 2
w = 8
h = 20
topb = "+-------+"
mb = "| |"
m.setTextScale(0.5)
m.setCursorPos(x,y)
m.setTextColor(colors.black)
m.setBackgroundColor(colors.white)
for i=1,h do
g = y + (i-1)
for v=1,16 do
t = x + ((v-1) * w)
m.setCursorPos(t,g)
if (i == 1) or (i == h) then
m.write(topb)
else
m.write(mb)
end
end
end
end
--DRAW BLACK
function noires()
print("NOIRES")
x = (xs - 128) /2
y = ys - 20 - 2
w = 6
h = 12
patt = " "
pat2 = {1,1,1,0,1,1,0,1,1,1,0,1,1,0,1}
m.setBackgroundColor(colors.black)
for s=1,h do
g = y + (s-1)
t=x+6
for i=1,15 do
m.setCursorPos(t,g)
if pat2[i] == 1 then
m.write(patt)
end
t = t + 8
end
end
end
--MAP WHITES POS FOR CLICK
function mapblanches()
print("MAPB")
x = (xs - 128) /2
y = ys - 20 - 2
w = 8
h = 20
for i=1,h do
g = y + (i-1)
for v=1,16 do
t = x + ((v-1) * w)
table.insert(mapb,t)
end
end
end
--MAP BLACK
function mapnoires()
print("MAPN")
x = (xs - 128) /2
y = ys - 20 - 2
w = 6
h = 12
for s=1,h do
g = y + (s-1)
t=x+6
for i=1,#pat2 do
if pat2[i] == 1 then
table.insert(mapn,t)
end
t = t + 8
end
end
end
--PLAY NOTES
notesnoires = {0,2,4,7,9,12,14,16,19,21,24}
notesblanches = {30,1,3,5,6,8,10,11,13,15,17,18,20,22,23,30}
--CONVERT WHITE NUMBER INTO BLOCK NOTE NUMBER
function playblanche(a)
print("PLAYBLANCHE")
print("touche blanche " .. a .. " pressee")
if a <= #notesblanches then
g = notesblanches[a]
play(0,g)
end
end
--IDEM FOR BLACK
function playnoire(a)
print("PLAYNOIRE")
print("touche noire " .. a .. " pressee")
if a <= #notesnoires then
g = notesnoires[a]
play(0,g)
end
end
--PLAY CONVERTED NOTE
function play(a,B)/>/>/>/>/>
print("PLAY")
if b <= 24 then
notebox.playNote(a,B)/>/>/>/>/>
end
end
--DETECT AND LOCALIZE TOUCH ON SCREEN, RUN PLAYING FUNC
function touch()
print("TOUCH")
local a,b,tx,ty = os.pullEvent("monitor_touch")
print(a)
print(B)/>/>/>/>/>
if (tx<x) or (tx>(x+128)) or (ty<y) or (ty>(ty+20)) then
elseif (ty>y) and (ty<(y+12)) then
for i= 1,#mapn do
local o = mapn[i] - 1
if ( tx > o ) and ( tx < (o+5)) then
playnoire(i)
fnoire=1
end
end
end
if (ty>y) and (ty<(y+20)) and (fnoire == 0) then
for i=1,#mapb do
local o = mapb[i]
if (tx > o) and (tx < o+8) then playblanche(i) end
end
end
fnoire = 0
end
--START
tour = 0
mapb = {}
mapn = {}
if detectm() == error then
print("Error, can't run")
else
blanches()
noires()
mapblanches()
mapnoires()
while true do
touch()
end
end