Skip to content

Commit

Permalink
Merge pull request #79 from JohnMarzulli/drawing_objects
Browse files Browse the repository at this point in the history
Merging based on 2020-03-07 test flight
  • Loading branch information
JohnMarzulli authored Mar 8, 2021
2 parents 44e0d61 + 5292023 commit 926eb7d
Show file tree
Hide file tree
Showing 6 changed files with 394 additions and 125 deletions.
290 changes: 290 additions & 0 deletions rendering/drawing.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,3 +249,293 @@ def segment(
framebuffer,
segments_to_draw,
color)


class HollowCircle:
"""
Holds the information to draw an hollow (unfilled) circle
"""

def __init__(
self,
center: list,
radius: int,
color: list,
width: int = 1,
is_antialiased: bool = True
) -> None:
"""
Create the circle to be drawn
Args:
center (list): The center of the circle (screen space)
radius (int): The radius of the circle.
color (list): The color of the circle.
width (int, optional): The width of the circle. Defaults to 1
is_antialiased (bool, optional): Should the circle be antialiased? Defaults to True.
"""

super().__init__()

self.__center__ = center
self.__radius__ = radius
self.__width__ = width
self.__color__ = color
self.__is_antialiased__ = is_antialiased

def render(
self,
framebuffer
) -> None:
"""
Draws the circle to the framebuffer
Args:
framebuffer: The framebuffer to draw to.
"""
circle(
framebuffer,
self.__color__,
self.__center__,
self.__radius__,
self.__width__,
self.__is_antialiased__)


class FilledCircle:
"""
Holds the information to draw an solid (filled) circle
"""

def __init__(
self,
center: list,
radius: int,
color: list,
is_antialiased: bool = True
) -> None:
"""
Create the circle to be drawn
Args:
center (list): The center of the circle (screen space)
radius (int): The radius of the circle.
color (list): The color of the circle.
is_antialiased (bool, optional): Should the circle be antialiased? Defaults to True.
"""

super().__init__()

self.__center__ = center
self.__radius__ = radius
self.__color__ = color
self.__is_antialiased__ = is_antialiased

def render(
self,
framebuffer
) -> None:
"""
Draws the circle to the framebuffer
Args:
framebuffer: The framebuffer to draw to.
"""

filled_circle(
framebuffer,
self.__color__,
self.__center__,
self.__radius__,
self.__is_antialiased__)


class Segment:
"""
Holds the information for a line segment.
"""

def __init__(
self,
start: list,
end: list,
color: list,
width: int = 1,
is_antialiased: bool = True
) -> None:
"""
Create the segment to be drawn.
Args:
start (list): The starting position of the segment (screen space)
end (list): The ending position of the segment (screen space)
color (list): The color of the segment
width (int, optional): The width of the segment. Defaults to 1.
is_antialiased (bool, optional): Is this antialiased? Defaults to True.
"""
super().__init__()

self.__start__ = start
self.__end__ = end
self.__color__ = color
self.__width__ = width
self.__is_anti_aliased__ = is_antialiased

def render(
self,
framebuffer
) -> None:
"""
Renders the segment.
Args:
framebuffer: The framebuffer to draw to.
"""
segment(
framebuffer,
self.__color__,
self.__start__,
self.__end__,
self.__width__,
self.__is_anti_aliased__)


class Segments:
"""
Holds the information for a set of connected line segment.
These segments do not connect the final point back to the start.
"""

def __init__(
self,
points: list,
color: list,
width: int = 1,
is_antialiased: bool = True
) -> None:
"""
Create the segments to be drawn.
Args:
points (list): The starting to ending points of the segment sets (screen space)
color (list): The color of the segment
width (int, optional): The width of the segment. Defaults to 1.
is_antialiased (bool, optional): Is this antialiased? Defaults to True.
"""

super().__init__()

self.__points__ = points
self.__color__ = color
self.__width__ = width
self.__is_anti_aliased__ = is_antialiased

def render(
self,
framebuffer
) -> None:
"""
Render the segments to the framebuffer
Args:
framebuffer: The framebuffer to draw to.
"""

segments(
framebuffer,
self.__color__,
False,
self.__points__,
self.__width__,
self.__is_anti_aliased__)


class HollowPolygon:
"""
Stores the info for a hollow (unfilled) polylon.
"""

def __init__(
self,
points: list,
color: list,
width: int,
is_antialiased: bool = True
) -> None:
"""
Create the polygon to be drawn. This is unfilled
Args:
points (list): The points of the segment that define the polygon (screen space)
color (list): The color of the polygon's outline
width (int, optional): The width of the polygon's outline. Defaults to 1.
is_antialiased (bool, optional): Is this antialiased? Defaults to True.
"""

super().__init__()

self.__points__ = points
self.__color__ = color
self.__width__ = width
self.__is_anti_aliased__ = is_antialiased

def render(
self,
framebuffer
) -> None:
"""
Renders the polygon.
Args:
framebuffer: The framebuffer to draw to.
"""
segments(
framebuffer,
self.__color__,
True,
self.__points__,
self.__width__,
self.__is_anti_aliased__)


class FilledPolygon:
"""
Stores the info for a solid (filled) polylon.
"""

def __init__(
self,
points: list,
color: list,
is_antialiased: bool = True
) -> None:
"""
Create the polygon to be drawn. This is solid/filled
Args:
points (list): The points of the segment that define the polygon (screen space)
color (list): The color of the polygon
is_antialiased (bool, optional): Is this antialiased? Defaults to True.
"""

super().__init__()

self.__points__ = points
self.__color__ = color
self.__is_anti_aliased__ = is_antialiased

def render(
self,
framebuffer
) -> None:
"""
Renders the polygon.
Args:
framebuffer: The framebuffer to draw to.
"""
polygon(
framebuffer,
self.__color__,
self.__points__,
self.__is_anti_aliased__)
Loading

0 comments on commit 926eb7d

Please sign in to comment.