def generate_random_stic ks width height num from random import randin

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
def generate_random_sticks(width, height, num):
from random import randint
from StringIO import StringIO
res = []
for i in range(num):
res.append(';'.join(map(str,[randint(0,width), randint(0,height), randint(0,width), randint(0,height)])))
return StringIO('\n'.join(res))
def draw_sticks(sticks, file):
import Image, ImageDraw
magn = 50
max_x = max(x for pair in map(lambda s: (s[0][0], s[1][0]), sticks) for x in pair)
max_y = max(x for pair in map(lambda s: (s[0][1], s[1][1]), sticks) for x in pair)
im = Image.new("RGB",map(int,(max_x*magn, max_y*magn)), (255,255,255))
draw = ImageDraw.Draw(im)
for s in sticks:
draw.line(map(lambda x: x*magn, s[0]+s[1]),fill=(0,0,0))
im.save("/tmp/sticks.png")
im.show()