Fill pygame font with custom pattern
Question: I'm currently working on a (first) project in Python/Pygame and I'm trying to
display text with a pattern overlay. The pattern consists vertical lines (1
pixel width), 2 alternating colors .

I'm creating this pattern using pygame.draw.line(), and I can create
rectangles with a custom function I created. But now I want this pattern on my
font.

I'm new to Python and am wondering: is there a way to create some sort of mask
so that the pattern will appear on the font characters only, not outside of
them? I've searched the web for some time but cannot find anything.

Many thanks in advance!


Answer: You could make use of the different blend modes to get the effect you desire.

Here's a simple example (where `t.bmp` is the image with your pattern, but of
course you can just use any other surface):

    
    
    import pygame
    pygame.init()
    screen = pygame.display.set_mode((490, 160))
    font = pygame.font.SysFont('Arial', 150)
    pattern = pygame.image.load('t.bmp').convert()
    text = font.render('FooBar', True, (255, 255, 255), (0, 0, 0))
    
    pattern.blit(text, (0, 0), special_flags = pygame.BLEND_MULT)
    
    screen.blit(pattern, (0, 0))
    pygame.display.flip();
    while True:
        if pygame.event.get(pygame.QUIT):
            break
    

**Result:**

![enter image description here](http://i.stack.imgur.com/X2u7i.png)

