''' Module mutate: Purpose provide support for pixel mutation Name 1: Name 2: Email id 1: Email id 2: ''' def same( p ) : ''' Returns a new pixel whose RGB values are ( r, g, b ), where r, g, and b are are the RGB values of pixel p ''' r, g, b = p result = ( r, g, b ) return result def blue( p ) : ''' Returns a new pixel whose RGB values are ( 0, 0, b ), where b is the B value of pixel p ''' r, g, b = p result = ( 0, 0, b ) return result def fade( p ) : # This function is making it paler -- we wanted whole number values # for r, g, b which is why we int everything # We also took the min of 255 and the product of 5 times the r # value so that they don't exceed 255 # we multiplied it by 1.5 to make it more white (bring it closer to # the white color value) r, g, b = p pale_red = int( 1.5 * r ) # getting an RGB value shifted towards white pale_green = int( 1.5 * g ) pale_blue = int( 1.5 * b ) pale_red = min( 255, pale_red ) # make sure shift is a legal RGB value pale_green = min( 255, pale_green ) pale_blue = min( 255, pale_blue ) return ( pale_red, pale_green, pale_blue ) def neg( p ) : ''' Returns a new pixel whose RGB values are the inverse of pixel p, that is ( 255 - r, 255 - g, 255 - b ), where r, g, and b are are the RGB values of pixel p ''' r, g, b = p result = ( 255 - r, 255 - g, 255 - b ) return result def bw( p ) : ''' Returns a new pixel whose RRB values are either ( 0, 0, 0 ) or ( 255, 255, 255 ). It returns ( 0, 0, 0 ) if the average of RGB values for pixel p is closer to 0 then 255; otherwise, it returns ( 255, 255, 255 ) ''' r, g, b = p average = ( r + g + b ) // 3 # get the average of the RGB components if ( average < 255 / 2 ) : # see whether average is below or above the mid RGB level return ( 0, 0, 0 ) else : return ( 255, 255, 255 ) return result def grey( p ) : ''' Returns a new pixel whose RGB values are ( m, m, m ) where m is is the integer cast of .299r + .587g + .114b, where r, g, and b are the RGB values of pixel p ''' r, g, b = p m = int( .299 * r + .587 * g + .114 * b ) return ( m, m, m ) def sepia( p ) : ''' Returns a new pixel whose RGB values are ( sr, sg, sb ) are based on the sepia formula '''