Skip to content

Instantly share code, notes, and snippets.

@Godzil
Last active March 14, 2018 13:51
Show Gist options
  • Save Godzil/a8ada4320e025e4d71655c0caa6ab529 to your computer and use it in GitHub Desktop.
Save Godzil/a8ada4320e025e4d71655c0caa6ab529 to your computer and use it in GitHub Desktop.
Generating Pi Colours
import colorsys
from PIL import Image, ImageDraw
pi = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 9]
image_height = 40
image_width = len(pi) * 10
img = Image.new("RGB", (image_width, image_height))
draw = ImageDraw.Draw(img)
def getColor(val):
c = colorsys.hsv_to_rgb(val / 10, 1, 1)
return ( int(c[0] * 256), int(c[1] * 256), int(c[2] * 256) )
for i in range(len(pi)):
draw.rectangle([i * 10, 0, (i * 10) + 10, image_height], outline=getColor(pi[i]), fill=getColor(pi[i]))
img.save("picolour.png")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment