Skip to content

Instantly share code, notes, and snippets.

Created May 2, 2012 11:57
Show Gist options
  • Save anonymous/2576078 to your computer and use it in GitHub Desktop.
Save anonymous/2576078 to your computer and use it in GitHub Desktop.
import datetime
import hashlib
from PIL import Image, ImageDraw
def circles(across, down, radius):
render_radius = 4 * radius
width = (2 * across - 1) * (2 * render_radius)
height = (2 * down - 1) * (2 * render_radius)
im = Image.new('RGB', (width, height), '#ffffff')
draw = ImageDraw.Draw(im)
for x in xrange(0, across):
center_x = 4 * x * render_radius
for y in xrange(0, down):
center_y = 4 * y * render_radius
colour = hashlib.md5(datetime.datetime.utcnow().isoformat()).hexdigest()[:6]
draw.ellipse((center_x, center_y, center_x + 2 * render_radius, center_y + 2 * render_radius), fill='#' + colour)
im.thumbnail((width / 4, height / 4), Image.ANTIALIAS)
im.save('circles.png')
if __name__ == '__main__':
circles(4, 4, 48)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment