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()

never mind fixed it, check this out, I like it I think it's getting kinda cool, but I need more randomness

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 draw2(image):
 

      return ImageDraw.Draw(image)      
steps = 6
data = ((0, 500), (500, 500), (250, 0))            
size = data[1]
update_image = draw2(im)


for i in range(1000):
    rndcol = (random.randint(1,255),random.randint(1,255),random.randint(1,255))
    sierpinski(data, steps, update_image, 0)
   
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))

              









#end of triangles code







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()

Allright, check this out... run it a couple times too... not done yet, but I'm likin it

import Image
import ImageDraw
import random

sizex= 1440
sizey = 900
im = Image.new("RGB", (sizex, sizey))





def triangles(point, reps, tmaker, h):

      tmaker.line((point[0], point[1]))
      tmaker.line((point[1], point[2]))
      tmaker.line((point[0], point[2]))
      
      x1 = (point[0][0] + point[1][0]) / 2
      y1 = (point[0][1] + point[1][1]) / 2
      
      x2 = (point[1][0] + point[2][0]) / 2
      y2 = (point[1][1] + point[2][1]) / 2
       
      
      x3 = (point[2][0] + point[0][0]) / 2
      y3 = (point[2][1] + point[0][1]) / 2
        
      point2 = ((x1, y1), (x2, y2), (x3, y3))

      h += 1

      if h <= reps:

            triangles((point[0], point2[0], point2[2]), reps, tmaker, h)
       
            triangles((point[1], point2[0], point2[1]), reps, tmaker, h)

def draw2(image):
 

      return ImageDraw.Draw(image)      
reps = random.randint(0,10)
point = ((0, 700), (500, 500), (350, 0))            
size = point[1]
tmaker = draw2(im)

for i in range(1000):
      rndcol = (random.randint(1,255),random.randint(1,255),random.randint(1,255))
      triangles(point, reps, tmaker, 0)

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))
#end triangle 1




def draw3(image):
 

      return ImageDraw.Draw(image)      
reps = random.randint(0,10)
point = ((0, 700), (1000, 1000), (350, 0))            
size = point[1]
tmaker = draw2(im)

for i in range(1000):
      rndcol = (random.randint(1,255),random.randint(1,255),random.randint(1,255))
      triangles(point, reps, tmaker, 0)
   
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))

#end triangle 2

def draw4(image):
            return ImageDraw.Draw(image)      
reps = random.randint(0,10)
point = ((500, 500), (1000, 1000), (350, 0))            
size = point[1]
tmaker = draw2(im)

for i in range(1000):
      rndcol = (random.randint(1,255),random.randint(1,255),random.randint(1,255))
      triangles(point, reps, tmaker, 0)
   
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))










#end pyramid scheme
im.save('background.png', 'png')
im.show()
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.