This question already has an answer here:
Ok so I have this program where I am trying to put a filter over a chosen image of a chosen color. I am writing this in Jython and here is the code: Here is the code:
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)
My problem comes when I run this program and it will always run the first if statement executable no matter what is inputted by the user. Why is it doing this? shouldn't it come to the first if statement and since it is false, just go on to the next and test that? Please help!
Aucun commentaire:
Enregistrer un commentaire