# Recipe 85: Visualising sound

def soundToPicture(sound):

  picture = makeEmptyPicture(640,480)
  soundIndex = 1

  for p in getPixels(picture):
    if soundIndex > getLength(sound):
      break

    sample = getSampleValueAt(sound,soundIndex)
    if sample > 1000:
      setColor(p,red)
    if sample < -1000:
      setColor(p,blue)
    if sample <= 1000 and sample >= -1000:
      setColor(p,green)
    soundIndex = soundIndex + 1

  return picture

