from PIL import Image
from colorPixelListPIL import *

def negative_color(pic,n):
    span = 256/n
    width, height = pic.size
    ni = Image.new("RGB", (width,height),(255,255,255))
    for w in range(width):
        for h in range(height):
            pix = pic.getpixel((w,h))
            (r,g,b) = pix
            newR = int(n-r/span)*256//n #+ 128//n
            newG = int(n-g/span)*256//n #+ 128//n
            newB = int(n-b/span)*256//n #+ 128//n
            ni.putpixel((w,h),(newR, newG, newB))
    return ni

def grayscale(pic):
    width, height = pic.size
    ni = pic.copy()
    for w in range(width):
        for h in range(height):
            pix = pic.getpixel((w,h))
            (r,g,b) = pix
            avg = int((r+g+b)/3)
            ni.putpixel((w,h),(avg,avg,avg))
    return ni

def negative_range(pic):
    width, height = pic.size
    ni = pic.copy()
    c1 = bisque4
    c2 = SteelBlue2
    c3 = CadetBlue
    c4 = dark_sea_green
    c5 = PaleTurquoise4
    c6 = OliveDrab1
    for w in range(width):
        for h in range(height):
            pix = pic.getpixel((w,h))
            (r,g,b) = pix
            if r <256/6*1:
                pix = c1
            elif r <256/6*2:
                pix = c2
            elif r <256/6*3:
                pix = c3
            elif r <256/6*4:
                pix = c4
            elif r <256/6*5:
                pix = c5
            elif r <256/6*6:
                pix = c6
            ni.putpixel((w,h),pix)
    return ni
            
a = Image.open("original.jpg")
b = negative_color(a,7)
b.save("negated.jpg")

c = grayscale(a)
d = negative_range(c)
d.save("negated_1.jpg")
