Advertisement
devEks

Mouse Click Color Changer

Dec 2nd, 2017
623
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.74 KB | None | 0 0
  1. import pygame, random, sys
  2. from pygame.locals import *
  3.  
  4. #Mouse click color changer.
  5.  
  6. #Initializing variables
  7. #RGB    =     R     G      B
  8. white   =   (255,   255,  255)
  9. black   =   (0,     0,      0)
  10. red     =   (255,   0,      0)
  11. green   =   (0,     255,    0)
  12. blue    =   (0,     0,    255)
  13.  
  14. bgcolor =   white
  15.  
  16. #List
  17. otherColors = [black, red, green, blue]
  18.  
  19. #Window Size & Clock Rate
  20. width   =   640
  21. height  =   480
  22. fps     =   30
  23.  
  24. #Initialize main
  25. def main():
  26.     pygame.init()
  27.     pygame.mixer.init()
  28.  
  29.     fpsClock = pygame.time.Clock()
  30.     displayScreen = pygame.display.set_mode((width, height))
  31.     pygame.display.set_caption('Mouse Click Color Changer')
  32.  
  33.     colorBoard = getRandomizedColor(otherColors)
  34.  
  35.     #Game Loop
  36.     while True:
  37.         #Process Input (Events)
  38.         mouseClicked = False
  39.  
  40.         for event in pygame.event.get():
  41.             if event.type == QUIT or (event.type == KEYUP and event.key == K_ESCAPE):
  42.                 pygame.quit()
  43.                 sys.exit()
  44.  
  45.             elif event.type == MOUSEBUTTONUP:
  46.                 mouseClicked = True
  47.  
  48.         #Update
  49.         if mouseClicked:
  50.             #Change Color
  51.             displayScreen.fill(otherColors)
  52.  
  53.         #Render (Draw)
  54.         displayScreen.fill(bgcolor)
  55.  
  56.         #redraws screen (https://www.pygame.org/docs/tut/newbieguide.html)
  57.         pygame.display.update()
  58.         fpsClock.tick(fps)
  59.  
  60.  
  61. def getRandomizedColor(changeColor):
  62.     #get a list of every possible color
  63.     backgroundColor = []
  64.     for color in otherColors:
  65.         backgroundColor.append(color)
  66.  
  67.     #Randomize the order of the list
  68.     changeColor = random.shuffle(backgroundColor)
  69.     return changeColor
  70.  
  71.  
  72. if __name__ == '__main__':
  73.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement