-1
from PIL import Image
import time
start = time.time()
import random as r
x = int(input("Enter the preferred width of your image:"))
y = int(input("Enter the preferred length of your image:"))
suggested = (x*y)
print("We suggest you use:",suggested,"pixels")
amount = int(input("How many pixels do you want to generate?"))
while amount > suggested:
amount = int(input("Please choose the number suggested or smaller. How many pixels do you want to generate?"))
numbers = []
numbs = (r.randint(0,255),r.randint(0,255),r.randint(0,255))
while len(numbers)<(amount):
numbers.append(numbs)
numbs = (r.randint(0,255),r.randint(0,255),r.randint(0,255))
print(numbers)
print('It took', time.time()-start, 'seconds')
im2 = Image.new('RGB', (x,y))
im2.putdata(numbers)
im2.show()
im2.save("out.png")
私が使ったコードでは、1つのタプルに3つの乱数を入れ、そのタプルをリストに入れます。各タプルはピクセルです。ユーザーが入力する寸法は、常に幅xと幅yの直線形状になります。形状を丸くし、曲線を描きたいと思います。どうやって?ありがとう。シェイプを円にするにはどうすればいいですか?