Created
March 19, 2022 13:38
-
-
Save kmatch98/32df3bece4be2ce7c9ed983049b10617 to your computer and use it in GitHub Desktop.
Creates a Line using CircuitPython's vectorio Polygon given two endpoints and the line stroke width
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@staticmethod | |
def _angled_rectangle(points, palette, stroke=1): | |
x1, y1 = points[0] | |
x2, y2 = points[1] | |
if ((x2-x1) == 0): | |
xdiff1 = round(stroke/2) | |
xdiff2 = -round(stroke-xdiff1) | |
ydiff1 = 0 | |
ydiff2 = 0 | |
elif ((y2-y1) == 0): | |
xdiff1 = 0 | |
xdiff2 = 0 | |
ydiff1 = round(stroke/2) | |
ydiff2 = -round(stroke-ydiff1) | |
else: | |
c=math.sqrt( (x2-x1)**2 + (y2-y1)**2) | |
xdiff=stroke*(y2-y1)/c | |
xdiff1=(round(xdiff/2)) | |
xdiff2=-round(xdiff-xdiff1) | |
ydiff=stroke*(x2-x1)/c | |
ydiff1=round(ydiff/2) | |
ydiff2=-round(ydiff-ydiff1) | |
return vectorio.Polygon( | |
points = [(x1+xdiff1,y1+ydiff2), (x1+xdiff2, y1+ydiff1), (x2+xdiff2, y2+ydiff1), (x2+xdiff1, y2+ydiff2)], | |
pixel_shader=palette, | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment