也许这对许多人来说是很容易的事情。我正在尝试用两种颜色创建背景。目的是它从左侧以一种颜色开始,以右侧(水平方向)的另一种颜色结束。
问题是我从一个角落到另一个角落。我正在寻找的是它是并排的。
我的代码:
from PIL import Image, ImageDraw
def interpolate(f_co, t_co, interval):
det_co =[(t - f) / interval for f , t in zip(f_co, t_co)]
for i in range(interval):
yield [round(f + det * i) for f, det in zip(f_co, det_co)]
imgsize=(1920,1080)
gradient = Image.new('RGBA', imgsize, color=0)
draw = ImageDraw.Draw(gradient)
f_co = (253, 46, 216)
t_co = (23, 214, 255)
for i, color in enumerate(interpolate(f_co, t_co, gradient.width * 2)):
draw.line([(i, 0), (0, i)], tuple(color), width=1)
gradient.show()
Run Code Online (Sandbox Code Playgroud)
结果: https: //i.stack.imgur.com/Wb00f.png