Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何使形状创建为圆形? 从PIL导入图像 导入时间 开始=时间。时间() 将随机导入为r x=int(输入(“输入图像的首选宽度:”) y=int(输入(“输入图像的首选长度:”) 建议=(x*y) 打印(“我们建议您使用:”,建议使用“像素”) amount=int(输入(“要生成多少像素?”) 虽然金额>建议: amount=int(输入(“请选择建议的数字或更小的数字。要生成多少像素?”) 数字=[] numbs=(r.randint(0255)、r.randint(0255)、r.randint(0255)) 而len(numbers)_Python_Python 3.x - Fatal编程技术网

Python 如何使形状创建为圆形? 从PIL导入图像 导入时间 开始=时间。时间() 将随机导入为r x=int(输入(“输入图像的首选宽度:”) y=int(输入(“输入图像的首选长度:”) 建议=(x*y) 打印(“我们建议您使用:”,建议使用“像素”) amount=int(输入(“要生成多少像素?”) 虽然金额>建议: amount=int(输入(“请选择建议的数字或更小的数字。要生成多少像素?”) 数字=[] numbs=(r.randint(0255)、r.randint(0255)、r.randint(0255)) 而len(numbers)

Python 如何使形状创建为圆形? 从PIL导入图像 导入时间 开始=时间。时间() 将随机导入为r x=int(输入(“输入图像的首选宽度:”) y=int(输入(“输入图像的首选长度:”) 建议=(x*y) 打印(“我们建议您使用:”,建议使用“像素”) amount=int(输入(“要生成多少像素?”) 虽然金额>建议: amount=int(输入(“请选择建议的数字或更小的数字。要生成多少像素?”) 数字=[] numbs=(r.randint(0255)、r.randint(0255)、r.randint(0255)) 而len(numbers),python,python-3.x,Python,Python 3.x,我使用了你的代码,能够添加一个开放的绿色圆圈和一个蓝色填充圆圈。试一试: 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)

我使用了你的代码,能够添加一个开放的绿色圆圈和一个蓝色填充圆圈。试一试:

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")
从PIL导入图像,ImageDraw
导入时间
输入数学
#
开始=时间。时间()
将随机导入为r
#x=int(输入(“输入图像的首选宽度:”)
x=100
#y=int(输入(“输入图像的首选长度:”)
y=150
建议=(x*y)
打印(“我们建议您使用:”,建议使用“像素”)
#amount=int(输入(“要生成多少像素?”)
金额=15000
虽然金额>建议:
amount=int(输入(“请选择建议的数字或更小的数字。要生成多少像素?”)
数字=[]
numbs=(r.randint(0255)、r.randint(0255)、r.randint(0255))
而len(数字)
from PIL import Image, ImageDraw
import time 
import math
#
start = time.time() 
import random as r 
#x = int(input("Enter the preferred width of your image:"))
x = 100
#y = int(input("Enter the preferred length of your image:"))
y = 150
suggested = (x*y)
print("We suggest you use:",suggested,"pixels")
#amount = int(input("How many pixels do you want to generate?"))
amount = 15000
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)
#-----------------------------------------------------------
numb_test = (255,0,0) # red circle
numb_test = (0,255,0) # green circle
radius_test = min(x,y) * 0.4
print "radius_test = " + str(radius_test)
x_center = x/2
y_center = y/2
angle_test = 0
print "pi = " + str(math.pi)
while angle_test < 360:
    angle_rads = angle_test * math.pi/180.0
    x_test = int(radius_test * math.cos(angle_rads)) + x_center
    y_test = int(radius_test * math.sin(angle_rads)) + y_center
    #print "x_test, y_test = " + str(x_test) + ", " + str(y_test)
    im2.putpixel((x_test, y_test),numb_test)
    angle_test += 1
#
draw = ImageDraw.Draw(im2)
draw.ellipse((20, 20, 40, 40), fill = 'blue', outline ='blue')
#-----------------------------------------------------------
im2.show()
im2.save("out.png")