



"""simple docstring"""





from math import isclose, sqrt
def      a__			(   lowerCAmelCase__			,    lowerCAmelCase__			,    lowerCAmelCase__   ):
      UpperCAmelCase_    				=							point_y / 4 / point_x
      UpperCAmelCase_    				=							2 * normal_gradient / (1 + normal_gradient * normal_gradient)
      UpperCAmelCase_    				=							(1 - normal_gradient * normal_gradient) / (
          1 + normal_gradient * normal_gradient
      )
      UpperCAmelCase_    				=							(sa - ca * incoming_gradient) / (ca + sa * incoming_gradient)

      # to find the next point, solve the simultaeneous equations:
      # y^2 + 4x^2 = 100
      # y - b = m * (x - a)
      # ==> A x^2 + B x + C = 0
      UpperCAmelCase_    				=							outgoing_gradient**2 + 4
      UpperCAmelCase_    				=							2 * outgoing_gradient * (point_y - outgoing_gradient * point_x)
      UpperCAmelCase_    				=							(point_y - outgoing_gradient * point_x) ** 2 - 100

      UpperCAmelCase_    				=							(
          -linear_term - sqrt(linear_term**2 - 4 * quadratic_term * constant_term   )
      ) / (2 * quadratic_term)
      UpperCAmelCase_    				=							(
          -linear_term + sqrt(linear_term**2 - 4 * quadratic_term * constant_term   )
      ) / (2 * quadratic_term)

      # two solutions, one of which is our input point
      UpperCAmelCase_    				=							x_minus if isclose(lowerCAmelCase__			,    lowerCAmelCase__   ) else x_plus
      UpperCAmelCase_    				=							point_y + outgoing_gradient * (next_x - point_x)

      return next_x, next_y, outgoing_gradient
def      a__			(   lowerCAmelCase__ = 1.4			,    lowerCAmelCase__ = -9.6   ):
      UpperCAmelCase_    				=							0
      UpperCAmelCase_    				=							first_x_coord
      UpperCAmelCase_    				=							first_y_coord
      UpperCAmelCase_    				=							(10.1 - point_y) / (0.0 - point_x)

      while not (-0.01 <= point_x <= 0.01 and point_y > 0):
            UpperCAmelCase_				,					UpperCAmelCase_				,					UpperCAmelCase_    				=							next_point(lowerCAmelCase__			,    lowerCAmelCase__			,    lowerCAmelCase__   )
            num_reflections += 1

      return num_reflections


if __name__ == "__main__":
  print(F"{solution() = }")









"""simple docstring"""





import colorsys

from PIL import Image  # type: ignore
def      a__			(   lowerCAmelCase__			,    lowerCAmelCase__			,    lowerCAmelCase__   ):
      UpperCAmelCase_    				=							x
      UpperCAmelCase_    				=							y
      for step in range(lowerCAmelCase__   ):  # noqa: B007
            UpperCAmelCase_    				=							a * a - b * b + x
            UpperCAmelCase_    				=							2 * a * b + y
            UpperCAmelCase_    				=							a_new

            # divergence happens for all complex number with an absolute value
            # greater than 4
            if a * a + b * b > 4:
                  break
      return step / (max_step - 1)
def      a__			(   lowerCAmelCase__   ):
      if distance == 1:
            return (0, 0, 0)
      else:
            return (255, 255, 255)
def      a__			(   lowerCAmelCase__   ):
      if distance == 1:
            return (0, 0, 0)
      else:
            return tuple(round(i * 255   ) for i in colorsys.hsv_to_rgb(lowerCAmelCase__			,    1			,    1   )   )
def      a__			(   lowerCAmelCase__ = 800			,    lowerCAmelCase__ = 600			,    lowerCAmelCase__ = -0.6			,    lowerCAmelCase__ = 0			,    lowerCAmelCase__ = 3.2			,    lowerCAmelCase__ = 50			,    lowerCAmelCase__ = True			,    ):
      UpperCAmelCase_    				=							Image.new("RGB"			,    (image_width, image_height)   )
      UpperCAmelCase_    				=							img.load()

      # loop through the image-coordinates
      for image_x in range(lowerCAmelCase__   ):
            for image_y in range(lowerCAmelCase__   ):
                  # determine the figure-coordinates based on the image-coordinates
                  UpperCAmelCase_    				=							figure_width / image_width * image_height
                  UpperCAmelCase_    				=							figure_center_x + (image_x / image_width - 0.5) * figure_width
                  UpperCAmelCase_    				=							figure_center_y + (image_y / image_height - 0.5) * figure_height

                  UpperCAmelCase_    				=							get_distance(lowerCAmelCase__			,    lowerCAmelCase__			,    lowerCAmelCase__   )

                  # color the corresponding pixel based on the selected coloring-function
                  if use_distance_color_coding:
                        UpperCAmelCase_    				=							get_color_coded_rgb(lowerCAmelCase__   )
                  else:
                        UpperCAmelCase_    				=							get_black_and_white_rgb(lowerCAmelCase__   )

      return img


if __name__ == "__main__":
  import doctest

  doctest.testmod()

  # colored version, full figure
  lowerCamelCase      =		get_image()

  # uncomment for colored version, different section, zoomed in
  # img = get_image(figure_center_x = -0.6, figure_center_y = -0.4,
  # figure_width = 0.8)

  # uncomment for black and white version, full figure
  # img = get_image(use_distance_color_coding = False)

  # uncomment to save the image
  # img.save("mandelbrot.png")

  img.show()




