File: blend_fill.py

package info (click to toggle)
pygame 1.9.4.post1%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 10,412 kB
  • sloc: ansic: 54,632; python: 28,791; objc: 334; php: 92; sh: 76; makefile: 36; cpp: 25
file content (102 lines) | stat: -rw-r--r-- 3,105 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/env python
import os
import pygame
from pygame.locals import *

def usage ():
    print ("Press R, G, B to increase the color channel values,")
    print ("1-9 to set the step range for the increment,")
    print ("A - ADD, S- SUB, M- MULT, - MIN, + MAX")
    print ("  to change the blend modes")


main_dir = os.path.split(os.path.abspath(__file__))[0]
data_dir = os.path.join(main_dir, 'data')

def main():
    color = [0, 0, 0]
    changed = False
    blendtype = 0
    step = 5

    pygame.init ()
    screen = pygame.display.set_mode ((640, 480), 0, 32)
    screen.fill ((100, 100, 100))

    image = pygame.image.load (os.path.join (data_dir, "liquid.bmp")).convert()
    blendimage = pygame.image.load (os.path.join (data_dir, "liquid.bmp")).convert()
    screen.blit (image, (10, 10))
    screen.blit (blendimage, (200, 10))

    pygame.display.flip ()
    pygame.key.set_repeat (500, 30)
    usage()

    going = True
    while going:
        for event in pygame.event.get ():
            if event.type == QUIT:
                going = False

            if event.type == KEYDOWN:
                usage ()

                if event.key == K_ESCAPE:
                    going = False

                if event.key == K_r:
                    color[0] += step
                    if color[0] > 255:
                        color[0] = 0
                    changed = True

                elif event.key == K_g:
                    color[1] += step
                    if color[1] > 255:
                        color[1] = 0
                    changed = True

                elif event.key == K_b:
                    color[2] += step
                    if color[2] > 255:
                        color[2] = 0
                    changed = True

                elif event.key == K_a:
                    blendtype = BLEND_ADD
                    changed = True
                elif event.key == K_s:
                    blendtype = BLEND_SUB
                    changed = True
                elif event.key == K_m:
                    blendtype = BLEND_MULT
                    changed = True
                elif event.key == K_PLUS:
                    blendtype = BLEND_MAX
                    changed = True
                elif event.key == K_MINUS:
                    blendtype = BLEND_MIN
                    changed = True

                elif event.key in (K_1, K_2, K_3, K_4, K_5, K_6, K_7, K_8, K_9):
                    step = int (event.unicode)

            if changed:
                screen.fill ((100, 100, 100))
                screen.blit (image, (10, 10))
                blendimage.blit (image, (0, 0))
                #blendimage.fill (color, (0, 0, 20, 20), blendtype)
                blendimage.fill (color, None, blendtype)
                screen.blit (blendimage, (200, 10))
                print ("Color: %s, Pixel (0,0): %s" %
                       (tuple(color),
                        [blendimage.get_at ((0, 0))]))
                changed = False
                pygame.display.flip ()


    pygame.quit()


if __name__ == '__main__': 
    main()