code: def set_pixel(self, x, y, color):
          
          try:  # these checks are for convenience, not for safety
              if len(color) < self.channels:  # color is a a tuple (length >= 1)
                  if len(color) == 1:
                      if self.channels == 2:
                          color = [color[0], 255]
                      elif self.channels == 3:
                          color = [color[0], color[0], color[0]]
                      elif self.channels == 4:
                          color = [color[0], color[0], color[0], 255]
                  elif len(color) == 2:
                      if self.channels == 3:
                          color = [color[0], color[1], 0]
                      elif self.channels == 4:
                          color = [color[0], color[1], 0, 255]
                  elif len(color) == 3:
                      if self.channels == 4:
                          color = [color[0], color[1], color[2], 255]
          except TypeError:  # color is not an iterable
              if self.channels > 1:
                  if self.channels == 2:
                      color = [color, 255]
                  elif self.channels == 3:
                      color = [color, color, color]
                  else:  # only values 1..4 are allowed
                      color = [color, color, color, 255]
          self.array[y, x] = color
docs: Color may be: value, tuple, list etc.
  
          If the image is set to contain more color-channels than len(color), the
          remaining channels will be filled automatically.
          Example (channels = 4, i.e. RGBA output):
            color = 17 -> color = [17,17,17,255]
            color = (17, 99) -> color = [17,99,0,255]
  
          Passing in shorthand color-tuples for larger images on a regular basis
          might result in a very noticeable performance penalty.