mardi 2 novembre 2021

Python keep generating same number

I want to 100 piece random generated image with 100x100 pixel.

But while i make this image i wanna change the color of the pixel's.

Somehow the images is always the same because its generate same numbers.

What should i change?

from PIL import Image, ImageDraw
import random

source_img = Image.open("base.png").convert("RGBA")

draw = ImageDraw.Draw(source_img)

Height = 100
Width = 100

R = 0
G = 0
B = 0

piece = 0
while (piece < 100):
    while (width > 0):
        while (height > -1):
            color = random.randint(1,3)
            if (color == 1):
                R = 255
                G = 0
                B = 0
            elif (color == 2):
                R = 0
                G = 255
                B = 0
            elif (color == 3):
                R = 0
                G = 0
                B = 255
            
            draw.rectangle(((heigth, 0), (heigth, width)), fill=(R, G, B))
            heigth -=1
        width -= 1
        heigth = 100
    piece +=1
    source_img.save("images/" + str(piece) + ".png", "PNG")
    
print("Images is done!")



Aucun commentaire:

Enregistrer un commentaire