def empty_circle(radius, x, y, outer_palette, inner_palette, thickness = 2): # radius = radius # x, y = location of circle in group # outer_palette = determines the color of boundary and outer fill # inner_pallete = determines fill color; the first value MUST BE # TRANSPARENT circle_gp = displayio.Group(max_size = 2) circle_gp.append( vt.VectorShape( shape = vt.Circle(radius), pixel_shader = outer_palette, x = x, y = y ) ) circle_gp.append( vt.VectorShape( shape = vt.Circle(radius-thickness), pixel_shader = inner_palette, x = x, y = y ) ) return circle_gp
def append_wobbly_star_shape(group: displayio.Group, color): # Make a wobbly star. The returned function wobbles its points a little. wobbly_star_points = [ (8, 50), (33, 0), (58, 50), (0, 20), (66, 20), ] star_center_x = 170 - 25 star_center_y = 120 - 33 wobbly_star_polygon = vectorio.Polygon(points=wobbly_star_points) wobbly_star_shape = vectorio.VectorShape(shape=wobbly_star_polygon, pixel_shader=monochrome(color), x=star_center_x, y=star_center_y) group.append(wobbly_star_shape) def make_star_wobble(): tremble = 4 shake = 3 trembling_points = [(random.randrange(x - tremble, x + tremble), random.randrange(y - tremble, y + tremble)) for x, y in wobbly_star_points] wobbly_star_polygon.points = trembling_points wobbly_star_shape.x = random.randrange(star_center_x - shake, star_center_x + shake) wobbly_star_shape.y = random.randrange(star_center_y - shake, star_center_y + shake) return make_star_wobble
def __init__(self, output): self.output = output self.palette = displayio.Palette(color_count=2) self.palette[0] = 0x000000 self.palette[1] = 0xFFFFFF self.rect = vectorio.VectorShape( shape=vectorio.Rectangle(100, 100), pixel_shader=self.palette, ) self.gp = displayio.Group(max_size=1) self.gp.append(self.rect)
def _draw_pointers(self, x: int, y: int) -> None: self._pointer = vectorio.Circle(self._pointer_radius) self._circle_palette = displayio.Palette(2) self._circle_palette.make_transparent(0) self._circle_palette[1] = self._pointer_color self._pointer_vector_shape = vectorio.VectorShape( shape=self._pointer, pixel_shader=self._circle_palette, x=x, y=y, ) self.append(self._pointer_vector_shape)
def _create_needle(self): # Create the needle self._needle_palette = displayio.Palette(2) self._needle_palette.make_transparent(0) self._needle_palette[1] = self._needle_color self._needle = vectorio.Polygon( points=[(100, 100), (100, 50), (50, 50), (50, 100)] ) self._needle_vector_shape = vectorio.VectorShape( shape=self._needle, pixel_shader=self._needle_palette, x=0, y=0, ) # if clipped, adjust the needle width up according to the clip amount if ( (self._sweep_angle < 180) and (self._clip_needle) and (self._trim_line is not None) ): # calculate the line where the needle is most visible max_visible_angle = (2 * math.pi / 360) * ( self._start_angle + self._sweep_angle / 2 ) while True: if max_visible_angle > math.pi: max_visible_angle -= 2 * math.pi elif max_visible_angle < -math.pi: max_visible_angle += 2 * math.pi else: break temp_x = self._dial_center[0] + self._dial_radius * math.sin( max_visible_angle ) temp_y = self._dial_center[1] - self._dial_radius * math.cos( max_visible_angle ) temp_line = [self._dial_center, (temp_x, temp_y)] x, y = _line_intersection(temp_line, self._trim_line) needle_length_showing = math.sqrt((x - temp_x) ** 2 + (y - temp_y) ** 2) self._needle_width = round( self._needle_width_requested * self._dial_radius / needle_length_showing ) else: self._needle_width = self._needle_width_requested
def rectangle_helper( x0: int, y0: int, height: int, width: int, bitmap, color_index: int, palette, bitmaptool: bool = True, ) -> None: """rectangle_helper function Draws a rectangle to the bitmap given using ``bitmapstools.bitmap`` or ``vectorio.rectangle`` functions :param int x0: rectangle lower corner x position :param int y0: rectangle lower corner y position :param int width: rectangle upper corner x position :param int height: rectangle upper corner y position :param int color_index: palette color index to be used :param palette: palette object to be used to draw the rectangle :param bitmap: bitmap for the rectangle to be drawn :param bool bitmaptool: uses :py:func:`~bitmaptools.draw_line` to draw the rectanlge. when `False` uses :py:func:`~vectorio.Rectangle` :return: None :rtype: None ┌───────────────────────┐ │ │ │ │ (x0,y0) └───────────────────────┘ """ if bitmaptool: bitmaptools.fill_region(bitmap, x0, y0, x0 + width, y0 + height, color_index) else: rect = vectorio.Rectangle(width, height) vectorio.VectorShape( shape=rect, pixel_shader=palette, x=x0, y=y0, )
def append_randart_shape(group: displayio.Group, color): # Make a random polygon to sit on the left side of the screen. # We'll update its points every now and then with the returned function. random_polygon = vectorio.Polygon(points=[(random.randrange(0, 100), random.randrange(0, 240)) for _ in range(40)]) random_shape = vectorio.VectorShape( shape=random_polygon, pixel_shader=monochrome(color), ) group.append(random_shape) def new_randart(): random_polygon.points = [(random.randrange(0, 100), random.randrange(0, 240)) for _ in range(40)] return new_randart
def append_vectorio_shape(group: displayio.Group, color): # Making fonts with vector points is a pain but the memory benefits are pretty nice. # Also you can rotate points for spinny text if you want! v_polygon = vectorio.Polygon(points=[ (0, 0), (10, 0), (18, 24), (26, 0), (36, 0), (22, 34), (10, 34), ]) v_shape = vectorio.VectorShape(shape=v_polygon, pixel_shader=monochrome(color), x=160, y=16) group.append(v_shape)
def run(): RED = 0xff0000 GREEN = 0x00ff00 VIOLET = 0xEE82EE BACKGROUND = 0xA0A000 # Initialize the hardware display = get_display() group = displayio.Group(max_size=10) # Assemble the displaygroup (only using 1) new_randart_fn = append_randart_shape(group, color=BACKGROUND) wobble_star_fn = append_wobbly_star_shape(group, color=RED) revolve_circle_fn, resize_circle_fn = append_circle_shape(group, color=GREEN) # Add a thing to revolve the circle under group.append( vectorio.VectorShape( shape=vectorio.Polygon(points=[(0, 0), (18, 32), (-10, 20)]), pixel_shader=monochrome(0xA0B0C0), x=110, y=65)) append_vectorio_shape(group, color=VIOLET) # Schedule the animations new_randart_fn = rate_limited(hz=1 / 5)(new_randart_fn) wobble_star_fn = rate_limited(hz=6)(wobble_star_fn) resize_circle_fn = rate_limited(hz=7)(resize_circle_fn) revolve_circle_fn = rate_limited(hz=20)(revolve_circle_fn) # And turn on the display display.brightness = 1 display.show(group) # Now drive the scheduled animations forever while True: new_randart_fn() wobble_star_fn() resize_circle_fn() revolve_circle_fn()
def append_circle_shape(group: displayio.Group, color): # Make a circle that will revolve around the star while changing size min_circle_radius = 5 max_circle_radius = 20 circle_axis = 170, 120 circle_revolution_radius = 60 circle = vectorio.Circle(radius=max_circle_radius) circle_shape = vectorio.VectorShape(shape=circle, pixel_shader=monochrome(color), x=circle_axis[0], y=circle_axis[1]) group.append(circle_shape) radians_in_circle = 2 * math.pi def revolve_circle(): seconds_per_revolution = 8 revolution_ratio = (time.monotonic() % seconds_per_revolution) / seconds_per_revolution revolution_radians = revolution_ratio * radians_in_circle s = math.sin(revolution_radians) c = math.cos(revolution_radians) x = s * circle_revolution_radius + circle_axis[0] y = c * circle_revolution_radius + circle_axis[1] circle_shape.x = round(x) circle_shape.y = round(y) def resize_circle(): seconds_per_size_cycle = 13 size_ratio = abs( int(time.monotonic() % (2 * seconds_per_size_cycle) / seconds_per_size_cycle) - time.monotonic() % seconds_per_size_cycle / seconds_per_size_cycle) new_radius = min_circle_radius + size_ratio * (max_circle_radius - min_circle_radius) circle.radius = int(new_radius) return revolve_circle, resize_circle
palette1[1] = 0xFF0000 # red palette1[0] = 0x000000 palette2.make_transparent(0) palette2[1] = 0x00FF00 # green palette2[0] = 0x000000 palette3.make_transparent(0) palette3[1] = 0x0000FF # blue palette3[0] = 0x000000 palette4.make_transparent(0) palette4[1] = 0x00FFFF # cyan palette4[0] = 0x000000 shape1 = vectorio.VectorShape(shape=rect1, pixel_shader=palette1) shape2 = vectorio.VectorShape(shape=rect2, pixel_shader=palette2) shape3 = vectorio.VectorShape(shape=rect3, pixel_shader=palette3) shape4 = vectorio.VectorShape(shape=rect4, pixel_shader=palette4) main_group = displayio.Group(max_size=4) group1 = displayio.Group(max_size=1) group2 = displayio.Group(max_size=1) group3 = displayio.Group(max_size=1) group4 = displayio.Group(max_size=1) group1.append(shape1) group1.x = 50 group1.y = 20 group2.append(shape2) group2.x = 20
print('brightness:', display.brightness) print('auto_brightness:', display.auto_brightness) print('bus_object:', display.bus) # show_display_info(display) circle_palette = displayio.Palette(color_count=2) circle_palette[0] = 0xffffff circle_palette[1] = 0xff0000 circle_palette.make_transparent(0) RADIUS = 30 circle = vectorio.VectorShape(shape=vectorio.Circle(RADIUS), pixel_shader=circle_palette, x=120, y=120) rect_palette = displayio.Palette(color_count=2) rect_palette[0] = 0xffffff rect_palette[1] = 0x00ff00 rect_palette.make_transparent(0) HEIGHT = 120 WIDTH = 60 rectangle = vectorio.VectorShape(shape=vectorio.Rectangle(WIDTH, HEIGHT), pixel_shader=rect_palette, x=120, y=120) poly_palette = displayio.Palette(color_count=2)