Guest User

Untitled

a guest
Jan 19th, 2020
344
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ############################
  2. # Copyright (c) 2007               #
  3. #       Igor aka kAIST              #
  4. # e-mail: igor.kaist@gmail.com    #
  5. # ICQ: 211141235                   #
  6. # URL: python.mirahost.ru         #
  7. ############################
  8.  
  9. def ru(x):return x.decode('utf-8')
  10. import os
  11. from appuifw import *
  12. def error(x=''):
  13.  note(ru('Error: '+x),'error')
  14.  os.abort()
  15. try:
  16.  import camera,time,thread,e32
  17.  from graphics import *
  18.  from audio import Sound
  19. except:error('It is impossible to load modules')
  20.  
  21. canvas=Canvas(event_callback=None, redraw_callback=None)
  22. app.body=canvas
  23. pt=0
  24.  
  25. app.title=ru('Seven notes')
  26. _state=0
  27. _null=[]
  28. _prev=None
  29. _path=u'e:\\System\\Apps\\7not\\Sounds\\'
  30. _sounds=[]
  31. _notes=[ru('si'),ru('la'),ru('sol'),ru('fa'),ru('mi'),ru('re'),ru('do'),ru('None')]
  32. #~~~~~~~~~~~~~~~~~~~~~~~~~~~
  33. def screen():
  34.  s=Image.new((176,144))
  35.  s.clear((0x7777ff))
  36.  s.rectangle((0,8,176,28),0x7777aa,fill=0x7777bb)
  37.  s.text((29,24),ru('S e v e n  n o  t e s'),0xffffff,font=u'LatinBold19')
  38.  s.text((31,26),ru('S e v e n  n o  t e s'),0xffffff,font=u'LatinBold19')
  39.  s.text((29,26),ru('S e v e n  n o  t e s'),0xffffff,font=u'LatinBold19')
  40.  s.text((31,24),ru('S e v e n  n o  t e s'),0xffffff,font=u'LatinBold19')
  41.  
  42.  s.text((30,25),ru('S e v e n  n o  t e s'),font=u'LatinBold19')
  43.  s.polygon([(80,50),(120,45),(110,60),(85,60),(80,100),(75,100)],0xaaaaaa,fill=0xcccccc)
  44.  
  45.  s.ellipse((50,90,80,120),0xaaaaaa,fill=0xcccccc)
  46.  s.text((15,60),ru('author: Игорь Р°ka kAIST'),font=u'LatinBold12')
  47.  s.text((5,75),ru('e-mail: igor.kaist@gmail.com'),font=u'LatinBold12')
  48.  s.text((50,90),ru('ICQ:211141235'),font=u'LatinBold12')
  49.  s.text((13,105),ru('Site: python.mirahost.ru'),font=u'LatinBold12')
  50.  
  51.  
  52.  s.text((30,140),ru('Wait, there is a loading...'),0xffffff)
  53.  canvas.blit(s)
  54.  e32.ao_sleep(5)
  55. screen()
  56. #~~~~~~~~~~~~~~~~~~~~~~~~~~~
  57. try:
  58.  g=open('e:/System/Apps/7not/sens.dat','rb')
  59.  x=g.read()
  60.  _sens=int(x)
  61. except:_sens=300
  62. try:
  63.  for w in range(0,7):
  64.   p=Sound.open(_path+str(w)+u'.amr')
  65.   _sounds.append(p)
  66. except:error('Shortage of memory, or problem with sounds')
  67. def state():
  68.  global _state
  69.  e32.ao_sleep(5)
  70.  _state=1
  71.  return 1
  72.  
  73. def sum(photo,x,y):
  74.  de=0
  75.  for b in [(0,0),(2,0),(1,4),(0,6),(2,6)]:
  76.   a=photo.getpixel((x+b[0],y+b[1]))
  77.   de=de+a[0][0]+a[0][1]+a[0][2]
  78.  return de
  79.  
  80. def detector(photo):
  81.  a=[20,40,60,80,100,120,140]
  82.  b=[]
  83.  for x in range(0,7):
  84.   photo.rectangle((a[x]-1,124,a[x]+3,132),0xff0000)
  85.   b.append(sum(photo,a[x],125))
  86.  return b
  87.  
  88. def otrabotka(mass):
  89.  global _null,_sens
  90.  for x in range(0,7):
  91.   if _null[x]-mass[x]>_sens:return x
  92.  
  93.  
  94. def go(number):
  95.  global _prev,_sounds
  96.  if number<>None and number<>_prev:
  97.   try:
  98.    _sounds[6-number].play()
  99.    e32.ao_sleep(0.05)
  100.   except:pass
  101.  if number==None:
  102.   try:_sounds[6-_prev].stop()
  103.   except:pass
  104.  _prev=number
  105.  
  106. mt=Image.new((176,20))
  107. mt.clear((0xcccccc))
  108.  
  109.  
  110. def main(photo):
  111.  global canvas,pt,_state,_null,_notes
  112.  d=time.clock()*100
  113.  z=int(100/(d-pt))
  114.  pt=d
  115.  if _state:
  116.   photo.text((2,23),'It is ready to play'.decode('utf-8'),0xffffff)
  117.   rez=otrabotka(detector(photo))
  118.   go(rez)
  119.   if rez==None:rez1=7
  120.   else:rez1=rez
  121.   photo.text((2,40),ru('note: ')+_notes[rez1],0xffffff)
  122.  
  123.  else:
  124.   photo.text((2,23),'Preparation for play'.decode('utf-8'),0xffffff)
  125.   _null= detector(photo)
  126.  
  127.    
  128.  photo.text((2,13),u'fps '+str(z).decode('utf-8'),0xffffff)
  129.  canvas.blit(mt,target=(0,132))
  130.  canvas.blit(photo,target=(0,0))
  131.  
  132.  
  133. def reload():
  134.  global _state
  135.  try:camera.stop_finder()
  136.  except:pass
  137.  _state=0
  138.  thread.start_new_thread(state,())
  139.  camera.start_finder(main)
  140.  
  141. def senset():
  142.  global _sens
  143.  x=query(ru('Sensitivity:'),'number',_sens)
  144.  _sens=x
  145.  m=open('e:/System/Apps/7not/sens.dat','w')
  146.  m.write(str(x))
  147.  m.close()
  148.  
  149.  
  150. app.menu=[(ru('Reload'),reload),(ru('Sensitivity'),senset)]
  151. reload()
RAW Paste Data