-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")
我使用的代碼將三個隨機數字放入一個元組中,然後將該元組放入列表中。每個元組都是一個像素。用戶輸入的尺寸總是形成一個直的形狀,寬x長,我想使形狀變圓並具有彎曲的邊緣。怎麼樣?謝謝。如何讓形狀創建一個圓形?