Skip to content

Instantly share code, notes, and snippets.

@kmatch98
Created March 19, 2022 13:38
Show Gist options
  • Save kmatch98/32df3bece4be2ce7c9ed983049b10617 to your computer and use it in GitHub Desktop.
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
@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