Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ############################
- # Copyright (c) 2007 #
- # Igor aka kAIST #
- # e-mail: igor.kaist@gmail.com #
- # ICQ: 211141235 #
- # URL: python.mirahost.ru #
- ############################
- def ru(x):return x.decode('utf-8')
- import os
- from appuifw import *
- def error(x=''):
- note(ru('Error: '+x),'error')
- os.abort()
- try:
- import camera,time,thread,e32
- from graphics import *
- from audio import Sound
- except:error('It is impossible to load modules')
- canvas=Canvas(event_callback=None, redraw_callback=None)
- app.body=canvas
- pt=0
- app.title=ru('Seven notes')
- _state=0
- _null=[]
- _prev=None
- _path=u'e:\\System\\Apps\\7not\\Sounds\\'
- _sounds=[]
- _notes=[ru('si'),ru('la'),ru('sol'),ru('fa'),ru('mi'),ru('re'),ru('do'),ru('None')]
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~
- def screen():
- s=Image.new((176,144))
- s.clear((0x7777ff))
- s.rectangle((0,8,176,28),0x7777aa,fill=0x7777bb)
- s.text((29,24),ru('S e v e n n o t e s'),0xffffff,font=u'LatinBold19')
- s.text((31,26),ru('S e v e n n o t e s'),0xffffff,font=u'LatinBold19')
- s.text((29,26),ru('S e v e n n o t e s'),0xffffff,font=u'LatinBold19')
- s.text((31,24),ru('S e v e n n o t e s'),0xffffff,font=u'LatinBold19')
- s.text((30,25),ru('S e v e n n o t e s'),font=u'LatinBold19')
- s.polygon([(80,50),(120,45),(110,60),(85,60),(80,100),(75,100)],0xaaaaaa,fill=0xcccccc)
- s.ellipse((50,90,80,120),0xaaaaaa,fill=0xcccccc)
- s.text((15,60),ru('author: РРіРѕСЂСЊ Р°ka kAIST'),font=u'LatinBold12')
- s.text((5,75),ru('e-mail: igor.kaist@gmail.com'),font=u'LatinBold12')
- s.text((50,90),ru('ICQ:211141235'),font=u'LatinBold12')
- s.text((13,105),ru('Site: python.mirahost.ru'),font=u'LatinBold12')
- s.text((30,140),ru('Wait, there is a loading...'),0xffffff)
- canvas.blit(s)
- e32.ao_sleep(5)
- screen()
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~
- try:
- g=open('e:/System/Apps/7not/sens.dat','rb')
- x=g.read()
- _sens=int(x)
- except:_sens=300
- try:
- for w in range(0,7):
- p=Sound.open(_path+str(w)+u'.amr')
- _sounds.append(p)
- except:error('Shortage of memory, or problem with sounds')
- def state():
- global _state
- e32.ao_sleep(5)
- _state=1
- return 1
- def sum(photo,x,y):
- de=0
- for b in [(0,0),(2,0),(1,4),(0,6),(2,6)]:
- a=photo.getpixel((x+b[0],y+b[1]))
- de=de+a[0][0]+a[0][1]+a[0][2]
- return de
- def detector(photo):
- a=[20,40,60,80,100,120,140]
- b=[]
- for x in range(0,7):
- photo.rectangle((a[x]-1,124,a[x]+3,132),0xff0000)
- b.append(sum(photo,a[x],125))
- return b
- def otrabotka(mass):
- global _null,_sens
- for x in range(0,7):
- if _null[x]-mass[x]>_sens:return x
- def go(number):
- global _prev,_sounds
- if number<>None and number<>_prev:
- try:
- _sounds[6-number].play()
- e32.ao_sleep(0.05)
- except:pass
- if number==None:
- try:_sounds[6-_prev].stop()
- except:pass
- _prev=number
- mt=Image.new((176,20))
- mt.clear((0xcccccc))
- def main(photo):
- global canvas,pt,_state,_null,_notes
- d=time.clock()*100
- z=int(100/(d-pt))
- pt=d
- if _state:
- photo.text((2,23),'It is ready to play'.decode('utf-8'),0xffffff)
- rez=otrabotka(detector(photo))
- go(rez)
- if rez==None:rez1=7
- else:rez1=rez
- photo.text((2,40),ru('note: ')+_notes[rez1],0xffffff)
- else:
- photo.text((2,23),'Preparation for play'.decode('utf-8'),0xffffff)
- _null= detector(photo)
- photo.text((2,13),u'fps '+str(z).decode('utf-8'),0xffffff)
- canvas.blit(mt,target=(0,132))
- canvas.blit(photo,target=(0,0))
- def reload():
- global _state
- try:camera.stop_finder()
- except:pass
- _state=0
- thread.start_new_thread(state,())
- camera.start_finder(main)
- def senset():
- global _sens
- x=query(ru('Sensitivity:'),'number',_sens)
- _sens=x
- m=open('e:/System/Apps/7not/sens.dat','w')
- m.write(str(x))
- m.close()
- app.menu=[(ru('Reload'),reload),(ru('Sensitivity'),senset)]
- reload()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement