text: # Import important modules
  import pygame
  import time, random, math
  
  from pygame import rect
  from pygame.constants import K_DOWN, K_LEFT, K_RIGHT, K_UP, USEREVENT
  
  # Init Pygame
  pygame.init()
  clock = pygame.time.Clock()
  clock.tick(120)
  
  # Variables
  SceneActive = True
  background = (255, 255, 255)
  
  # Standard Colors
  BLACK = (0, 0, 0)
  
  # Game Vars
  TileSize = 30
  Columns = 30
  Rows = 30
  LineThickness = 1
  
  SnakeHeadSize = 1
  SnakeBodySize = 1
  SnakeBodyRandomness = 0
  SnakeStartPos = [math.ceil(Rows/2), math.ceil(Columns/2)]
  SnakeMoveTime = 150
  
  SnakeHeadColor = (0, 255, 0)
  SnakeBodyColor = (0, 255, 0)
  
  # Snake Classes
  class Body:
      def __init__(self, pos, dir) -> None:
          self.size = TileSize*(SnakeBodySize + random.randint(-1, 1)*random.random()*SnakeBodyRandomness)
          self.color = SnakeBodyColor
          self.position = pos
          self.direction = dir
          
      def draw(self, animTime):
          self.animPos = (self.position[0]+self.direction[0]*(animTime/SnakeMoveTime), self.position[1]+self.direction[1]*(animTime/SnakeMoveTime))
          pygame.draw.rect(screen, self.color, (self.animPos[0]*TileSize+((TileSize-self.size)/2), self.animPos[1]*TileSize+((TileSize-self.size)/2), self.size, self.size))
      def move(self, nextPart):
          self.position[0] += self.direction[0]
          self.position[1] += self.direction[1]
          self.direction = (nextPart.position[0]-self.position[0], nextPart.position[1]-self.position[1])
  class Head:
      def __init__(self, pos, dir) -> None:
          self.size = TileSize*SnakeHeadSize
          self.color = SnakeHeadColor
          self.position = pos
          self.direction = dir
          self.nextDirection = self.direction
      def draw(self, animTime):
          self.animPos = (self.position[0]+self.direction[0]*(animTime/SnakeMoveTime), self.position[1]+self.direction[1]*(animTime/SnakeMoveTime))
          pygame.draw.rect(screen, self.color, (self.animPos[0]*TileSize+((TileSize-self.size)/2), self.animPos[1]*TileSize+((TileSize-self.size)/2), self.size, self.size))
      def move(self):
          self.position[0] += self.direction[0]
          self.position[1] += self.direction[1]
          self.direction = self.nextDirection
  class Snake:
      def __init__(self, length, startPos) -> None:
          self.parts = [Body([SnakeStartPos[0]-(x+1), SnakeStartPos[1]], (1, 0)) for x in range(length-1)]
          self.parts.insert(0, Head(startPos, (1, 0)))
          self.headPos = self.parts[0].position
      def draw(self, animTime):
          for part in self.parts:
              part.draw(animTime)
  
  snake = Snake(100, SnakeStartPos)
  
  screen = pygame.display.set_mode((TileSize*Columns, TileSize*Rows))
  
  # Draw Grid
  def DrawGrid(cols, rows, size, thickness):
      for col in range(cols):
          for row in range(rows):
              pygame.draw.rect(screen, BLACK, (col*size, row*size, size, size), thickness)
  
  MoveSnakeEvent = pygame.USEREVENT+1
  MoveStartTime = pygame.time.get_ticks()
  AnimationTime = pygame.time.get_ticks()-MoveStartTime
  
  pygame.time.set_timer(MoveSnakeEvent, SnakeMoveTime)
  
  
  # Game Loop
  while SceneActive:
      # Refresh Screen
      screen.fill(background)
  
      # Draw Grid
      DrawGrid(Columns, Rows, TileSize, LineThickness)
  
      # Event Handler
      for event in pygame.event.get():
          if event.type == pygame.QUIT:
              SceneActive = False
          if event.type == pygame.KEYDOWN:
              if event.key == K_UP:
                  snake.parts[0].nextDirection = (0, -1)
              elif event.key == K_DOWN:
                  snake.parts[0].nextDirection = (0, 1)
              if event.key == K_LEFT:
                  snake.parts[0].nextDirection =  (-1, 0)
              elif event.key == K_RIGHT:
                  snake.parts[0].nextDirection = (1, 0)
          if event.type == MoveSnakeEvent:
              snake.parts[0].move()
              for part in enumerate(snake.parts[1:]):
                  part[1].move(snake.parts[part[0]])
              MoveStartTime = pygame.time.get_ticks()
      AnimationTime = pygame.time.get_ticks()-MoveStartTime
  
      # Draw Snake 
      snake.draw(AnimationTime)
  
      # Update Screen
      pygame.display.update()
  
  
  # Exit Pygame
  pygame.quit()