Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame, random, sys
- from pygame.locals import *
- #Mouse click color changer.
- #Initializing variables
- #RGB = R G B
- white = (255, 255, 255)
- black = (0, 0, 0)
- red = (255, 0, 0)
- green = (0, 255, 0)
- blue = (0, 0, 255)
- bgcolor = white
- #List
- otherColors = [black, red, green, blue]
- #Window Size & Clock Rate
- width = 640
- height = 480
- fps = 30
- #Initialize main
- def main():
- pygame.init()
- pygame.mixer.init()
- fpsClock = pygame.time.Clock()
- displayScreen = pygame.display.set_mode((width, height))
- pygame.display.set_caption('Mouse Click Color Changer')
- colorBoard = getRandomizedColor(otherColors)
- #Game Loop
- while True:
- #Process Input (Events)
- mouseClicked = False
- for event in pygame.event.get():
- if event.type == QUIT or (event.type == KEYUP and event.key == K_ESCAPE):
- pygame.quit()
- sys.exit()
- elif event.type == MOUSEBUTTONUP:
- mouseClicked = True
- #Update
- if mouseClicked:
- #Change Color
- displayScreen.fill(otherColors)
- #Render (Draw)
- displayScreen.fill(bgcolor)
- #redraws screen (https://www.pygame.org/docs/tut/newbieguide.html)
- pygame.display.update()
- fpsClock.tick(fps)
- def getRandomizedColor(changeColor):
- #get a list of every possible color
- backgroundColor = []
- for color in otherColors:
- backgroundColor.append(color)
- #Randomize the order of the list
- changeColor = random.shuffle(backgroundColor)
- return changeColor
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement