

'''simple docstring'''






import builtins
import sys

from ...utils.imports import _is_package_available
from . import cursor, input
from .helpers import Direction, clear_line, forceWrite, linebreak, move_cursor, reset_cursor, writeColor
from .keymap import KEYMAP


lowerCAmelCase__      		=			False
try:
 lowerCAmelCase__      		=			_is_package_available('''google.colab''')
except ModuleNotFoundError:
 pass






@input.register
class     lowercase_			:




  """simple docstring"""




  def __init__(   self     :  str      ,lowercase__     :  str = None      ,lowercase__     :  list = []    ):
   __lowercase													=				0
   __lowercase													=				choices
   __lowercase													=				prompt
   if sys.platform == "win32":
    __lowercase													=				'''*'''
   else:
    __lowercase													=				'''➔ '''






  def       SCREAMING_SNAKE_CASE   (   self     :  str      ,lowercase__     :  int      ,lowercase__     :  str = ""    ):
   if sys.platform != "win32":
    writeColor(self.choices[index]      ,3_2      ,lowercase__    )
   else:
    forceWrite(self.choices[index]      ,lowercase__    )






  def       SCREAMING_SNAKE_CASE   (   self     :  Union[str, Any]      ,lowercase__     :  int    ):
   if index == self.position:
    forceWrite(F" {self.arrow_char} "    )
    self.write_choice(lowercase__    )
   else:
    forceWrite(F"    {self.choices[index]}"    )
   reset_cursor()






  def       SCREAMING_SNAKE_CASE   (   self     :  List[Any]      ,lowercase__     :  Direction      ,lowercase__     :  int = 1    ):
   __lowercase													=				self.position
   if direction == Direction.DOWN:
    if self.position + 1 >= len(self.choices    ):
     return
    self.position += num_spaces
   else:
    if self.position - 1 < 0:
     return
    self.position -= num_spaces
   clear_line()
   self.print_choice(lowercase__    )
   move_cursor(lowercase__      ,direction.name    )
   self.print_choice(self.position    )






  @input.mark(KEYMAP['''up''']    )
  def       SCREAMING_SNAKE_CASE   (   self     :  Union[str, Any]    ):
   self.move_direction(Direction.UP    )






  @input.mark(KEYMAP['''down''']    )
  def       SCREAMING_SNAKE_CASE   (   self     :  List[str]    ):
   self.move_direction(Direction.DOWN    )






  @input.mark(KEYMAP['''newline''']    )
  def       SCREAMING_SNAKE_CASE   (   self     :  str    ):
   move_cursor(len(self.choices    ) - self.position      ,'''DOWN'''    )
   return self.position






  @input.mark(KEYMAP['''interrupt''']    )
  def       SCREAMING_SNAKE_CASE   (   self     :  List[Any]    ):
   move_cursor(len(self.choices    ) - self.position      ,'''DOWN'''    )
   raise KeyboardInterrupt






  @input.mark_multiple(*[KEYMAP[str(lowercase__    )] for number in range(1_0    )]    )
  def       SCREAMING_SNAKE_CASE   (   self     :  Any    ):
   __lowercase													=				int(chr(self.current_selection    )    )
   __lowercase													=				index - self.position
   if index == self.position:
    return
   if index < len(self.choices    ):
    if self.position > index:
     self.move_direction(Direction.UP      ,-movement    )
    elif self.position < index:
     self.move_direction(Direction.DOWN      ,lowercase__    )
    else:
     return
   else:
    return






  def       SCREAMING_SNAKE_CASE   (   self     :  Any      ,lowercase__     :  int = 0    ):
   if self.prompt:
    linebreak()
    forceWrite(self.prompt      ,'''\n'''    )
    if in_colab:
     forceWrite('''Please input a choice index (starting from 0), and press enter'''      ,'''\n'''    )
    else:
     forceWrite('''Please select a choice using the arrow or number keys, and selecting with enter'''      ,'''\n'''    )
   __lowercase													=				default_choice
   for i in range(len(self.choices    )    ):
    self.print_choice(lowercase__    )
    forceWrite('''\n'''    )
   move_cursor(len(self.choices    ) - self.position      ,'''UP'''    )
   with cursor.hide():
    while True:
     if in_colab:
      try:
       __lowercase													=				int(builtins.input()    )
      except ValueError:
       __lowercase													=				default_choice
     else:
      __lowercase													=				self.handle_input()
     if choice is not None:
      reset_cursor()
      for _ in range(len(self.choices    ) + 1    ):
       move_cursor(1      ,'''UP'''    )
       clear_line()
      self.write_choice(lowercase__      ,'''\n'''    )
      return choice




'''simple docstring'''






from __future__ import annotations

import matplotlib.pyplot as plt  # type: ignore
import numpy

# initial triangle of Koch snowflake
lowerCAmelCase__      		=			numpy.array([0, 0])
lowerCAmelCase__      		=			numpy.array([0.5, 0.8_660_254])
lowerCAmelCase__      		=			numpy.array([1, 0])
lowerCAmelCase__      		=			[VECTOR_1, VECTOR_2, VECTOR_3, VECTOR_1]


def 	_A  (					A__  ,       A__   ):






 """simple docstring"""



 __lowercase													=				initial_vectors
 for _ in range(A__   ):
  __lowercase													=				iteration_step(A__   )
 return vectors


def 	_A  (					A__   ):






 """simple docstring"""



 __lowercase													=				[]
 for i, start_vector in enumerate(vectors[:-1]   ):
  __lowercase													=				vectors[i + 1]
  new_vectors.append(A__   )
  __lowercase													=				end_vector - start_vector
  new_vectors.append(start_vector + difference_vector / 3   )
  new_vectors.append(
      start_vector + difference_vector / 3 + rotate(difference_vector / 3  ,       60   )   )
  new_vectors.append(start_vector + difference_vector * 2 / 3   )
 new_vectors.append(vectors[-1]   )
 return new_vectors


def 	_A  (					A__  ,       A__   ):






 """simple docstring"""



 __lowercase													=				numpy.radians(A__   )
 __lowercase						,			__lowercase													=				numpy.cos(A__   ), numpy.sin(A__   )
 __lowercase													=				numpy.array(((c, -s), (s, c))   )
 return numpy.dot(A__  ,       A__   )


def 	_A  (					A__   ):






 """simple docstring"""



 __lowercase													=				plt.gca()
 axes.set_aspect('''equal'''   )

 # matplotlib.pyplot.plot takes a list of all x-coordinates and a list of all
 # y-coordinates as inputs, which are constructed from the vector-list using
 # zip()
 __lowercase						,			__lowercase													=				zip(*A__   )
 plt.plot(A__  ,       A__   )
 plt.show()


if __name__ == "__main__":
 import doctest

 doctest.testmod()

 lowerCAmelCase__      		=			iterate(INITIAL_VECTORS, 5)
 plot(processed_vectors)

