Difference between revisions of "CSC111 Lab 7 Solutions 2014"

From dftwiki3
Jump to: navigation, search
(Created page with "--~~~~ ---- =Solution Programs/Functions= <onlydft> <source lang="python"> # fog( image ): creates a foggy image with the top line original to the # original line of pixels,...")
 
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
--[[User:Thiebaut|D. Thiebaut]] ([[User talk:Thiebaut|talk]]) 17:40, 10 March 2014 (EDT)
 
--[[User:Thiebaut|D. Thiebaut]] ([[User talk:Thiebaut|talk]]) 17:40, 10 March 2014 (EDT)
 
----
 
----
 +
<onlydft>
 +
 
=Solution Programs/Functions=
 
=Solution Programs/Functions=
  
<onlydft>
+
 
<source lang="python">
 
<source lang="python">
  
Line 17: Line 19:
 
         green = getGreen(pixel)
 
         green = getGreen(pixel)
 
         blue  = getBlue(pixel)
 
         blue  = getBlue(pixel)
 
+
 
         red  = red + int( (255-red) * 1.0 * y/getHeight( image ) )
+
        fogFactor = 1.0 * y / getHeight( image )
         green = green + int( (255-green) * 1.0 * y/getHeight( image ) )
+
         red  = red + int( (255-red) * fogFactor )
         blue  = blue + int( (255-blue) * 1.0 * y/getHeight( image ) )
+
         green = green + int( (255-green) * fogFactor )
 +
         blue  = blue + int( (255-blue) * fogFactor )
  
 
         newColor = makeColor( red, green, blue )
 
         newColor = makeColor( red, green, blue )
Line 74: Line 77:
 
         setColor( pixel, newColor )
 
         setColor( pixel, newColor )
 
   return image
 
   return image
 +
 +
# saturate(): transforms component into min or max value
 +
# depending on its intensity.
 +
def saturate( component ):
 +
        if component < 125:
 +
          component = 0
 +
        else:
 +
          component = 255
 +
        return component
 +
  
 
# AndyWarhol( image ): saturates the image by saturating the  
 
# AndyWarhol( image ): saturates the image by saturating the  
Line 89: Line 102:
 
         # the line below replaces the pixel with its original color.  Change
 
         # the line below replaces the pixel with its original color.  Change
 
         # the amount of red, green and blue to see some change in the colors
 
         # the amount of red, green and blue to see some change in the colors
        if red < 125:
+
 
          red = 0
+
         newColor = makeColor( saturate(red), saturate(green), saturate(blue) )
        else:
 
          red = 255
 
        if green < 125:
 
          green = 0
 
        else:
 
          green = 255
 
        if blue < 125:
 
          blue = 0
 
        else:
 
          blue = 255
 
         newColor = makeColor( red, green, blue )
 
 
         setColor( pixel, newColor )
 
         setColor( pixel, newColor )
 
   return image
 
   return image
Line 182: Line 184:
  
 
</source>
 
</source>
 +
 +
 
</onlydft>
 
</onlydft>
 
  
 
<br />
 
<br />

Latest revision as of 21:40, 9 January 2015

--D. Thiebaut (talk) 17:40, 10 March 2014 (EDT)



...