def __init__(self, display, layout_json): self.json = layout_json if "view_type" not in layout_json: raise MissingTypeError if layout_json["view_type"] != "Polygon": raise IncorrectTypeError( "view_type '{}' does not match Layout Class 'Line'".format( layout_json["view_type"])) self._display = display if "attributes" in layout_json: _missing_attrs = [] for attribute in REQUIRED_ATTRIBUTES: if attribute not in layout_json['attributes']: _missing_attrs.append(attribute) if len(_missing_attrs) > 0: raise MissingRequiredAttributesError( "Missing required attributes: {}".format(_missing_attrs)) _outline = 0xFFFFFF if "outline" in layout_json["attributes"]: _outline = int(layout_json["attributes"]["outline"], 16) _points = [] if "points" in layout_json["attributes"]: for _point in layout_json["attributes"]["points"]: _points.append((self.keyword_compiler(_point[0]), self.keyword_compiler(_point[1]))) self.polygon = Polygon(_points, outline=_outline) self.view = self.polygon else: raise MissingAttributesError()
def main(): # Make the display context splash = displayio.Group(max_size=20) board.DISPLAY.show(splash) # Make a background color fill color_bitmap = displayio.Bitmap(320, 240, 1) color_palette = displayio.Palette(1) color_palette[0] = 0xFFFFFF bg_sprite = displayio.TileGrid(color_bitmap, x=0, y=0, pixel_shader=color_palette) splash.append(bg_sprite) ########################################################################## splash.append(Line(220, 130, 270, 210, 0xFF0000)) splash.append(Line(270, 210, 220, 210, 0xFF0000)) splash.append(Line(220, 210, 270, 130, 0xFF0000)) splash.append(Line(270, 130, 220, 130, 0xFF0000)) #Draw a blue star polygon = Polygon([(255, 40), (262, 62), (285, 62), (265, 76), (275, 100), (255, 84), (235, 100), (245, 76), (225, 62), (248, 62)], outline=0x0000FF) splash.append(polygon) triangle = Triangle(170, 50, 120, 140, 210, 160, fill=0x00FF00, outline=0xFF00FF) splash.append(triangle) rect = Rect(80, 20, 41, 41, fill=0x0) splash.append(rect) circle = Circle(100, 100, 20, fill=0x00FF00, outline=0xFF00FF) splash.append(circle) rect2 = Rect(50, 100, 61, 81, outline=0x0, stroke=3) splash.append(rect2) roundrect = RoundRect(10, 10, 61, 81, 10, fill=0x0, outline=0xFF00FF, stroke=6) splash.append(roundrect) sleep(4) running = False
########################################################################## splash.append(Line(220, 130, 270, 210, 0xFF0000)) splash.append(Line(270, 210, 220, 210, 0xFF0000)) splash.append(Line(220, 210, 270, 130, 0xFF0000)) splash.append(Line(270, 130, 220, 130, 0xFF0000)) # Draw a blue star polygon = Polygon( [ (255, 40), (262, 62), (285, 62), (265, 76), (275, 100), (255, 84), (235, 100), (245, 76), (225, 62), (248, 62), ], outline=0x0000FF, ) splash.append(polygon) triangle = Triangle(170, 50, 120, 140, 210, 160,
group.append(rect4) group.append(rect5) group.append(rect6) def redraw_frame(): # to adjust spacing at bottom later rect3.fill = color[2] rect4.fill = color[2] rect5.fill = color[2] rect6.fill = color[2] # draw the wings w polygon shapes wing_polys = [] wing_polys.append(Polygon([(3, 3), (9, 3), (9, 4), (4, 4)], outline=color[1])) wing_polys.append(Polygon([(5, 6), (9, 6), (9, 7), (6, 7)], outline=color[1])) wing_polys.append(Polygon([(7, 9), (9, 9), (9, 10), (8, 10)], outline=color[1])) wing_polys.append( Polygon([(54, 3), (60, 3), (59, 4), (54, 4)], outline=color[1])) wing_polys.append( Polygon([(54, 6), (58, 6), (57, 7), (54, 7)], outline=color[1])) wing_polys.append( Polygon([(54, 9), (56, 9), (55, 10), (54, 10)], outline=color[1])) for wing_poly in wing_polys: group.append(wing_poly) def redraw_wings(index): # to change colors
def draw_poly(): polygon = Polygon( [(80, 10), (160, 10), (220, 220), (20, 220)], outline=0x0, ) return polygon
def draw_clock(self, x, y, radius, hour, minute): grp = displayio.Group(max_size=20, x=x, y=y) # Draw the clock outline. grp.append( Circle(radius, radius, radius, outline=self.FOREGROUND_COLOR, stroke=int(radius / 30))) # Draw the tick marks. for i in range(12): dx = math.sin(i / 12 * 2 * math.pi) dy = math.cos(i / 12 * 2 * math.pi) grp.append( Line(int(radius + radius * 0.85 * dx), int(radius - radius * 0.85 * dy), int(radius + radius * 0.95 * dx), int(radius - radius * 0.95 * dy), self.FOREGROUND_COLOR)) # Draw the hour hand. hour_angle = (hour * 60 + minute) / 60 / 12 * 2 * math.pi hx = math.sin(hour_angle) hy = math.cos(hour_angle) grp.append( Polygon([ (int(radius + radius * 0.66 * hx), int(radius - radius * 0.66 * hy)), (int(radius + radius * 0.07 * hy), int(radius + radius * 0.07 * hx)), (int(radius - radius * 0.15 * hx), int(radius + radius * 0.15 * hy)), (int(radius - radius * 0.07 * hy), int(radius - radius * 0.07 * hx)), ], outline=self.FOREGROUND_COLOR)) # Draw the minute hand. minute_angle = minute / 60 * 2 * math.pi mx = math.sin(minute_angle) my = math.cos(minute_angle) grp.append( Triangle(int(radius + radius * 0.92 * mx), int(radius - radius * 0.92 * my), int(radius + radius * 0.05 * my), int(radius + radius * 0.05 * mx), int(radius - radius * 0.05 * my), int(radius - radius * 0.05 * mx), fill=self.FOREGROUND_COLOR)) grp.append( Triangle(int(radius - radius * 0.15 * mx), int(radius + radius * 0.15 * my), int(radius + radius * 0.05 * my), int(radius + radius * 0.05 * mx), int(radius - radius * 0.05 * my), int(radius - radius * 0.05 * mx), fill=self.FOREGROUND_COLOR)) # Draw the pin in the center. grp.append( Circle(radius, radius, int(radius * 0.03), fill=self.BACKGROUND_COLOR, outline=self.FOREGROUND_COLOR, stroke=1)) self._frame.append(grp)
########################################################################## splash.append(Line(220, 130, 270, 210, 0xFF0000)) splash.append(Line(270, 210, 220, 210, 0xFF0000)) splash.append(Line(220, 210, 270, 130, 0xFF0000)) splash.append(Line(270, 130, 220, 130, 0xFF0000)) # Draw a blue star polygon = Polygon( [ (155, 40), (162, 62), (185, 62), (165, 76), (175, 100), (155, 84), (135, 100), (145, 76), (125, 62), (148, 62), ], outline=0x0000FF, ) splash.append(polygon) triangle = Triangle(170, 50, 120, 140, 210, 160,