Skip to content

Instantly share code, notes, and snippets.

@jcarlosroldan
Last active October 28, 2020 12:56
Show Gist options
  • Select an option

  • Save jcarlosroldan/ba3c7d6afd329cf99a6867679ffd943a to your computer and use it in GitHub Desktop.

Select an option

Save jcarlosroldan/ba3c7d6afd329cf99a6867679ffd943a to your computer and use it in GitHub Desktop.
Generate color spectrum using PIL
from PIL import Image
WIDTH = 700
HEIGHT = 350
img = Image.new('HSV', (WIDTH, HEIGHT))
for x in range(WIDTH):
for y in range(HEIGHT):
if y < HEIGHT / 2: # white to rainbow
color = (255 * x / WIDTH, 255 * (2 * y / HEIGHT), 255)
else: # rainbow to black
color = (255 * x / WIDTH, 255, 2 * 255 * (1 - y / HEIGHT))
img.putpixel((x, y), tuple(map(int, color)))
img.convert('RGB').save('spectrum.png')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment