|
| 1 | +import pygame |
| 2 | +from pygame.locals import * |
| 3 | +from sys import exit |
| 4 | + |
| 5 | +pygame.init() |
| 6 | + |
| 7 | +screen = pygame.display.set_mode((640, 480), 0, 32) |
| 8 | + |
| 9 | +def create_scales(height): |
| 10 | + red_scale_surface = pygame.surface.Surface((640, height)) |
| 11 | + green_scale_surface = pygame.surface.Surface((640, height)) |
| 12 | + blue_scale_surface = pygame.surface.Surface((640, height)) |
| 13 | + for x in range(640): |
| 14 | + c = int((x/640.)*255.) |
| 15 | + red = (c, 0, 0) |
| 16 | + green = (0, c, 0) |
| 17 | + blue = (0, 0, c) |
| 18 | + line_rect = Rect(x, 0, 1, height) |
| 19 | + pygame.draw.rect(red_scale_surface, red, line_rect) |
| 20 | + pygame.draw.rect(green_scale_surface, green, line_rect) |
| 21 | + pygame.draw.rect(blue_scale_surface, blue, line_rect) |
| 22 | + return red_scale_surface, green_scale_surface, blue_scale_surface |
| 23 | + |
| 24 | +red_scale, green_scale, blue_scale = create_scales(80) |
| 25 | + |
| 26 | +color = [127, 127, 127] |
| 27 | + |
| 28 | +while True: |
| 29 | + |
| 30 | + for event in pygame.event.get(): |
| 31 | + if event.type == QUIT: |
| 32 | + exit() |
| 33 | + |
| 34 | + screen.fill((0, 0, 0)) |
| 35 | + |
| 36 | + screen.blit(red_scale, (0, 00)) |
| 37 | + screen.blit(green_scale, (0, 80)) |
| 38 | + screen.blit(blue_scale, (0, 160)) |
| 39 | + |
| 40 | + x, y = pygame.mouse.get_pos() |
| 41 | + |
| 42 | + if pygame.mouse.get_pressed()[0]: |
| 43 | + for component in range(3): |
| 44 | + if y > component*80 and y < (component+1)*80: |
| 45 | + color[component] = int((x/639.)*255.) |
| 46 | + pygame.display.set_caption("PyGame Color Test - "+str(tuple(color))) |
| 47 | + |
| 48 | + for component in range(3): |
| 49 | + pos = ( int((color[component]/255.)*639), component*80+40 ) |
| 50 | + pygame.draw.circle(screen, (255, 255, 255), pos, 20) |
| 51 | + |
| 52 | + pygame.draw.rect(screen, tuple(color), (0, 240, 640, 240)) |
| 53 | + |
| 54 | + pygame.display.update() |
0 commit comments