





'''simple docstring'''

from __future__ import annotations

from PIL import Image

# Define glider example
a   	=    [
    [0, 1, 0, 0, 0, 0, 0, 0],
    [0, 0, 1, 0, 0, 0, 0, 0],
    [1, 1, 1, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0],
]

# Define blinker example
a   	=    [[0, 1, 0], [0, 1, 0], [0, 1, 0]]

def     __magic_name__							(				__UpperCAmelCase   )    ->       list[list[int]]:

   '''simple docstring'''







   __SCREAMING_SNAKE_CASE   				=							[]
   for i in range(len(__UpperCAmelCase   )   ):
      __SCREAMING_SNAKE_CASE   				=							[]
      for j in range(len(cells[i]   )   ):
         # Get the number of live neighbours
         __SCREAMING_SNAKE_CASE   				=							0
         if i > 0 and j > 0:
            neighbour_count += cells[i - 1][j - 1]
         if i > 0:
            neighbour_count += cells[i - 1][j]
         if i > 0 and j < len(cells[i]   ) - 1:
            neighbour_count += cells[i - 1][j + 1]
         if j > 0:
            neighbour_count += cells[i][j - 1]
         if j < len(cells[i]   ) - 1:
            neighbour_count += cells[i][j + 1]
         if i < len(__UpperCAmelCase   ) - 1 and j > 0:
            neighbour_count += cells[i + 1][j - 1]
         if i < len(__UpperCAmelCase   ) - 1:
            neighbour_count += cells[i + 1][j]
         if i < len(__UpperCAmelCase   ) - 1 and j < len(cells[i]   ) - 1:
            neighbour_count += cells[i + 1][j + 1]

         # Rules of the game of life (excerpt from Wikipedia):
         # 1. Any live cell with two or three live neighbours survives.
         # 2. Any dead cell with three live neighbours becomes a live cell.
         # 3. All other live cells die in the next generation.
         #    Similarly, all other dead cells stay dead.
         __SCREAMING_SNAKE_CASE   				=							cells[i][j] == 1
         if (
             (alive and 2 <= neighbour_count <= 3)
             or not alive
             and neighbour_count == 3
         ):
            next_generation_row.append(1   )
         else:
            next_generation_row.append(0   )

      next_generation.append(__UpperCAmelCase   )
   return next_generation

def     __magic_name__							(				__UpperCAmelCase				,						__UpperCAmelCase   )    ->       list[Image.Image]:

   '''simple docstring'''







   __SCREAMING_SNAKE_CASE   				=							[]
   for _ in range(__UpperCAmelCase   ):
      # Create output image
      __SCREAMING_SNAKE_CASE   				=							Image.new("""RGB"""				,						(len(cells[0]   ), len(__UpperCAmelCase   ))   )
      __SCREAMING_SNAKE_CASE   				=							img.load()

      # Save cells to image
      for x in range(len(__UpperCAmelCase   )   ):
         for y in range(len(cells[0]   )   ):
            __SCREAMING_SNAKE_CASE   				=							255 - cells[y][x] * 255
            __SCREAMING_SNAKE_CASE   				=							(colour, colour, colour)

        # Save image
      images.append(__UpperCAmelCase   )
      __SCREAMING_SNAKE_CASE   				=							new_generation(__UpperCAmelCase   )
   return images


if __name__ == "__main__":
    a   	=    generate_images(GLIDER, 16)
    images[0].save("out.gif", save_all=True, append_images=images[1:])












'''simple docstring'''

# Copyright 2023 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import TYPE_CHECKING

# rely on isort to merge the imports
from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available, is_vision_available


__lowerCAmelCase				:      Optional[int]						      ={
    "configuration_vivit": ["VIVIT_PRETRAINED_CONFIG_ARCHIVE_MAP", "VivitConfig"],
}
try:
  if not is_vision_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  __lowerCAmelCase				:      int						      =["VivitImageProcessor"]


try:
  if not is_torch_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  __lowerCAmelCase				:      int						      =[
      "VIVIT_PRETRAINED_MODEL_ARCHIVE_LIST",
      "VivitModel",
      "VivitPreTrainedModel",
      "VivitForVideoClassification",
  ]


if TYPE_CHECKING:
  from .configuration_vivit import VIVIT_PRETRAINED_CONFIG_ARCHIVE_MAP, VivitConfig

  try:
    if not is_vision_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .image_processing_vivit import VivitImageProcessor

  try:
    if not is_torch_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_vivit import (
        VIVIT_PRETRAINED_MODEL_ARCHIVE_LIST,
        VivitForVideoClassification,
        VivitModel,
        VivitPreTrainedModel,
    )


else:
  import sys

  __lowerCAmelCase				:      List[Any]						      =_LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)



