2013-08-21 1 views
0

이 스크립트의 어딘가에 그라디언트가 생성됩니다. 깊이가 차이와 같을 때 그라디언트는 완벽하지만 부동 소수점 증가는이를 망칠 것 같습니다. 나는 오랫동안이 코드를 쳐다 보면서 대답을 볼 수 없었다.그래디언트 생성 오류.

이 코드의 잘못된 점은 무엇입니까?

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" 
+0

문제를 보여 그'depth','start', 그리고'end'에 대한 값을 제공 할 수 있을까요? "_ 플로팅 포인트 증분이 올라간다"라고 말하면 "오류 메시지가 나타납니다"또는 "실행되지만 결과가 예상대로 표시되지 않습니다"라는 의미입니까? 오류 메시지 및/또는 잘못된 결과 이미지를 게시하십시오. – Kevin

+0

들여 쓰기가 엉망입니다. 'interpolate'의 모든 줄은 잘못된 들여 쓰기 단계에 있습니다. –

답변

2

이 : 예를 들어 diff가 3 n가 2 인 경우 있도록

increment =diff/n 

는, 정수 나눗셈을하고

, 당신은 1.5 일하지 얻을.

식 플로트를 확인,이 문제를 해결하려면 :

increment = float(diff)/n 
+0

그러나 이것은 단지 3.0 이전의 Python에서만 사실입니다. 3.0+에서/연산자는 "참"나누기를 수행하고 정수 나누기를 수행합니다. –

+0

이것은 효과가없는 것 같습니다. –

관련 문제