I'm trying to generate images for artistic purposes. The images I want to generate show the process of diffusion. Basically I want the image to start in a state of low entropy and move to a state of maximum entropy. I'd like 3 images:
- A circle, half black and half transparent (minimal entropy)
- The black and transparent pixels have partially mixed (medium entropy).
- A circle filled randomly with half black and half transparent pixels (maximum entropy)
My first attempt at this is to start with the black semicircle and then for each pixel, if it's black, move to a random adjacent clear pixel. This works okay, but not perfectly. If I run for enough iterations, it starts to form clumps of black pixels. Here's the relevant part of the code:
for i in range(im.size[0]): # for every col:
for j in range(im.size[1]): # For every row
if pixels[i,j] == (0, 0, 0, 255):
xs = random.randint(-1,1)
ys = random.randint(-1,1)
try:
target = pixels[i+xs, j+ys]
except IndexError:
continue
if (i+xs, j+ys) in badpixels: # badpixels is a hacky way to keep all pixels in a circle
continue
if target == (0, 0, 0, 0): # move if unoccupied
try:
pixels[i+xs,j+ys] = (0, 0, 0, 255)
pixels[i,j] = (0, 0, 0, 0)
except IndexError:
pass
With this process after 500 iterations I get this:
After 1000 iterations I get this:
And after 3000 iterations I get this:
As you can see, there are unwanted clumps at the end. Please let me know how I should proceed to do this properly.