Last active
October 28, 2020 12:56
-
-
Save jcarlosroldan/ba3c7d6afd329cf99a6867679ffd943a to your computer and use it in GitHub Desktop.
Generate color spectrum using PIL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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