Advertisement
Mr-A

A-Piano V2

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