purpleRinse.py
def classDemo(fileName):
picture = makePicture(fileName)
show(picture)
manipulate(picture)
repaint(picture)
def manipulate(image):
for pix in getPixels(image):
purpleRinse2(pix)
# Hand-coded version without the distance function, which was incorrect in first version of JES
# made available for download.
def purpleRinse1(pixel):
hairRed = 161
hairGreen = 137
hairBlue = 125
r = getRed(pixel)
g = getGreen(pixel)
b = getBlue(pixel)
if (abs(r-hairRed) < 10 and abs(b-hairBlue) < 10 and abs(g-hairGreen) < 10):
setRed(pixel, r*1.5)
setBlue(pixel, b* 2)
# Better solution, using built-in distance function. This works with the latest version
# of JES available on the downloads page.
def purpleRinse2(pixel):
hairColor = makeColor(161, 137, 125)
pixelColor = getColor(pixel)
if distance(hairColor, pixelColor) < 10:
setRed(pixel, getRed(pixel) *1.5)
setBlue(pixel, getBlue(pixel)* 2)
Link to this Page