I am generating images with PIL. I am needing to generate 100 image but the second image has the content of the first image and so on. By image 100 all of the previous data is drawn on the old image. Right now its only generating 5.
My goal is to make a animation out of the random images. That is why the next points are near the old points. I thought it would look cool.
I've added my code and the first and second images to show what is going on
from PIL import Image, ImageDraw
import random
def generate():
imagesizepx = 500
imageColor = (255, 255, 255)
paddingpx = 20
count = 0
points = []
for _ in range(5):
image = Image.new(
"RGB",
size=(imagesizepx, imagesizepx),
color=imageColor)
draw = ImageDraw.Draw(image)
if not points:
# randomly generate the points that will be connected by the lines
for _ in range(10):
random_point = (
random.randint(paddingpx, imagesizepx - paddingpx),
random.randint(paddingpx, imagesizepx - paddingpx)
)
points.append(random_point)
else:
# generate new points near old points
for i in range(len(points)):
a, b = points[i]
random_point = (
random.randint(a - 10, a + 10),
random.randint(b - 10, b + 10)
)
points.append(random_point)
thickness = 0
for i, point in enumerate(points):
p1 = point
if i == len(points) - 1:
p2 = points[0]
else:
p2 = points[i + 1]
xy = (p1, p2)
lineColor = "orange"
thickness = 2
draw.line(xy, fill=lineColor, width=thickness)
# save image
image.save(str(count) + ".jpeg")
count += 1

