Using nested loops, write a function that reduces red in the top third of a picture and clears blue in the bottom third.
The question does not specify the amount to reduce red by. In this solution, a variable is passed in to determine that amount, but it could also have been hardcoded into the function.
```
def colorAffectThirds (src, redReduction):
wThird = int(getWidth(src)/3.0)
hThird = int(getHeight(src)/3.0)
wTwoThird = int(2.0*(getWidth(src)/3.0))
hTwoThird = int(2.0*(getHeight(src)/3.0))
w = (getWidth(src))
h = (getHeight(src))
for x in range(0, wThird):
for y in range(0,hThird):
p = getPixel(src, x, y)
redAmount = getRed(p)-redReduction
if redAmount <0:
redAmount = 0
setRed(p, redAmount)
for x in range(wTwoThird, w):
for y in range(hTwoThird,h):
p = getPixel(src, x, y)
setBlue(p, 0)
```
You might also like to view...
Answer the following statements true (T) or false (F)
1. A RadioButton is known as a switch button because it can be in only the “on” (True) state or the “off” (False) state. 2. RadioButtons can be separated into several groups, but all of the groups must be in the same container (typically a GroupBox). 3. The ReDim statement enables you to dynamically change the array size, type of the array elements, and the number of dimensions in the array. 4. The ReDim statement will automatically save the data stored in the array. 5. The ReDim statement is used only to expand an array.
One or more objects may be created from a(n) __________.
a. field b. method c. instance d. class
Most cybercrimes go unnoticed.
Answer the following statement true (T) or false (F)
With the Targeted Adjustment Tool, which of the following is NOT an adjustment you can make?
a. Parametric Curve b. Graduated Filter c. Hue d. Grayscale Mix