OK, so heres my code, check it out, let me know what you think, I'm trying to embed a serpenski triangle into it, and the program isn't crashing but it isn't displaying and I'm not sure why, if you can tell me it would be greatly appreciated. Also, I need to know how to make the location of the geometric shapes randomly generate their positions and colors each time they generate. Thanks for looking guys, any help is appreciated.
import Image
import ImageDraw
import random
sizex= 1280
sizey = 800
im = Image.new("RGB", (sizex, sizey))
def sierpinski(data, steps, update_image, k):
update_image.line((data[0], data[1]))
update_image.line((data[1], data[2]))
update_image.line((data[0], data[2]))
x1 = (data[0][0] + data[1][0]) / 2
y1 = (data[0][1] + data[1][1]) / 2
x2 = (data[1][0] + data[2][0]) / 2
y2 = (data[1][1] + data[2][1]) / 2
x3 = (data[2][0] + data[0][0]) / 2
y3 = (data[2][1] + data[0][1]) / 2
data2 = ((x1, y1), (x2, y2), (x3, y3))
k += 1
if k <= steps:
sierpinski((data[0], data2[0], data2[2]), steps, update_image, k)
sierpinski((data[1], data2[0], data2[1]), steps, update_image, k)
def draw(image):
return ImageDraw.Draw(image)
steps = 6
data = ((0, 500), (500, 500), (250, 0))
size = data[1]
picture = Image.new('1', size, color="blue")
update_image = draw(picture)
sierpinski(data, steps, update_image, 0)
def DrawBox(C):
numbx = random.randint(100, 1440)
numby = random.randint(-900, -100)
newx = numbx + (random.randint(30, 100))
newy = numby + (random.randint(30, 100))
draw = ImageDraw.Draw(im)
draw.rectangle([(600,100),(800,800)], fill=(45,0,0), outline=(random.randint(1,255),0,0))
draw.rectangle([(300,100),(400,600)], fill=(0,89,0), outline=(random.randint(1,56),0,0))
draw.rectangle([(500,600),(800,900)], fill=(0,0,156), outline=(random.randint(45,45),0,0))
for i in range(1000):
rndcol = (random.randint(1,255),random.randint(1,255),random.randint(1,255))
DrawBox(rndcol)
draw = ImageDraw.Draw(im)
draw.line((0, 0) + im.size, fill=(0,89,0))
draw.line((0, im.size[1], im.size[0], 0), fill=(45,67,0))
im.save('background.png', 'png')
im.show()