Skip to content

Instantly share code, notes, and snippets.

@andreasf
Created February 2, 2012 21:02
Show Gist options
  • Save andreasf/1725737 to your computer and use it in GitHub Desktop.
Save andreasf/1725737 to your computer and use it in GitHub Desktop.
#!/bin/python
import Image
import ImageDraw
import os
import random
# width
# height
# nx
# ny
# count
# prefix
class Pict:
count = 50
prefix = 'rect'
rects = []
width = 1440
height = 900
nx = 8
ny = 4
def make_image(self):
im = Image.new('RGB', (self.width, self.height))
draw = ImageDraw.Draw(im)
x_width = round(self.width/self.nx)
y_width = round(self.height/self.ny)
for x in range(1, self.nx+1):
for y in range (1, self.ny+1):
x1 = x_width * (x - 1)
x2 = x_width * x
y1 = y_width * (y-1)
y2 = y_width * y
col = self.random_color()
draw.rectangle((x1, y1, x2, y2), fill = col)
return im
def random_color(self):
random.seed()
m = random.randint(0,6)
if (m == 0):
r = random.randint(150,255)
g = random.randint(0,200)
b = random.randint(0,100)
if (m == 1):
r = random.randint(0,200)
g = random.randint(150,255)
b = random.randint(0,100)
if (m == 2):
r = random.randint(0,100)
g = random.randint(0,200)
b = random.randint(150,255)
if (m == 3):
r = 0
g = 0
b = random.randint(30,255)
if (m == 4):
r = random.randint(30,255)
g = 0
b = 0
if (m == 5):
r = 0
g = random.randint(30,200)
b = 0
if (m == 6):
r = random.randint(0,255)
g = random.randint(0,255)
b = random.randint(0,255)
return (r, g, b)
def make_lots(self):
for i in range(0, self.count):
file_name = self.prefix + str(i) + '.png'
z = self.make_image()
z.save(file_name)
z = Pict()
z.make_lots()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment