-
-
Save sneeu/2576080 to your computer and use it in GitHub Desktop.
Generate Hirst–like circles
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
import datetime | |
import hashlib | |
from PIL import Image, ImageDraw | |
def circles(across, down, radius): | |
# Scale the image up by 4, to anti-alias. | |
scale = 4 | |
render_radius = scale * 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 / scale, height / scale), 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