Advertisement
Guest User

A-PIANO V.2.0

a guest
Jun 23rd, 2012
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 18.14 KB | None | 0 0
  1. #All rights reserved for A-MAN a.k.a Mr.A
  2. #Coded in python
  3. #uses pygame library
  4.  
  5. import pygame, sys, os, time
  6. from pygame.locals import *
  7. from winsound import Beep
  8.  
  9.  
  10.  
  11.  
  12.  
  13. def Close():
  14.     pygame.quit()
  15.     sys.exit()
  16. def collide_w_mouse(x, y, rect):
  17.     if (x > rect.left) and (x < rect.right) and (y > rect.top) and (y < rect.bottom):
  18.         return True
  19.     else:
  20.         return False
  21.  
  22. def collide_w_mouse2(x, y, polygon1):
  23.     if (x > polygon1[0][0]) and (x < polygon1[1][0]) and (y > polygon1[1][1]) and (y < polygon1[2][1]):
  24.         return True
  25.     else:
  26.         return False
  27. def collide_w_mouse3(x, y, polygon1):
  28.     if (x < polygon1[0][0]) and (x > polygon1[1][0]) and (y > polygon1[1][1]) and (y < polygon1[2][1]):
  29.         return True
  30.     else:
  31.         return False
  32.  
  33. def main():
  34.     global freq, beep1, beep2, beep3, beep4, beep5, beep6, beep7, beep8, beep9, Clock, FPS
  35.     APPNAME= 'A-PIANO'
  36.     freq= 0
  37.     COLORS      = {'black' : (0  , 0  , 0  ), 'red'   : (150, 0  , 0  ),
  38.                    'blue'  : (0  , 0  , 150), 'green' : (0  , 150, 0  ),
  39.                    'orange': (150, 50 , 0  ), 'purple': (50 , 0  , 150),
  40.                    'yellow': (150, 150, 0  ), 'aqua'  : (0  , 150, 150),
  41.                    'teal'  : (0  , 50 , 50 ), 'grey'  : (100, 100, 100),
  42.                    'white' : (255, 255, 255), 'brown' : (128, 64 , 0  ),
  43.                    'pink'  : (155, 0  , 155), 'sred'  : (255, 0  , 0  ),
  44.                    'sgreen': (0  , 255, 0  ), 'sblue' : (0  , 0  , 255)}
  45.     LIGHTCOLORS = {'light red'   : (250, 100, 100), 'light blue'  : (100, 100, 250),
  46.                    'light green' : (100, 250, 100), 'light orange': (250, 150, 100),
  47.                    'light purple': (150, 50 , 250), 'light yellow': (250, 250, 100),
  48.                    'light aqua'  : (100, 250, 250), 'light teal'  : (100, 150, 150),
  49.                    'light grey'  : (200, 200, 200), 'light white' : (50 , 50 , 50 ),
  50.                    'light brown' : (228, 164, 100), 'light pink'  : (255, 0  , 255)}
  51.     pygame.init()
  52.     pygame.display.set_caption(APPNAME)
  53.     DISPLAYSURF = pygame.display.set_mode((780, 600), 0, 32)      
  54.  
  55.     instructions1 = 'You can either use the mouse to click on the buttons'
  56.     instructions2 = 'or use the keyboard keys: A S D F G H J K L ; \' \\ '
  57.     instructions3 = 'and the left and right buttons to change the frequency average.'
  58.     thecopyright  = 'All rights reserved for the A-MAN                                          (c)2011-2012'
  59.     WELCOMINGFONT = pygame.font.SysFont(None, 100)
  60.     NORMALFONT    = pygame.font.SysFont(None, 30 )
  61.     COPYRIGHTFONT = pygame.font.SysFont(None, 20 )
  62.     FREQFONT      = pygame.font.SysFont(None, 40 )
  63.     BGCOLOR       = COLORS['black']
  64.     MenuText      = WELCOMINGFONT.render('A-PIANO', True, COLORS['white'], BGCOLOR)
  65.     MenuTextrect  = MenuText.get_rect()
  66.     InstText1     = NORMALFONT.render(instructions1, True, COLORS['blue'], BGCOLOR)
  67.     InstTextrect1 = InstText1.get_rect()
  68.     InstText2     = NORMALFONT.render(instructions2, True, COLORS['blue'], BGCOLOR)
  69.     InstTextrect2 = InstText2.get_rect()
  70.     InstText3     = NORMALFONT.render(instructions3, True, COLORS['blue'], BGCOLOR)
  71.     InstTextrect3 = InstText3.get_rect()
  72.     CopyRText     = NORMALFONT.render(thecopyright, True, COLORS['yellow'], BGCOLOR)
  73.     CopyRTextrect = CopyRText.get_rect()
  74.     FREQLABEL     = WELCOMINGFONT.render(str(freq), True, COLORS['sgreen'], BGCOLOR)
  75.     FREQLABELrect = FREQLABEL.get_rect()
  76.  
  77.     MenuTextrect.centerx = DISPLAYSURF.get_rect().centerx
  78.     MenuTextrect.top     = DISPLAYSURF.get_rect().top + 100
  79.     InstTextrect1.center = DISPLAYSURF.get_rect().center
  80.     InstTextrect2.center = DISPLAYSURF.get_rect().center
  81.     InstTextrect2.centery= DISPLAYSURF.get_rect().centery+50
  82.     InstTextrect3.center = DISPLAYSURF.get_rect().center
  83.     InstTextrect3.centery= DISPLAYSURF.get_rect().centery+100
  84.     CopyRTextrect.centerx= DISPLAYSURF.get_rect().centerx
  85.     CopyRTextrect.bottom = DISPLAYSURF.get_rect().bottom - 20
  86.     FREQLABELrect.centerx= DISPLAYSURF.get_rect().centerx - 40
  87.     FREQLABELrect.centery= 470
  88.  
  89.     buttonsize = {'1' : pygame.Rect(35 , 200, 50, 200),      '2' : pygame.Rect(95 , 200, 50, 200), '3' : pygame.Rect(155, 200, 50, 200),
  90.                   '4' : pygame.Rect(215, 200, 50, 200),      '5' : pygame.Rect(275, 200, 50, 200), '6' : pygame.Rect(335, 200, 50, 200),
  91.                   '7' : pygame.Rect(395, 200, 50, 200),      '8' : pygame.Rect(455, 200, 50, 200), '9' : pygame.Rect(515, 200, 50, 200),
  92.                   '10': pygame.Rect(575, 200, 50, 200),      '11': pygame.Rect(635, 200, 50, 200), '12': pygame.Rect(695, 200, 50, 200),
  93.                   '13': ((200, 470),(250, 420), (250, 520)), '14': ((580, 470),(530, 420), (530, 520))}
  94.  
  95.     buttons = {'1'      : 'pygame.draw.rect(DISPLAYSURF, COLORS[\'red\'],     buttonsize[\'2\'], 10)',
  96.                '2'      : 'pygame.draw.rect(DISPLAYSURF, COLORS[\'blue\'],   buttonsize[\'3\'], 10)',
  97.                '3'      : 'pygame.draw.rect(DISPLAYSURF, COLORS[\'green\'],  buttonsize[\'4\'], 10)',
  98.                '4'      : 'pygame.draw.rect(DISPLAYSURF, COLORS[\'orange\'], buttonsize[\'5\'], 10)',
  99.                '5'      : 'pygame.draw.rect(DISPLAYSURF, COLORS[\'purple\'], buttonsize[\'6\'], 10)',
  100.                '6'      : 'pygame.draw.rect(DISPLAYSURF, COLORS[\'yellow\'], buttonsize[\'7\'], 10)',
  101.                '7'      : 'pygame.draw.rect(DISPLAYSURF, COLORS[\'aqua\'],   buttonsize[\'8\'], 10)',
  102.                '8'      : 'pygame.draw.rect(DISPLAYSURF, COLORS[\'teal\'],   buttonsize[\'9\'], 10)',
  103.                '9'      : 'pygame.draw.rect(DISPLAYSURF, COLORS[\'white\'],  buttonsize[\'1\'], 10)',
  104.                '10'     : 'pygame.draw.rect(DISPLAYSURF, COLORS[\'brown\'],  buttonsize[\'10\'], 10)',
  105.                '11'     : 'pygame.draw.rect(DISPLAYSURF, COLORS[\'pink\'],   buttonsize[\'11\'], 10)',
  106.                '12'     : 'pygame.draw.rect(DISPLAYSURF, COLORS[\'grey\'],   buttonsize[\'12\'], 10)',
  107.                'bleft'  : 'pygame.draw.polygon(DISPLAYSURF, COLORS[\'sred\'],   buttonsize[\'13\'], 10)',
  108.                'bright' : 'pygame.draw.polygon(DISPLAYSURF, COLORS[\'sblue\'],   buttonsize[\'14\'], 10)'}
  109.     beep1, beep2, beep3, beep4, beep5, beep6, beep7, beep8, beep9, beep10, beep11, beep12     = False, False, False, False, False, False, False, False, False, False, False, False
  110.     light1,light2,light3,light4,light5,light6,light7,light8,light9, light10, light11, light12 = False, False, False, False, False, False, False, False, False, False, False, False
  111.     light13, light14 = False, False
  112.     FPS = 100
  113.     Clock = pygame.time.Clock()
  114.     window = 1
  115.     DISPLAYSURF.fill(BGCOLOR)
  116.     while True:
  117.         DISPLAYSURF.fill(BGCOLOR)
  118.         if window == 1:
  119.             DISPLAYSURF.blit(MenuText,  MenuTextrect)
  120.             DISPLAYSURF.blit(InstText1, InstTextrect1)
  121.             DISPLAYSURF.blit(InstText2, InstTextrect2)
  122.             DISPLAYSURF.blit(InstText3, InstTextrect3)
  123.             DISPLAYSURF.blit(CopyRText, CopyRTextrect)
  124.             for event in pygame.event.get():
  125.                 if event.type == QUIT:
  126.                     Close()
  127.                 if event.type == KEYDOWN:
  128.                     if event.key == K_RETURN:
  129.                         window += 1
  130.                         DISPLAYSURF.fill(BGCOLOR)
  131.                     if event.key == K_ESCAPE:
  132.                         Close()
  133.         if window == 2:
  134.  
  135.                
  136.             FREQLABEL= WELCOMINGFONT.render(str(freq+600), True, COLORS['sgreen'], BGCOLOR)
  137.             DISPLAYSURF.blit(MenuText, MenuTextrect)
  138.             DISPLAYSURF.blit(MenuText, MenuTextrect)
  139.             DISPLAYSURF.blit(CopyRText, CopyRTextrect)
  140.             DISPLAYSURF.blit(FREQLABEL, FREQLABELrect)
  141.             for a in buttons:
  142.                 exec(buttons[a])
  143.             COLORS      = {'black' : (0  , 0  , 0  ), 'red'   : (150, 0  , 0  ),
  144.                            'blue'  : (0  , 0  , 150), 'green' : (0  , 150, 0  ),
  145.                            'orange': (150, 50 , 0  ), 'purple': (50 , 0  , 150),
  146.                            'yellow': (150, 150, 0  ), 'aqua'  : (0  , 150, 150),
  147.                            'teal'  : (0  , 50 , 50 ), 'grey'  : (100, 100, 100),
  148.                            'white' : (255, 255, 255), 'brown' : (128, 64 , 0  ),
  149.                            'pink'  : (155, 0  , 155), 'sred'  : (255, 0  , 0  ),
  150.                            'sgreen': (0  , 255, 0  ), 'sblue' : (0  , 0  , 255)}
  151.             for event in pygame.event.get():
  152.                 if event.type == QUIT:
  153.                     Close()
  154.                 if event.type == MOUSEBUTTONDOWN:
  155.                     if event.button == 1:
  156.                         if  collide_w_mouse(event.pos[0], event.pos[1], buttonsize['1']):
  157.                             light1 = True
  158.                          
  159.                         if  collide_w_mouse(event.pos[0], event.pos[1], buttonsize['2']):
  160.                             light2 = True
  161.                          
  162.                         if  collide_w_mouse(event.pos[0], event.pos[1], buttonsize['3']):
  163.                             light3 = True
  164.                          
  165.                         if  collide_w_mouse(event.pos[0], event.pos[1], buttonsize['4']):
  166.                             light4 = True
  167.                          
  168.                         if  collide_w_mouse(event.pos[0], event.pos[1], buttonsize['5']):
  169.                             light5 = True
  170.                          
  171.                         if  collide_w_mouse(event.pos[0], event.pos[1], buttonsize['6']):
  172.                             light6 = True
  173.  
  174.                         if  collide_w_mouse(event.pos[0], event.pos[1], buttonsize['7']):
  175.                             light7 = True
  176.  
  177.                         if  collide_w_mouse(event.pos[0], event.pos[1], buttonsize['8']):
  178.                             light8 = True
  179.                                
  180.                         if  collide_w_mouse(event.pos[0], event.pos[1], buttonsize['9']):
  181.                             light9 = True
  182.  
  183.                         if  collide_w_mouse(event.pos[0], event.pos[1], buttonsize['10']):
  184.                             light10 = True
  185.  
  186.                         if  collide_w_mouse(event.pos[0], event.pos[1], buttonsize['11']):
  187.                             light11 = True
  188.  
  189.                         if  collide_w_mouse(event.pos[0], event.pos[1], buttonsize['12']):
  190.                             light12 = True
  191.  
  192.                         if  collide_w_mouse2(event.pos[0], event.pos[1], buttonsize['13']):
  193.                             light13 = True
  194.  
  195.                         if  collide_w_mouse3(event.pos[0], event.pos[1], buttonsize['14']):
  196.                             light14 = True
  197.                            
  198.  
  199.  
  200.                            
  201.                 if event.type == MOUSEBUTTONUP:
  202.                     if event.button == 1:
  203.                         beep1, beep2, beep3, beep4, beep5, beep6, beep7, beep8, beep9, beep10, beep11, beep12     = False, False, False, False, False, False, False, False, False, False, False, False
  204.                         light1,light2,light3,light4,light5,light6,light7,light8,light9, light10, light11, light12 = False, False, False, False, False, False, False, False, False, False, False, False
  205.                         light13, light14 = False, False
  206.  
  207.  
  208.                 if event.type == KEYDOWN:
  209.                     if event.key == K_ESCAPE:
  210.                         Close()
  211.                     if event.key == K_RIGHT:
  212.                         light14 = True
  213.                     if event.key == K_LEFT:
  214.                         light13 = True
  215.                     if event.key == ord('a') or event.key == ord('A'):
  216.                         light1 = True
  217.                     if event.key == ord('s') or event.key == ord('S'):
  218.                         light2 = True
  219.                     if event.key == ord('d') or event.key == ord('D'):
  220.                         light3 = True
  221.                     if event.key == ord('f') or event.key == ord('F'):
  222.                         light4 = True
  223.                     if event.key == ord('g') or event.key == ord('G'):
  224.                         light5 = True
  225.                     if event.key == ord('h') or event.key == ord('H'):
  226.                         light6 = True
  227.                     if event.key == ord('j') or event.key == ord('J'):
  228.                         light7 = True
  229.                     if event.key == ord('k') or event.key == ord('K'):
  230.                         light8 = True
  231.                     if event.key == ord('l') or event.key == ord('L'):
  232.                         light9 = True
  233.                     if event.key == ord(';'):
  234.                         light10= True
  235.                     if event.key == ord('\''):
  236.                         light11= True
  237.                     if event.key == ord('\\'):
  238.                         light12= True
  239.                 if event.type == KEYUP:
  240.                     if event.key == ord('a') or event.key == ord('A'):
  241.                         beep1  = False
  242.                         light1 = False
  243.                     if event.key == ord('s') or event.key == ord('S'):
  244.                         beep2  = False
  245.                         light2 = False
  246.                     if event.key == ord('d') or event.key == ord('D'):
  247.                         beep3  = False
  248.                         light3 = False
  249.                     if event.key == ord('f') or event.key == ord('F'):
  250.                         beep4  = False
  251.                         light4 = False
  252.                     if event.key == ord('g') or event.key == ord('G'):
  253.                         beep5  = False
  254.                         light5 = False
  255.                     if event.key == ord('h') or event.key == ord('H'):
  256.                         beep6  = False
  257.                         light6 = False
  258.                     if event.key == ord('j') or event.key == ord('J'):
  259.                         beep7  = False
  260.                         light7 = False
  261.                     if event.key == ord('k') or event.key == ord('K'):
  262.                         beep8  = False
  263.                         light8 = False
  264.                     if event.key == ord('l') or event.key == ord('L'):
  265.                         beep9  = False
  266.                         light9 = False
  267.                     if event.key == ord(';'):
  268.                         beep10 = False
  269.                         light10= False
  270.                     if event.key == ord('\''):
  271.                         beep11 = False
  272.                         light11= False
  273.                     if event.key == ord('\\'):
  274.                         beep12 = False
  275.                         light12= False
  276.                     if event.key == K_RIGHT:
  277.                         light14 = False
  278.                     if event.key == K_LEFT:
  279.                         light13 = False                        
  280.  
  281.             if beep1 == True:
  282.                 COLORS['white']  = LIGHTCOLORS['light white']
  283.                 Beep(1200+ freq, 100)
  284.             if beep2 == True:
  285.                 COLORS['red']    = LIGHTCOLORS['light red']
  286.                 Beep(1350+ freq, 100)
  287.             if beep3 == True:
  288.                 COLORS['blue']   = LIGHTCOLORS['light blue']
  289.                 Beep(1500+ freq, 100)
  290.             if beep4 == True:
  291.                 COLORS['green']  = LIGHTCOLORS['light green']
  292.                 Beep(1650+ freq, 100)
  293.             if beep5 == True:
  294.                 COLORS['orange'] = LIGHTCOLORS['light orange']
  295.                 Beep(1800+ freq, 100)
  296.             if beep6 == True:
  297.                 COLORS['purple'] = LIGHTCOLORS['light purple']
  298.                 Beep(1950+ freq, 100)
  299.             if beep7 == True:
  300.                 COLORS['yellow'] = LIGHTCOLORS['light yellow']
  301.                 Beep(2100+ freq, 100)
  302.             if beep8 == True:
  303.                 COLORS['aqua']   = LIGHTCOLORS['light aqua']
  304.                 Beep(2250+ freq, 100)
  305.             if beep9 == True:
  306.                 COLORS['teal']   = LIGHTCOLORS['light teal']
  307.                 Beep(2400+ freq, 100)
  308.             if beep10 == True:
  309.                 COLORS['brown']   = LIGHTCOLORS['light brown']
  310.                 Beep(2550+ freq, 100)
  311.             if beep11 == True:
  312.                 COLORS['pink']    = LIGHTCOLORS['light pink']
  313.                 Beep(2600+ freq, 100)
  314.             if beep12 == True:
  315.                 COLORS['grey']    = LIGHTCOLORS['light grey']
  316.                 Beep(2750+ freq, 100)
  317.  
  318.             if light1 == True:
  319.                 COLORS['white']  = LIGHTCOLORS['light white']
  320.                 beep1= True
  321.             if light2 == True:
  322.                 COLORS['red']    = LIGHTCOLORS['light red']
  323.                 beep2= True
  324.             if light3 == True:
  325.                 COLORS['blue']   = LIGHTCOLORS['light blue']
  326.                 beep3= True
  327.             if light4 == True:
  328.                 COLORS['green']  = LIGHTCOLORS['light green']
  329.                 beep4= True
  330.             if light5 == True:
  331.                 COLORS['orange'] = LIGHTCOLORS['light orange']
  332.                 beep5= True
  333.             if light6 == True:
  334.                 COLORS['purple'] = LIGHTCOLORS['light purple']
  335.                 beep6= True
  336.             if light7 == True:
  337.                 COLORS['yellow'] = LIGHTCOLORS['light yellow']
  338.                 beep7= True
  339.             if light8 == True:
  340.                 COLORS['aqua']   = LIGHTCOLORS['light aqua']
  341.                 beep8= True
  342.             if light9 == True:
  343.                 COLORS['teal']   = LIGHTCOLORS['light teal']
  344.                 beep9= True
  345.             if light10 == True:
  346.                 COLORS['brown']   = LIGHTCOLORS['light brown']
  347.                 beep10= True
  348.             if light11 == True:
  349.                 COLORS['pink']   = LIGHTCOLORS['light pink']
  350.                 beep11= True
  351.             if light12 == True:
  352.                 COLORS['grey']   = LIGHTCOLORS['light grey']
  353.                 beep12= True
  354.             if light13 == True:
  355.                 COLORS['sred']   = COLORS['white']
  356.                 if freq > -599:
  357.                     freq -= 1                
  358.             if light14 == True:
  359.                 COLORS['sblue']  = COLORS['white']
  360.                 if freq < 3001:
  361.                     freq += 1
  362.  
  363.         pygame.display.update()
  364.         Clock.tick(FPS)
  365. if __name__ == '__main__':
  366.     main()
  367. else:
  368.     pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement