Skip to content

Instantly share code, notes, and snippets.

@art-solopov
Created February 26, 2014 20:03
Show Gist options
  • Save art-solopov/9237386 to your computer and use it in GitHub Desktop.
Save art-solopov/9237386 to your computer and use it in GitHub Desktop.
Modern art generator
#!/usr/bin/python3
from PIL import Image, ImageDraw
from random import randrange, choice
COLORS = ['black', 'red', 'blue', 'green', 'yellow']
HEIGHT=1000
WIDTH=800
def draw_hline(draw):
y = randrange(HEIGHT)
draw.line([(0, y), (WIDTH, y)], fill=choice(COLORS), width=randrange(5, 10))
def draw_vline(draw):
x = randrange(WIDTH)
draw.line([(x, 0), (x, HEIGHT)], fill=choice(COLORS), width=randrange(5, 10))
def draw_rect(draw):
width = randrange(3 * WIDTH / 4)
height = randrange(3 * HEIGHT / 4)
x = randrange(WIDTH - width)
y = randrange(HEIGHT - height)
draw.rectangle([x, y, x + width, y + height], fill=choice(COLORS), outline=choice(COLORS))
MODES = {
'hline': draw_hline,
'vline': draw_vline,
'rect': draw_rect
}
image = Image.new('RGB', (WIDTH, HEIGHT), 'white')
draw = ImageDraw.Draw(image)
for i in range(randrange(5, 10)):
modefun = choice(list(MODES.values()))
modefun(draw)
del draw
image.save('painting.png')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment