Python. Image background random generator

I want to create random background generator to create random layer for my composed images.

generate image with питон and Программирование|lower


PYTHON. RANDOM IMAGE GENERATION

1. Create image from random pixels:

import numpy

from PIL import Image

random_matrix = numpy.random.rand(500,300,4)*255 # args 500,300,4 is array dimensions. Each pixels has 4 values RGBA

cat_image = Image.fromarray(random_matrix.astype('uint8')) # Convert data format

cat_image.save('path/to/cat/image.png')

1.1. Create image with random color:

from PIL import Image

imort random

dog_image = Image.new(mode='RGBA', size=(500, 300), color=(int(random.random()*255),int(random.random()*255),int(random.random()*255)))
dog_image.save('dog_image.png')

2. I want some random auto image like fractal. Is it possible to generate?

2.1. import turtle

2.1.1. Create function for Koch fractal:

def koch(turtle, div, siz):
   if(div == 0):
      turtle.forward(siz)
   else:
      for squirrel in [60, -120, 60, 0]:
         koch(turtle, div - 1, siz / 3)              
         turtle.left(squirrel)

d=3

s = 300

w=turtle.Screen()

w.setup(width=1000, height = 500)

turtle.speed(1000)

turtle.pendown()

for jack in range(3):

koch(turtle,d,s)

turtle.left(-120) 

2.1.2. turtle lib requires tkinter (lib for GUI applications) to be installed. // $ pip install tk // No

2.1.3. I still get error "no module named tkinter" while import turtle

2.1.4. $ sudo apt-get install python3-tk

3. Load an bmp image into numpy.

image = np.asarray(img)