Created
February 23, 2015 21:05
-
-
Save Arachnid/d4cb28bfed98475c8cdb to your computer and use it in GitHub Desktop.
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 random | |
import sys | |
from PIL import Image, ImageDraw | |
starts = range(0, 85, 12) | |
# Defined as (start_pixel, end_pixel, is_down) | |
circles = [ | |
(starts[0], starts[1], False), | |
(starts[0], starts[1], True), | |
(starts[0], starts[2], False), | |
(starts[0], starts[2], True), | |
(starts[0], starts[3], False), | |
(starts[0], starts[3], True), | |
(starts[0], starts[4], False), | |
(starts[0], starts[4], True), | |
(starts[1], starts[2], False), | |
(starts[1], starts[2], True), | |
(starts[1], starts[3], False), | |
(starts[1], starts[3], True), | |
(starts[1], starts[4], False), | |
(starts[1], starts[4], True), | |
(starts[1], starts[5], False), | |
(starts[1], starts[5], True), | |
(starts[2], starts[3], False), | |
(starts[2], starts[3], True), | |
(starts[2], starts[4], False), | |
(starts[2], starts[4], True), | |
(starts[2], starts[5], False), | |
(starts[2], starts[5], True), | |
(starts[2], starts[6], False), | |
(starts[2], starts[6], True), | |
(starts[3], starts[4], False), | |
(starts[3], starts[4], True), | |
(starts[3], starts[5], False), | |
(starts[3], starts[5], True), | |
(starts[3], starts[6], False), | |
(starts[3], starts[6], True), | |
(starts[3], starts[7], False), | |
(starts[3], starts[7], True), | |
(starts[4], starts[7], False), | |
(starts[4], starts[7], True), | |
(starts[5], starts[7], False), | |
(starts[5], starts[7], True), | |
(starts[6], starts[7], False), | |
(starts[6], starts[7], True), | |
] | |
fillpoints = [(x, 24) for x in range(6, 84, 12)] | |
def draw_semicircle(draw, fill, x1, x2, down): | |
radius = (x2 - x1) / 2 | |
bb = (x1, 24 - radius, x2, 24 + radius) | |
if down: | |
draw.arc(bb, 0, 180, fill=fill) | |
else: | |
draw.arc(bb, 180, 0, fill=fill) | |
def draw(num): | |
img = Image.new('1', (84, 48), 255) | |
draw = ImageDraw.Draw(img) | |
for circle in circles: | |
if num & 1: | |
draw_semicircle(draw, 0, *circle) | |
num >>= 1 | |
for fillpoint in fillpoints: | |
if num & 1: | |
ImageDraw.floodfill(img, fillpoint, 0) | |
num >>= 1 | |
return img | |
def random_image_number(): | |
imgnum = 0 | |
num_fills = random.randrange(0, 2) | |
bits = range(len(fillpoints)) | |
random.shuffle(bits) | |
for bit in bits[:num_fills]: | |
imgnum |= 1 << bit | |
imgnum <<= len(circles) | |
num_circles = random.randrange(3, 10) | |
bits = range(len(circles)) | |
random.shuffle(bits) | |
for bit in bits[:num_circles]: | |
imgnum |= 1 << bit | |
return imgnum | |
if __name__ == '__main__': | |
img = Image.new('1', (500, 860), 255) | |
for x in range(10): | |
for y in range(10): | |
imgnum = random_image_number() | |
img.paste(draw(imgnum).rotate(90), (x * 50, y * 86)) | |
img.show() | |
# if len(sys.argv) > 1: | |
# imgnum = int(sys.argv[1]) | |
# else: | |
# imgnum = random_image_number() | |
# print imgnum | |
# img = draw(imgnum) | |
# img.rotate(90).show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment