#Make a sunset
#Why is this function badly written?
#1) Consistent Organization is important
#2) How many tasks are we doing in this function?
#   A: 2
#   How many tasks should we be doing?
#   A: 1
#   What should we do to redesign this function?
#   Make two loops? Even better: make helper functions
# Key Skills: 1) Read programs for meaning
#             2) Counting tasks
#             3) Separating tasks
#             4) Identifying similar behaviours
#     5) Giving similar behaviours common structure

def badSunset(picture):
   for p in getPixels(picture):
       newBlue = getBlue(p)*0.9
       setBlue(p,newBlue)
       #Should have newGreen if we use newBlue
       setGreen(p,getGreen(p)*0.9) 
   return picture
#A good version (Should just call helper functions)
def goodSunset(picture):
    reduceBlue(picture)
    reduceGreen(picture)
    return picture
#Helper functions for testability (doing one thing)
#Consistent Style
#Exercise: Try this with some stuff from A1.
def reduceBlue(pic):
    for p in getPixels(pic):
      setBlue(p,getBlue(p)*0.9)
def reduceGreen(pic):
    for p in getPixels(pic):
       setGreen(p,getGreen(p)*0.9)
       
#Exercise: Take your exercise 3 and rewrite it
# in this fashion.
#3(a) is the spec for the main function
#3(b) Is a single task that should be in a helper function
#3(c) Is a single task that should be in a helper function
#3(d) Is a single task that should be in a helper function
#3(e) Is a compound task that should be in a seperate function
# with its own helper functions.
#Bit of a trap here: Screws up counting.
# May want to manage counters manually.
# 3b Define your functions to take in indices.
# Did some of the sound examples (clip)
# targetIndex ends task for 3b at
# value= length(smallerSound)/2
def thisIsQ3(sound1,sound2):
    longerSound=whichIsLonger(sound1,sound2)
    shorterSound=whichIsShorter(sound1,sound2)
    #Something for 3b here
    makeEmptySound(length(shorterSound)/2+length(longerSound))
    copy3b(shorterSound,targetSound,length(shorterSound)/2)
    addAndCopy3c(shorterSound,longerSound,targetSound,length(shorterSound)/2, length(shorterSound))
    #...

