This little Pygame program paints the Rainbow Flag, as used by the LGBT movement. It illustrates:
- Importing the Pygame library
- RGB colours in hexadecimal
- Python’s for loop using the enumerate() function
- Filling a rectangular area in Pygame
- Updating display with flip()
- Saving the image
''' RainbowFlag.py
Author: Alan Richmond, Python3.codes
https://en.wikipedia.org/wiki/Rainbow_flag_(LGBT_movement)
'''
import pygame
cols = ['#ff0000','#ff8000','#ffff00','#008000','#0000ff','#a000c0']
w, h = 1000, 618 # width, height
y = h/6 # width per stripe
d = pygame.display.set_mode((w,h))
for i, c in enumerate(cols):
d.fill(pygame.Color(c),rect=(0,i*y,w,y*(i+1)))
pygame.display.flip()
pygame.image.save(d,'RainbowFlag.png')
