1 # SPDX-FileCopyrightText: 2020 Melissa LeBlanc-Williams for Adafruit Industries
 
   3 # SPDX-License-Identifier: MIT
 
   7 ================================================================================
 
   9 vectorio Circle for Blinka
 
  11 **Software and Dependencies:**
 
  14   https://github.com/adafruit/Adafruit_Blinka/releases
 
  16 * Author(s): Melissa LeBlanc-Williams
 
  20 from typing import Union
 
  21 from displayio._colorconverter import ColorConverter
 
  22 from displayio._palette import Palette
 
  23 from displayio._area import Area
 
  24 from ._vectorshape import _VectorShape
 
  26 __version__ = "0.0.0+auto.0"
 
  27 __repo__ = "https://github.com/adafruit/Adafruit_Blinka_displayio.git"
 
  30 class Circle(_VectorShape):
 
  36         pixel_shader: Union[ColorConverter, Palette],
 
  41         """Circle is positioned on screen by its center point.
 
  43         :param Union[~displayio.ColorConverter,~displayio.Palette] pixel_shader:
 
  44             The pixel shader that produces colors from values
 
  45         :param int radius: The radius of the circle in pixels
 
  46         :param int x: Initial x position of the axis.
 
  47         :param int y: Initial y position of the axis.
 
  48         :param int color_index: Initial color_index to use when selecting color from the palette.
 
  52         super().__init__(pixel_shader, x, y)
 
  56     def radius(self) -> int:
 
  57         """The radius of the circle in pixels"""
 
  61     def radius(self, value: int) -> None:
 
  63             raise ValueError("radius must be >= 1")
 
  64         self._radius = abs(value)
 
  65         self._shape_set_dirty()
 
  68     def color_index(self) -> int:
 
  69         """The color_index of the circle as 0 based index of the palette."""
 
  70         return self._color_index - 1
 
  73     def color_index(self, value: int) -> None:
 
  74         self._color_index = abs(value + 1)
 
  75         self._shape_set_dirty()
 
  77     def _get_pixel(self, x: int, y: int) -> int:
 
  80         if x + y <= self._radius:
 
  81             return self._color_index
 
  82         if x > self._radius or y > self._radius:
 
  84         pythagoras_smaller_than_radius = x * x + y * y <= self._radius * self._radius
 
  85         return self._color_index if pythagoras_smaller_than_radius else 0
 
  87     def _get_area(self, out_area: Area) -> None:
 
  88         out_area.x1 = -1 * self._radius - 1
 
  89         out_area.y1 = -1 * self._radius - 1
 
  90         out_area.x2 = self._radius + 1
 
  91         out_area.y2 = self._radius + 1