好吧,所以我有这个程序,试图将滤镜放在所选颜色的所选图像上。我正在Jython中编写此代码,这是代码:这是代码:
def makeGrayscale(pixel): #makes the image grayscale
newRed = getRed(pixel)*0.299
newGreen = getGreen(pixel)*0.587
newBlue = getBlue(pixel)*0.114
luminance = newRed+newGreen+newBlue
setColor(pixel, makeColor(luminance, luminance, luminance))
def makePurple(pixel): #makes the image purple
value=getGreen(pixel)
setGreen(pixel,value*0.25)
value=getRed (pixel)
setRed(pixel,value*0.8)
value=getBlue(pixel)
setBlue(pixel,value*1)
def makeRed(pixel): #makes the image red
value=getGreen(pixel)
setGreen(pixel,value*0.25)
value=getRed (pixel)
setRed(pixel,value*1)
value=getBlue(pixel)
setBlue(pixel,value*0.25)
def makeGreen(pixel): #makes the image green
value=getGreen(pixel)
setGreen(pixel,value*1)
value=getRed (pixel)
setRed(pixel,value*0.25)
value=getBlue(pixel)
setBlue(pixel,value*0.25)
def makeBlue(pixel): #makes the image blue
value=getGreen(pixel)
setGreen(pixel,value*0.25)
value=getRed (pixel)
setRed(pixel,value*0.25)
value=getBlue(pixel)
setBlue(pixel,value*1)
#lope is the picture btw
showInformation("Choose a photo") #basic UI
file = pickAFile()
lope = makePicture(file)
for px in getPixels(lope): #this turns the image into a grayscale so the
user can filter the image into any color they want
makeGrayscale(px) # without interference from the colors of the
original image
color = requestString("What color filter do you want on your image?")
if color == "Gray" or "gray":
show(lope)
elif color == "Red" or "red":
for px in getPixels(picture):
makeRed(px)
elif color == "Green" or "green":
for px in getPixels(lope):
makeGreen(px)
elif color == "Blue" or "blue":
for px in getPixels(lope):
makeBlue(px)
elif color == "Purple" or "purple":
for px in getPixels(lope):
makePurple(px)
else: showError("Color not found") #extra error message
show(lope)
我的问题出在我运行该程序时,无论用户输入什么内容,它将始终运行第一个if可执行文件。为什么这样做呢?它不应该出现在第一个if语句中,并且由于它为假,所以继续执行下一个并测试该语句?请帮忙!