Skip to content

Instantly share code, notes, and snippets.

@CodeaLuis
Created November 17, 2013 18:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CodeaLuis/7516348 to your computer and use it in GitHub Desktop.
Save CodeaLuis/7516348 to your computer and use it in GitHub Desktop.
Codea Project Gist Created with AutoGist
AutoGist Tab Order Version: 2.2.8
------------------------------
This file should not be included in the Codea project.
#K12
#Lesskeys
#Main
#BlackButtons
#buttons
#moreKeys
#Piano2
#Texts
#piano1
---------------------------------------
--creamos la clas BotonesNegros class()
---------------------------------------
BotonesNegros = class()
function BotonesNegros:init()
-------------------------
--> creamos nuevos tonos
-------------------------
newBotones = 10
------------------------------------------------
--> creamos los tonos de los botones superiores
------------------------------------------------
_A = {nota1=1,nota2=2,nota3=3,nota4=4,nota5=5,nota6=6,nota7=7,
nota8=8,nota9=9,nota10=10}
------------------------------------------------
--> escalamos las notas de los botones de arrib
------------------------------------------------
scale = {"nota1","nota2","nota3","nota4","nota5","nota6","nota7","nota10"}
tonosSuperiores = nil
toques = {}
test = 0
end
function BotonesNegros:draw()
--nueva tabla
teclasArriba_1 = {}
for w,touch in pairs(toques) do
x = touch.x
x = math.ceil(x/WIDTH*newBotones)
if x > 0 and CurrentTouch.y >= HEIGHT/2+130 then
table.insert(teclasArriba_1,x)
self:getSoundUp()
end
end
for w = 1 , newBotones do
-----------------------
--> probando sombra
-----------------------
pushStyle()
fill(230)
roundRect((w-1)*WIDTH/newBotones+12.5,HEIGHT/2+113,WIDTH/newBotones-28,WIDTH/2-470,11)
popStyle()
----------------------
--> Botones negros
----------------------
pushStyle()
fill(23)
roundRect((w-1)*WIDTH/newBotones+16,HEIGHT/2+120,WIDTH/newBotones-35,WIDTH/2-242,10)
popStyle()
-----------------------------------------
--> recta encima de los botones negros
-----------------------------------------
pushStyle()
fill(76)
roundRect((w-1)*WIDTH/newBotones+24,HEIGHT/2+147,WIDTH/newBotones-51,WIDTH/2-272,7)
popStyle()
end
for w,r in pairs(teclasArriba_1) do
-- pushStyle()
fill(95)
stroke(23)
strokeWidth(4.5)
rect((r-1)*WIDTH/newBotones+24,HEIGHT/2+147,WIDTH/newBotones-51,WIDTH/2-225)
-- popStyle()
end
end
function BotonesNegros:getSoundUp()
button = scale[x]
sound(SOUND_BLIT,_A[button])
end
function BotonesNegros:touched(touch)
if touch.state == ENDED then
toques[touch.id] = nil
else
toques[touch.id] = touch
end
end
Buttons = class()
---------------------------------
--> A SIMPLE BUUTON CLASS
---------------------------------
function Buttons:init(x,y,txt,funct,Mode,l,h)
self.x = x
self.y = y
fontSize(30)
font("Georgia-Bold")
self.txt = txt
self.Sl,self.Sh = textSize(self.txt)
self.funct = funct
self.l=l or self.Sl+20
self.h=h or self.Sh+20
self.mode=Mode
self.colour=color(175, 158, 44, 255)
end
function Buttons:draw()
pushStyle()
fontSize(30)
font("Copperplate-Bold")
fill(self.colour)
if self.mode then
text(self.txt,self.x+self.l/2,self.y+self.h/2)
else
text(self.txt,self.x,self.y)
end
popStyle()
end
function Buttons:touched(touch)
if self.mode then
self.tx=touch.x-self.l/2
self.ty=touch.y-self.h/2
else
self.tx = touch.x
self.ty = touch.y
end
if self.tx<=self.x + self.l/2 and self.tx>=self.x - self.l/2 and
self.ty>=self.y - self.h/2 and self.ty<=self.y + self.h/2 then
if touch.state==BEGAN then
self.colour=color(251, 251, 251, 255)
self.press=true
elseif touch.state == ENDED and self.press then
self.colour=color(255, 255, 255, 255)
self.funct()
sound(SOUND_PICKUP, 89899)
end
else
self.colour=color(0, 0, 0, 255)
end
if touch.state==ENDED then
self.colour=color(0, 0, 0, 255)
self.press=false
end
end
k12 = class()
function k12:init()
-- you can accept and set parameters here
touches_M12 = {}
--a = Botones()
-----------------------
--> CALL BUTTONS CLASS
-----------------------
BackOriginKeys12 = Buttons(WIDTH/2-463,HEIGHT/2-194,"...",MoreKeys)
texts = Texts()
song12 = {nota1=85,nota2=321,nota3=48,nota4=63,
nota5=60,nota6=68,nota7=11,nota8=60,nota9=22,
nota10=22,nota11=52,nota12=91,nota13=112}
--> SCALE THE NOTES
scale = {"nota1","nota2","nota3","nota4","nota5","nota6",
"nota7","nota8","nota9","nota10",
"nota11","nota12","nota13"}
keys12 = 12
end
function k12:draw()
-- Codea does not automatically call this method
background(0,0,0,255)
tocarNotas12 = {}
for r,touch in pairs(touches_M12) do
x = touch.x
x = math.ceil(x/WIDTH*keys12)
if CurrentTouch.y <= HEIGHT/2+100 and CurrentTouch.y >= HEIGHT/2-180 and x > 0 then
table.insert(tocarNotas12,x)
--function ponermusica
self:getSound()
end
end
pushStyle()
font("Georgia-BoldItalic")
fontSize(40)
fill(202, 203, 217, 135)
text("PIANO",WIDTH/2,HEIGHT/2-280)
text("Developed by luismi",WIDTH/2,HEIGHT/2-330)
popStyle()
for k = 1 , keys12 do
fill(255, 255, 255, 255)
stroke(0)
strokeWidth(1)
roundRect((k-1)*WIDTH/keys12,HEIGHT-559,WIDTH/keys12,HEIGHT/2+183,20)
end
texts:k12()
for k,var12 in pairs(tocarNotas12) do
fill(0, 0, 0, 43)
stroke(0)
strokeWidth(5.8)
rect((var12-1)*(WIDTH/keys12),HEIGHT - 560,WIDTH/keys12,HEIGHT/2+190)
end
-- a:draw()
BackOriginKeys12:draw()
pushStyle()
fill(255)
stroke(255)
strokeWidth(6)
line(33,184,59,184)
popStyle()
end
function k12:touched(touch)
if touch.state == ENDED then
touches_M12[touch.id]=nil
else
touches_M12[touch.id]=touch
end
BackOriginKeys12:touched(touch)
--a:touched(touch)
-- Codea does not automatically call this method
end
function k12:getSound()
h12 = scale[x]
sound(SOUND_BLIT,song12[h12])
end
---------------------------------------
---------------------------------------
---------------------------------------
--creamos la clas BotonesNegros class()
---------------------------------------
Botones12 = class()
function Botones12:init()
-------------------------
--> creamos nuevos tonos
-------------------------
newBotoness12 = 12
------------------------------------------------
--> creamos los tonos de los botones superiores
------------------------------------------------
_AA12 = {nota1=1,nota2=2,nota3=3,nota4=4,nota5=5,nota6=6,nota7=7,
nota8=8,nota9=9,nota10=10,nota11=11,nota12=12}
------------------------------------------------
--> escalamos las notas de los botones de arrib
------------------------------------------------
scale = {"nota1","nota2","nota3","nota4","nota5","nota6","nota7",
"nota8","nota9","nota10","nota11","nota12"}
tonosSuperiores = nil
toques12 = {}
test = 0
end
function Botones12:draw()
--nueva tabla
teclasArriba_12 = {}
for w,touch in pairs(toques12) do
x = touch.x
x = math.ceil(x/WIDTH*newBotoness12)
if x > 0 and CurrentTouch.y >= HEIGHT/2+130 then
table.insert(teclasArriba_12,x)
self:getSoundUp()
end
end
for w = 1 , newBotoness12 do
-----------------------
--> probando sombra
-----------------------
pushStyle()
fill(230)
roundRect((w-1)*WIDTH/newBotoness12+12.5,HEIGHT/2+113,WIDTH/newBotoness12-28,WIDTH/2-470,11)
popStyle()
----------------------
--> Botones negros
----------------------
pushStyle()
fill(23)
roundRect((w-1)*WIDTH/newBotoness12+16,HEIGHT/2+120,WIDTH/newBotoness12-35,WIDTH/2-242,10)
popStyle()
-----------------------------------------
--> recta encima de los botones negros
-----------------------------------------
pushStyle()
fill(76)
roundRect((w-1)*WIDTH/newBotoness12+24,HEIGHT/2+147,WIDTH/newBotoness12-51,WIDTH/2-272,7)
popStyle()
end
for w,r in pairs(teclasArriba_12) do
-- pushStyle()
fill(95)
stroke(23)
strokeWidth(4.5)
rect((r-1)*WIDTH/newBotoness12+24,HEIGHT/2+147,WIDTH/newBotoness12-51,WIDTH/2-225)
-- popStyle()
end
end
function Botones12:getSoundUp()
button12 = scale[x]
sound(SOUND_BLIT,_AA12[button12])
end
function Botones12:touched(touch)
if touch.state == ENDED then
toques12[touch.id] = nil
else
toques12[touch.id] = touch
end
end
---------------------
--> class for 9 KEYS
---------------------
Lesskeys = class()
function Lesskeys:init()
SONGK9 = {nota1=85,nota2=321,nota3=48,nota4=63,
nota5=60,nota6=68,nota7=11,nota8=60,nota9=22,nota10=54}
--> SCALE THE NOTES
scale = {"nota1","nota2","nota3","nota4","nota5","nota6",
"nota7","nota8","nota9","nota10"}
keys9 = 9
sty = Texts()
touchesK9 = {}
a = Buttons(WIDTH/2+470,HEIGHT/2-195,"...",setup)
end
function Lesskeys:draw()
k9notes = {}
-- This sets a dark background color
for r,touch in pairs(touchesK9) do
x = touch.x
x = math.ceil(x/WIDTH*keys9)
if CurrentTouch.y <= HEIGHT/2+100 and CurrentTouch.y >= HEIGHT/2-180 and x > 0 then
table.insert(k9notes,x)
--function ponermusica
self:d()
end
end
background(0, 0, 0, 255)
pushStyle()
font("Georgia-BoldItalic")
fontSize(40)
fill(202, 203, 217, 135)
text("PIANO",WIDTH/2,HEIGHT/2-280)
text("Developed by luismi",WIDTH/2,HEIGHT/2-330)
popStyle()
for m = 1 , keys9 do
fill(255, 255, 255, 255)
stroke(0)
strokeWidth(1)
roundRect((m-1)*WIDTH/keys9,HEIGHT-559,WIDTH/keys9,HEIGHT/2+183,20)
end
-----------------------------
--> We Show the stile Piano1
-----------------------------
--style:StylePiano1()
for m,n in pairs(k9notes) do
fill(0, 0, 0, 43)
stroke(0)
strokeWidth(5.8)
rect((n-1)*(WIDTH/keys9),HEIGHT - 560,WIDTH/keys9,HEIGHT/2+190)
pushStyle()
end
-- Do your drawing here
-- mas:draw()-- siguiente piano (mas button)
sty:less()
a:draw()
pushStyle()
stroke(255)
strokeWidth(6)
fill(255)
line(973,184,995,184)
line(985,172,985,196)
popStyle()
end
function Lesskeys:touched(touch)
if touch.state == ENDED then
touchesK9[touch.id]=nil
else
touchesK9[touch.id]=touch
end
a:touched(touch)
end
function Lesskeys:d()
s = scale[x]
sound(SOUND_BLIT,SONGK9[s])
end
---------------------------------------
--creamos la clas BotonesNegros class()
---------------------------------------
Botonesk9 = class()
function Botonesk9:init()
-------------------------
--> creamos nuevos tonos
-------------------------
newBotonessk9 = 9
------------------------------------------------
--> creamos los tonos de los botones superiores
------------------------------------------------
k9 = {nota1=1,nota2=2,nota3=3,nota4=4,nota5=5,nota6=6,nota7=7,
nota8=8,nota9=9}
------------------------------------------------
--> escalamos las notas de los botones de arrib
------------------------------------------------
scale = {"nota1","nota2","nota3","nota4","nota5","nota6","nota7",
"nota8","nota9"}
toquesk9 = {}
end
function Botonesk9:draw()
--nueva tabla
teclasArriba_1k9 = {}
for w,touch in pairs(toquesk9) do
x = touch.x
x = math.ceil(x/WIDTH*newBotonessk9)
if x > 0 and CurrentTouch.y >= HEIGHT/2+130 then
table.insert(teclasArriba_1k9,x)
self:getSound()
end
end
for p = 1 , newBotonessk9 do
-----------------------
--> probando sombra
-----------------------
pushStyle()
fill(230)
roundRect((p-1)*WIDTH/newBotonessk9+12.5,HEIGHT/2+113,WIDTH/newBotonessk9-28,WIDTH/2-470,11)
popStyle()
----------------------
--> Botones negros
----------------------
pushStyle()
fill(23)
roundRect((p-1)*WIDTH/newBotonessk9+16,HEIGHT/2+120,WIDTH/newBotonessk9-35,WIDTH/2-242,10)
popStyle()
-----------------------------------------
--> recta encima de los botones negros
-----------------------------------------
pushStyle()
fill(76)
roundRect((p-1)*WIDTH/newBotonessk9+24,HEIGHT/2+147,WIDTH/newBotonessk9-51,WIDTH/2-272,7)
popStyle()
end
for p,rr in pairs(teclasArriba_1k9) do
-- pushStyle()
fill(95)
stroke(23)
strokeWidth(4.5)
rect((rr-1)*WIDTH/newBotonessk9+24,HEIGHT/2+147,WIDTH/newBotonessk9-51,WIDTH/2-225)
-- popStyle()
end
end
function Botonesk9:getSound()
p = scale[x]
sound(SOUND_BLIT,k9[p])
end
function Botonesk9:touched(touch)
if touch.state == ENDED then
toquesk9[touch.id] = nil
else
toquesk9[touch.id] = touch
end
end
PROJECTNAME = "AutoGist"
VERSION = "2.2.8"
--Project: PIANO
--Version: beta 2.2.8
--Comments: FINAL
-- Piano
-------------------
--> MAIN PROJECT
-------------------
-- Use this function to perform your initial setup
function setup()
supportedOrientations(LANDSCAPE_ANY)
displayMode(FULLSCREEN)
saveProjectInfo("Author","luismi")
saveProjectInfo("Description","PIANO desarrollandolo")
readProjectInfo("Author")
readProjectInfo("Description")
PhysicsBodies = {}
------------------------
--> imagen twolivesleft
------------------------
TwolivesleftImage = nil
----------------------
--call http.request
----------------------
http.request("http://twolivesleft.com/logo.png",loadImagen)
-------------------------------------------
--> BLACKS BOTONS (WORKING IN THAT SOUND)
-------------------------------------------
black = BotonesNegros()
-----------------------
--> LEES KEYS CLASS
-----------------------
z = Lesskeys()
-----------------------
--> 1er PIANO CLASS
-----------------------
a = piano1()
-----------------------
--> 2do PIANO CLASS
-----------------------
r = piano2()
-----------------------
--> MORE KEYS CLASS
-----------------------
g = moreKeys()
-----------------------
--> CLASS BOTON
-----------------------
t = Botones()
-----------------------
--> K12 CLASS
-----------------------
p = k12()
-----------------------
--> Botones12 class
-----------------------
q = Botones12()
-----------------------
--> Botones k9
-----------------------
o = Botonesk9()
GameState = "tonos"
end
function draw()
if GameState == "k9" then
z:draw()
o:draw()
elseif GameState == "tonos" then
a:draw()
black:draw()
elseif GameState == "nuevosTonos" then
r:draw()
black:draw()
elseif GameState == "atras" then
a:draw()
black:draw()
elseif GameState == "more" then
g:draw()
t:draw()
elseif GameState == "k12" then
p:draw()
q:draw()
end
if twolivesleftImage ~= nil then
sprite(twolivesleftImage,WIDTH/2+400,HEIGHT/2-310,140)
end
--dibujamos los cambios de estado
end
--------------------------------------------------
--> MAKE A ROUND RECT FOR THE KEYS
--> INPORTED FROM ANOTHER PROYECT(CODEA EXAMPLES)
--------------------------------------------------
function roundRect(x,y,w,h,r)
pushStyle()
insetPos = vec2(x+r,y+r)
insetSize = vec2(w-2*r,h-2*r)
local red,green,blue,a = fill()
stroke(red,green,blue,a)
noSmooth()
rectMode(CORNER)
rect(insetPos.x,insetPos.y,insetSize.x,insetSize.y)
if r > 0 then
smooth()
lineCapMode(ROUND)
strokeWidth(r*1.84)
line(insetPos.x, insetPos.y,
insetPos.x + insetSize.x, insetPos.y)
line(insetPos.x, insetPos.y,
insetPos.x, insetPos.y + insetSize.y)
line(insetPos.x, insetPos.y + insetSize.y,
insetPos.x + insetSize.x, insetPos.y + insetSize.y)
line(insetPos.x + insetSize.x, insetPos.y,
insetPos.x + insetSize.x, insetPos.y + insetSize.y)
end
popStyle()
end
function loadImagen(imagen)
twolivesleftImage = imagen
end
function touched(touch)
-- if the state change , we show the staff(button back)
if GameState == "k9" then
z:touched(touch)
o:touched(touch)
elseif GameState == "tonos" then
a:touched(touch)
black:touched(touch)
elseif GameState == "nuevosTonos" then
r:touched(touch)
black:touched(touch)
elseif GameState == "atras" then
a:touched(touch)
black:touched(touch)
elseif GameState == "more" then
g:touched(touch)
t:touched(touch)
elseif GameState == "k12" then
p:touched(touch)
q:touched(touch)
end
end
--function Change state (cambiampos el estado de la pantalla)
--para colocar mas teclas del piano
-------------------------
--> CHANGE THE STATE
-------------------------
function ChangeState(State,funct)
for k,v in pairs(PhysicsBodies) do
v:destroy()
v=nil
end
PhysicsBodies={}
funct()
GameState=State
end
--realizamos cambio de estados
--we created the function (funcion). we call in ChangeState another function (piano2setup)
function funcion()
ChangeState("nuevosTonos",r.init)
end
function home()
ChangeState("tonos",a.init)
end
function back()
ChangeState("atras",setup)
end
function MoreKeys()
ChangeState("more",g.init)
end
function KEYS12()
ChangeState("k12",p.init)
end
function KEYS9()
ChangeState("k9",z.init)
end
moreKeys = class()
function moreKeys:init()
-- you can accept and set parameters here
touches_M = {}
--a = Botones()
-----------------------
--> CALL BUTTONS CLASS
-----------------------
keys10 = Buttons(WIDTH/2-463,HEIGHT/2-194,"...",back)
keys12 = Buttons(WIDTH/2+467,HEIGHT/2-194,"..",KEYS12)
e = Texts()
song = {nota1=85,nota2=321,nota3=48,nota4=63,
nota5=60,nota6=68,nota7=11,nota8=60,nota9=22,
nota10=22,nota11=52,nota12=91,nota13=112}
--> SCALE THE NOTES
scale = {"nota1","nota2","nota3","nota4","nota5","nota6",
"nota7","nota8","nota9","nota10",
"nota11","nota12","nota13"}
keys = 11
end
function moreKeys:draw()
-- Codea does not automatically call this method
background(0,0,0,255)
tocarNotas = {}
for r,touch in pairs(touches_M) do
x = touch.x
x = math.ceil(x/WIDTH*keys)
if CurrentTouch.y <= HEIGHT/2+100 and CurrentTouch.y >= HEIGHT/2-180 and x > 0 then
table.insert(tocarNotas,x)
--function ponermusica
self:getSound()
end
end
pushStyle()
font("Georgia-BoldItalic")
fontSize(40)
fill(202, 203, 217, 135)
text("PIANO",WIDTH/2,HEIGHT/2-280)
text("Developed by luismi",WIDTH/2,HEIGHT/2-330)
popStyle()
for var = 1 , keys do
fill(255, 255, 255, 255)
stroke(0)
strokeWidth(1)
roundRect((var-1)*WIDTH/keys,HEIGHT-559,WIDTH/keys,HEIGHT/2+183,20)
end
e:StyleMoreKeys1()
for var,var1 in pairs(tocarNotas) do
fill(0, 0, 0, 43)
stroke(0)
strokeWidth(5.8)
rect((var1-1)*(WIDTH/keys),HEIGHT - 560,WIDTH/keys,HEIGHT/2+190)
end
-- a:draw()
-- keys10:draw()
keys12:draw()
pushStyle()
fill(255)
stroke(255)
strokeWidth(6)
line(33,184,59,184)
popStyle()
pushStyle()
stroke(255)
strokeWidth(6)
fill(255)
line(973,184,995,184)
line(985,172,985,196)
popStyle()
end
function moreKeys:touched(touch)
if touch.state == ENDED then
touches_M[touch.id]=nil
else
touches_M[touch.id]=touch
end
keys12:touched(touch)
keys10:touched(touch)
--a:touched(touch)
-- Codea does not automatically call this method
end
function moreKeys:getSound()
h = scale[x]
sound(SOUND_BLIT,song[h])
end
---------------------------------------
---------------------------------------
---------------------------------------
--creamos la clas BotonesNegros class()
---------------------------------------
Botones = class()
function Botones:init()
-------------------------
--> creamos nuevos tonos
-------------------------
newBotoness = 11
------------------------------------------------
--> creamos los tonos de los botones superiores
------------------------------------------------
_AA = {nota1=1,nota2=2,nota3=3,nota4=4,nota5=5,nota6=6,nota7=7,
nota8=8,nota9=9,nota10=10,nota11=11}
------------------------------------------------
--> escalamos las notas de los botones de arrib
------------------------------------------------
scale = {"nota1","nota2","nota3","nota4","nota5","nota6","nota7",
"nota8","nota9","nota10"}
tonosSuperiores = nil
toques = {}
test = 0
end
function Botones:draw()
--nueva tabla
teclasArriba_1 = {}
for w,touch in pairs(toques) do
x = touch.x
x = math.ceil(x/WIDTH*newBotoness)
if x > 0 and CurrentTouch.y >= HEIGHT/2+130 then
table.insert(teclasArriba_1,x)
self:getSoundUp()
end
end
for w = 1 , newBotoness do
-----------------------
--> probando sombra
-----------------------
pushStyle()
fill(230)
roundRect((w-1)*WIDTH/newBotoness+12.5,HEIGHT/2+113,WIDTH/newBotoness-28,WIDTH/2-470,11)
popStyle()
----------------------
--> Botones negros
----------------------
pushStyle()
fill(23)
roundRect((w-1)*WIDTH/newBotoness+16,HEIGHT/2+120,WIDTH/newBotoness-35,WIDTH/2-242,10)
popStyle()
-----------------------------------------
--> recta encima de los botones negros
-----------------------------------------
pushStyle()
fill(76)
roundRect((w-1)*WIDTH/newBotoness+24,HEIGHT/2+147,WIDTH/newBotoness-51,WIDTH/2-272,7)
popStyle()
end
for w,r in pairs(teclasArriba_1) do
-- pushStyle()
fill(95)
stroke(23)
strokeWidth(4.5)
rect((r-1)*WIDTH/newBotoness+24,HEIGHT/2+147,WIDTH/newBotoness-51,WIDTH/2-225)
-- popStyle()
end
end
function Botones:getSoundUp()
button = scale[x]
sound(SOUND_BLIT,_AA[button])
end
function Botones:touched(touch)
if touch.state == ENDED then
toques[touch.id] = nil
else
toques[touch.id] = touch
end
end
---------------------------------
--> WE MAKE THE FIRS PIANO CLASS
---------------------------------
------------------
--> PIANO1 CLASS
------------------
piano1 = class()
function piano1:init()
----------------
--> Call class
----------------
style = Texts()
r = piano2()
o = 0
print("piano")
--> WE CREATE THE TONES
--> DO,RE,MI,FA,SO
---------------
--> NOTA1 (DO)
--> NOTA2 (RE)
--> NOTA3 (MI)
--> NOTA+1...
---------------
notas = {nota1=85,nota2=321,nota3=48,nota4=63,
nota5=60,nota6=68,nota7=11,nota8=60,nota9=22,
nota10=23}
--> SCALE THE NOTES
scale = {"nota1","nota2","nota3","nota4","nota5","nota6",
"nota7","nota8","nota9","nota10"}
-- a color table , not used yet
colores = {color(183, 30, 31, 136),color(215, 192, 12, 145),
color(6, 247, 4, 121),color(3, 89, 253, 113)}
touches = {}
less = Buttons(WIDTH/2-460,HEIGHT/2-195,"..",KEYS9)
mas = Buttons(WIDTH/2+400,HEIGHT/2-200,"mas",funcion)
moreKEYS = Buttons(WIDTH/2+470,HEIGHT/2-194,"..",MoreKeys)
teclas = 10 --> NUMBERS OF KEYS
end
------------------------
--> DRAW FUNCTION
------------------------
function piano1:draw()
tocarNotas = {}
notasAbajo = {}
-- This sets a dark background color
for r,touch in pairs(touches) do
x = touch.x
x = math.ceil(x/WIDTH*teclas)
if CurrentTouch.y <= HEIGHT/2+100 and CurrentTouch.y >= HEIGHT/2-180 and x > 0 then
table.insert(tocarNotas,x)
--function ponermusica
self:tocarSonido()
end
end
background(0, 0, 0, 255)
pushStyle()
font("Georgia-BoldItalic")
fontSize(40)
fill(202, 203, 217, 135)
text("PIANO",WIDTH/2,HEIGHT/2-280)
text("Developed by luismi",WIDTH/2,HEIGHT/2-330)
popStyle()
for s = 1 , teclas do
fill(255, 255, 255, 255)
stroke(0)
strokeWidth(1)
roundRect((s-1)*WIDTH/teclas,HEIGHT-559,WIDTH/teclas,HEIGHT/2+183,20)
end
-----------------------------
--> We Show the stile Piano1
-----------------------------
style:StylePiano1()
for s,v in pairs(tocarNotas) do
fill(0, 0, 0, 43)
stroke(0)
strokeWidth(5.8)
rect((v-1)*(WIDTH/teclas),HEIGHT - 560,WIDTH/teclas,HEIGHT/2+190)
pushStyle()
end
-- Do your drawing here
mas:draw()-- siguiente piano (mas button)
moreKEYS:draw()
less:draw()
--SPRITE THE IMAGE
sprite("Cargo Bot:Step Button",WIDTH/2+400,HEIGHT/2-200,80)
pushStyle()
stroke(255)
strokeWidth(6)
fill(255)
line(973,184,995,184)
line(985,172,985,196)
popStyle()
pushStyle()
fill(255)
stroke(255)
strokeWidth(6)
line(33,184,59,184)
popStyle()
end
-------------------------------
--> MAKE THE SOUND FUNCTION
--> THIS IS THE FIRS TABLE SONGS FOR THE CLASS 1()
--> PIANO 1 CLASS()
-------------------------------
function piano1:tocarSonido()
keyPressed = scale[x] --> we use the method scale
sound(SOUND_BLIT,notas[keyPressed]) --> make the sound(working in that)
end
------------------------------------
--> WE SHOW THE NUMBERS IN THE KEYS
------------------------------------
function piano1:showText(string,x,y)
pushStyle()
fill(80)
fontSize(30)
text(string,x,y)
popStyle()
end
function piano1:touched(touch)
if touch.state == ENDED then
touches[touch.id]=nil
else
touches[touch.id]=touch
end
mas:touched(touch) --> BUTTON BACK
moreKEYS:touched(touch)
less:touched(touch)
end
-----------------------------------------
--creamos una clase aparte para el piano2
-----------------------------------------
piano2 = class()
function piano2:init()
notass = {nota1=100,nota2=200,nota3=300,nota4=500,
nota5=600,nota6=21,nota7=11,nota8=60,nota9=22,
nota10=22,nota11=52,nota12=91,nota13=112}
--scale the notes
scale = {"nota1","nota2","nota3","nota4","nota5","nota6",
"nota7","nota8","nota9","nota10",
"nota11","nota12","nota13"}
atras = Buttons(WIDTH/2-400,HEIGHT/2-200,"men",back) --Buttons class()
teclas_piano2=10
styleP2 = Texts()
tabla = {}
end
function piano2:draw()
nuevasNotas = {}
for r,touch in pairs(tabla) do
x = touch.x
x = math.ceil(x/WIDTH*teclas_piano2)
if CurrentTouch.y <= HEIGHT/2+100 and CurrentTouch.y >= HEIGHT/2-180 and x > 0 then
table.insert(nuevasNotas,x)
self:getSound()
end
end --end for
background(0, 0, 0, 255)
pushStyle() --style information of PIANO
font("Georgia-BoldItalic")
fontSize(40)
fill(202, 203, 217, 135)
text("PIANO",WIDTH/2,HEIGHT/2-280)
text("Developed by luismi",WIDTH/2,HEIGHT/2-330)
popStyle()
for s = 1 , teclas_piano2 do --show the white keys in the table
fill(255, 255, 255, 255)
stroke(0)
strokeWidth(1)
roundRect((s-1)*(WIDTH/teclas_piano2), HEIGHT-559,WIDTH/teclas_piano2,HEIGHT/2+190,20)
end
----------------------
--> Call piano2 style
----------------------
styleP2:StylePiano2()
for s,v in pairs(nuevasNotas) do
fill(0, 0, 0, 43)
stroke(0)
strokeWidth(5.8)
rect((v-1)*(WIDTH/teclas_piano2),HEIGHT - 560,WIDTH/teclas_piano2,HEIGHT/2+190)
end
-- Do your drawing her
atras:draw()
sprite("Cargo Bot:Step Button",WIDTH/2-400,HEIGHT/2-200,-80)
end
function piano2:touched(touch)
if touch.state == ENDED then
tabla[touch.id] = nil
else
tabla[touch.id] = touch
end
atras:touched(touch)
end
function piano2:getSound()
-- r = DATA, "ZgJASABAQEBAQEBAAAAAALNkoj5YV2E+XgBAf0BAQEBAQEBA"
f = scale[x]
sound(SOUND_BLIT,notass[f])
end
Texts = class()
function Texts:init()
-------------------------------------------
--> you can accept and set parameters here
-------------------------------------------
end
function Texts:draw()
end
---------------------------
--> Style for piano1
---------------------------
function Texts:StylePiano1()
self:showText("C5",WIDTH/2-460,HEIGHT/2-83)--muestra el texto C5
self:showText("E5",WIDTH/2-255,HEIGHT/2-83)--muestra el texto C6
self:showText("D5",WIDTH/2-358,HEIGHT/2-83)--muestra el texto C7
self:showText("F5",WIDTH/2-153,HEIGHT/2-83)--muestra el texto C8
self:showText("G5",WIDTH/2-52,HEIGHT/2-83)--muestra el texto C9
self:showText("A5",WIDTH/2+52,HEIGHT/2-83)
self:showText("B5",WIDTH/2+153,HEIGHT/2-83)
self:showText("G6",WIDTH/2+255,HEIGHT/2-83)
self:showText("A6",WIDTH/2+358,HEIGHT/2-83)
self:showText("B6",WIDTH/2+460,HEIGHT/2-83)
fill(140, 255, 0, 69)
stroke(255)
strokeWidth(2)
rect(WIDTH/2-292,HEIGHT/2-120,WIDTH/2-440,HEIGHT/2-310)--E5
rect(WIDTH/2-497,HEIGHT/2-120,WIDTH/2-440,HEIGHT/2-310)--C5
rect(WIDTH/2-394,HEIGHT/2-120,WIDTH/2-440,HEIGHT/2-310)--D5
rect(WIDTH/2-189,HEIGHT/2-120,WIDTH/2-440,HEIGHT/2-310)--F5
rect(WIDTH/2-87,HEIGHT/2-120,WIDTH/2-440,HEIGHT/2-310)--G5
rect(WIDTH/2+15,HEIGHT/2-120,WIDTH/2-440,HEIGHT/2-310)--A5
rect(WIDTH/2+118,HEIGHT/2-120,WIDTH/2-440,HEIGHT/2-310)--B5
pushStyle()
fill(6, 17, 244, 33)
stroke(255)
strokeWidth(2)
rect(WIDTH/2+220,HEIGHT/2-120,WIDTH/2-440,HEIGHT/2-310)--G6
rect(WIDTH/2+322,HEIGHT/2-120,WIDTH/2-440,HEIGHT/2-310)--A6
rect(WIDTH/2+425,HEIGHT/2-120,WIDTH/2-440,HEIGHT/2-310)--B6
popStyle()
end
----------------------
--> Style for piano2
----------------------
function Texts:StylePiano2()
pushStyle()
fill(0, 0, 0, 242)
stroke(20)
fontSize(30)
self:showText("C8",WIDTH/2-460,HEIGHT/2-83)
self:showText("E8",WIDTH/2-255,HEIGHT/2-83)
self:showText("D8",WIDTH/2-358,HEIGHT/2-83)
self:showText("F8",WIDTH/2-153,HEIGHT/2-83)
self:showText("G8",WIDTH/2-52,HEIGHT/2-83)
self:showText("A9",WIDTH/2+52,HEIGHT/2-83)
self:showText("B9",WIDTH/2+153,HEIGHT/2-83)
self:showText("G9",WIDTH/2+255,HEIGHT/2-83)
self:showText("A9",WIDTH/2+358,HEIGHT/2-83)
self:showText("B9",WIDTH/2+460,HEIGHT/2-83)
popStyle()
pushStyle()
fill(255, 91, 0, 61)
stroke(255)
strokeWidth(2)
rect(WIDTH/2-292,HEIGHT/2-120,WIDTH/2-440,HEIGHT/2-310)--E5
rect(WIDTH/2-497,HEIGHT/2-120,WIDTH/2-440,HEIGHT/2-310)--C5
rect(WIDTH/2-394,HEIGHT/2-120,WIDTH/2-440,HEIGHT/2-310)--D5
rect(WIDTH/2-189,HEIGHT/2-120,WIDTH/2-440,HEIGHT/2-310)--F5
rect(WIDTH/2-87,HEIGHT/2-120,WIDTH/2-440,HEIGHT/2-310)--G5
rect(WIDTH/2+15,HEIGHT/2-120,WIDTH/2-440,HEIGHT/2-310)--A5
rect(WIDTH/2+118,HEIGHT/2-120,WIDTH/2-440,HEIGHT/2-310)--B5
popStyle()
pushStyle()
fill(244, 5, 236, 50)
stroke(255)
strokeWidth(2)
rect(WIDTH/2+220,HEIGHT/2-120,WIDTH/2-440,HEIGHT/2-310)--G6
rect(WIDTH/2+322,HEIGHT/2-120,WIDTH/2-440,HEIGHT/2-310)--A6
rect(WIDTH/2+425,HEIGHT/2-120,WIDTH/2-440,HEIGHT/2-310)--B6
popStyle()
end
function Texts:StyleMoreKeys1()
self:showText("C5",WIDTH/2-463,HEIGHT/2-83)--muestra el texto C5
self:showText("E5",WIDTH/2-278,HEIGHT/2-83)--muestra el texto C6
self:showText("D5",WIDTH/2-371,HEIGHT/2-83)--muestra el texto C7
self:showText("F5",WIDTH/2-184,HEIGHT/2-83)--muestra el texto C8
self:showText("G5",WIDTH/2-92,HEIGHT/2-83)--muestra el texto C9
self:showText("A5",WIDTH/2,HEIGHT/2-83)
self:showText("B5",WIDTH/2+92,HEIGHT/2-83)
self:showText("G6",WIDTH/2+186,HEIGHT/2-83)
self:showText("A6",WIDTH/2+279,HEIGHT/2-83)
self:showText("B6",WIDTH/2+373,HEIGHT/2-83)
self:showText("D6",WIDTH/2+465,HEIGHT/2-83)
fill(140, 255, 0, 69)
stroke(255)
strokeWidth(2)
rect(WIDTH/2-314,HEIGHT/2-120,WIDTH/2-440,HEIGHT/2-310)--E5
rect(WIDTH/2-501,HEIGHT/2-120,WIDTH/2-440,HEIGHT/2-310)--C5
rect(WIDTH/2-407,HEIGHT/2-120,WIDTH/2-440,HEIGHT/2-310)--D5
rect(WIDTH/2-222,HEIGHT/2-120,WIDTH/2-440,HEIGHT/2-310)--F5
rect(WIDTH/2-128,HEIGHT/2-120,WIDTH/2-440,HEIGHT/2-310)--G5
rect(WIDTH/2-36,HEIGHT/2-120,WIDTH/2-440,HEIGHT/2-310)--A5
rect(WIDTH/2+58,HEIGHT/2-120,WIDTH/2-440,HEIGHT/2-310)--B5
pushStyle()
fill(6, 17, 244, 33)
stroke(255)
strokeWidth(2)
rect(WIDTH/2+150,HEIGHT/2-120,WIDTH/2-440,HEIGHT/2-310)--G6
rect(WIDTH/2+243,HEIGHT/2-120,WIDTH/2-440,HEIGHT/2-310)--A6
rect(WIDTH/2+337,HEIGHT/2-120,WIDTH/2-440,HEIGHT/2-310)--B6
rect(WIDTH/2+428,HEIGHT/2-120,WIDTH/2-440,HEIGHT/2-310)--B6
popStyle()
end
function Texts:k12()
self:showText12("C5",WIDTH/2-468,HEIGHT/2-83)--muestra el texto C5
self:showText12("E5",WIDTH/2-297,HEIGHT/2-83)--muestra el texto C6
self:showText12("D5",WIDTH/2-381,HEIGHT/2-83)--muestra el texto C7
self:showText12("F5",WIDTH/2-213,HEIGHT/2-83)--muestra el texto C8
self:showText12("G5",WIDTH/2-128,HEIGHT/2-83)--muestra el texto C9
self:showText12("A5",WIDTH/2-42,HEIGHT/2-83)
self:showText12("B5",WIDTH/2+42,HEIGHT/2-83)
self:showText12("G6",WIDTH/2+128,HEIGHT/2-83)
self:showText12("A6",WIDTH/2+213,HEIGHT/2-83)
self:showText12("B6",WIDTH/2+298,HEIGHT/2-83)
self:showText12("D6",WIDTH/2+384,HEIGHT/2-83)
self:showText12("H6",WIDTH/2+469,HEIGHT/2-83)
fill(140, 255, 0, 69)
stroke(255)
strokeWidth(2)
rect(WIDTH/2-331,HEIGHT/2-120,WIDTH/2-446,HEIGHT/2-314)--E5
rect(WIDTH/2-502,HEIGHT/2-120,WIDTH/2-446,HEIGHT/2-314)--C5
rect(WIDTH/2-416,HEIGHT/2-120,WIDTH/2-446,HEIGHT/2-314)--D5
rect(WIDTH/2-246,HEIGHT/2-120,WIDTH/2-446,HEIGHT/2-314)--F5
rect(WIDTH/2-161,HEIGHT/2-120,WIDTH/2-446,HEIGHT/2-314)--G5
rect(WIDTH/2-75,HEIGHT/2-120,WIDTH/2-446,HEIGHT/2-314)--A5
rect(WIDTH/2+10,HEIGHT/2-120,WIDTH/2-446,HEIGHT/2-314)--B5
pushStyle()
fill(6, 17, 244, 33)
stroke(255)
strokeWidth(2)
rect(WIDTH/2+95,HEIGHT/2-120,WIDTH/2-446,HEIGHT/2-314)--G6
rect(WIDTH/2+180,HEIGHT/2-120,WIDTH/2-446,HEIGHT/2-314)--A6
rect(WIDTH/2+266,HEIGHT/2-120,WIDTH/2-446,HEIGHT/2-314)--B6
rect(WIDTH/2+351,HEIGHT/2-120,WIDTH/2-446,HEIGHT/2-314)--B6
rect(WIDTH/2+436,HEIGHT/2-120,WIDTH/2-446,HEIGHT/2-314)--B6
popStyle()
end
-------------------
--> STYLE FOR LESS
-------------------
function Texts:less()
self:showText("C5",WIDTH/2-460,HEIGHT/2-83)--muestra el texto C5
self:showText("E5",WIDTH/2-229,HEIGHT/2-83)--muestra el texto C6
self:showText("D5",WIDTH/2-339,HEIGHT/2-83)--muestra el texto C7
self:showText("F5",WIDTH/2-114,HEIGHT/2-83)--muestra el texto C8
self:showText("G5",WIDTH/2-2,HEIGHT/2-83)--muestra el texto C9
self:showText("A5",WIDTH/2+114,HEIGHT/2-83)
self:showText("B5",WIDTH/2+228,HEIGHT/2-83)
self:showText("G6",WIDTH/2+342,HEIGHT/2-83)
self:showText("A6",WIDTH/2+453,HEIGHT/2-83)
fill(140, 255, 0, 69)
stroke(255)
strokeWidth(2)
rect(WIDTH/2-270,HEIGHT/2-120,WIDTH/2-430,HEIGHT/2-310)--E5
rect(WIDTH/2-497,HEIGHT/2-120,WIDTH/2-430,HEIGHT/2-310)--C5
rect(WIDTH/2-382,HEIGHT/2-120,WIDTH/2-430,HEIGHT/2-310)--D5
rect(WIDTH/2-155,HEIGHT/2-120,WIDTH/2-430,HEIGHT/2-310)--F5
rect(WIDTH/2-42,HEIGHT/2-120,WIDTH/2-430,HEIGHT/2-310)--G5
rect(WIDTH/2+73,HEIGHT/2-120,WIDTH/2-430,HEIGHT/2-310)--A5
rect(WIDTH/2+188,HEIGHT/2-120,WIDTH/2-430,HEIGHT/2-310)--B5
pushStyle()
fill(6, 17, 244, 33)
stroke(255)
strokeWidth(2)
rect(WIDTH/2+300,HEIGHT/2-120,WIDTH/2-430,HEIGHT/2-310)--G6
rect(WIDTH/2+414,HEIGHT/2-120,WIDTH/2-430,HEIGHT/2-310)--A6
popStyle()
end
function Texts:showText(string,x,y)
pushStyle()
fill(80)
fontSize(30)
text(string,x,y)
popStyle()
end
function Texts:showText12(string,x,y)
pushStyle()
fill(80)
fontSize(26)
text(string,x,y)
popStyle()
end
function Texts:touched(touch)
-- Codea does not automatically call this method
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment