生成渐变时出错

2024-10-02 10:23:32 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个错误,在这个脚本的某个地方,应该产生一个梯度。当深度等于差值时,梯度是完美的,但浮点增量似乎会把它搞砸。我盯着这个代码看了这么久,看不出答案。你知道吗

这个代码怎么了?你知道吗

def interpolate(s, e, n):

start = list(s)
end = list(e)
incrementlst = []

for i in range(0,len(start)):
    diff = int(end[i]) - int(start[i])
    if diff == 0:
        increment = 0.0
    else:
        increment =diff/n


    incrementlst.append(increment)

return incrementlst

def incrementedValue(s, i, n):

    start = list(s)
    increment = list(i)
    n = n-1
    finallst = [0,0,0,0]
    if n < 1:
        return start

    for i in range(0,len(start)):
        finallst[i] = start[i] + (n*(increment[i]))


    return finallst

def formatIncrementedValue(l):

    cmykList = list(l)

    formattedString = str(int(round(cmykList[0], 0))) + " " + str(int(round(cmykList[1], 0))) + " " + str(int(round(cmykList[2], 0))) + " " + str(int(round(cmykList[3], 0)))
    return formattedString

# Get user inputs.
depth = int(ca_getcustomvalue ("depth", "0"))
start = ca_getcustomvalue("start", "0")
end = ca_getcustomvalue("end", "0")

startlst = start.split(" ")
startlst = [int(i) for i in startlst]
endlst = end.split(" ")
endlst = [int(i) for i in endlst]

# draw a line and incrementally change the pen colour towards the end colour 
colorlst = interpolate(startlst, endlst, depth)
for i in range(1,depth-1):
    color = formatIncrementedValue(incrementedValue(startlst, colorlst, i))

    #Draw line at correct offset in colour "color"

Tags: inforreturndefstartlistintend

热门问题