Stars and Stripes

A variation on the Stars and Stripes American Flag for Independence Day. It’s an exercise in the use of transparency in Pygame. The stripes are made transparent so the stars image behind shows through.

'''     Stars and Stripes
    Just a little July 4th exercise...
    Authour: Alan Richmond, Python3.Codes
'''
import pygame as p

w,h = 1000,624                      # Flag size
y = h/13                            # width of a stripe

d = p.display.set_mode((w,h))

img = p.image.load("stars.jpg").convert()
d.blit(img,(0,0))

s = p.Surface((w,y))
s.set_alpha(100)

rd = p.Color(255,0,0)
wt = p.Color(255,255,255)
c = rd

for i in range(13):

    s.fill(c)
    d.blit(s, (0,y*i))
    if c==rd:   c=wt
    else:       c=rd

p.display.flip()
p.image.save(d,'Stars-Stripes.png')
Author: Mandrian

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.