Пример #1
0
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
Пример #2
0
def draw_spirit():
    design.append(draw_background())
    design.append(draw_poly())
    design.append(draw_poly_using_triangle())

    design.append(draw_sprit_rect(120, 90, 40, 120))
    design.append(Line(100, 110, 140, 110, 0x0))
    design.append(Line(100, 70, 140, 70, 0x0))

    design.append(draw_sprit_rect(120, 180, 120, 40))
    design.append(Line(100, 160, 100, 200, 0x0))
    design.append(Line(140, 160, 140, 200, 0x0))

    draw_bubbles()
    design.append(bubble_groupx)
    design.append(bubble_groupy)
Пример #3
0
 def line(self, x0, y0, x1, y1, col, index=None):
   """ Draw a line
   """
   c = self._pal[min(col, _MAX_COLORS-1)]
   l = Line(x0, y0, x1, y1, c)
   if index:
     self._group.insert(index, l)
   else:
     self._group.append(l)
   return l
Пример #4
0
 def MoveCursor(display, cursor):
     if time.monotonic() >= mNextSensorRead:
         x0 = getCursorX(mPot0)
         y0 = getCursorY(mPot1)
         z = getZoomLevel(mZoomPot)
         newHeight = int(z / 2)
         newWidth = int((z * WIDTH / HEIGHT) / 2)
         left, right = x0 - newWidth, x0 + newWidth
         top, bottom = y0 - newHeight, y0 + newHeight
         cursor.pop()
         cursor.pop()
         cursor.pop()
         cursor.pop()
         cursor.append(Line(left, top, right, top, 0X000000))  # Top Line
         cursor.append(Line(left, top, left, bottom, 0X000000))  # Left Line
         cursor.append(Line(right, top, right, bottom,
                            0X000000))  # Right Line
         cursor.append(Line(left, bottom, right, bottom,
                            0X000000))  # Bottom Line
         display.refresh()
         mNextSensorRead = time.monotonic() + 0.1
def on_iso(client, feed_id, payload):
    timezone = adafruit_datetime.timezone.utc
    timezone._offset = adafruit_datetime.timedelta(seconds=UTC_OFFSET * 3600)
    datetime = adafruit_datetime.datetime.fromisoformat(
        payload[:-1]).replace(tzinfo=timezone)
    local_datetime = datetime.tzinfo.fromutc(datetime)
    print(local_datetime)
    dt_hour = local_datetime.hour
    dt_minute = local_datetime.minute
    if not local_datetime.second % 10:
        theta = (dt_hour / 6 + dt_minute / 360) - 0.5
        y_1 = int((72 * math.sin(math.pi * theta)) + 128)
        x_1 = int((72 * math.cos(math.pi * theta)) + 114)
        new_hour = Line(114, 128, x_1, y_1, 0xFFFFFF)
        splash[-3] = new_hour

        theta = (dt_minute / 30) - 0.5
        y_1 = int((96 * math.sin(math.pi * theta)) + 128)
        x_1 = int((96 * math.cos(math.pi * theta)) + 114)
        dt_minute = Line(114, 128, x_1, y_1, 0xFFFFFF)
        splash[-2] = dt_minute

    theta = (local_datetime.second / 30) - 0.5
    y_1 = int((96 * math.sin(math.pi * theta)) + 128)
    x_1 = int((96 * math.cos(math.pi * theta)) + 114)
    new_second = Line(114, 128, x_1, y_1, 0x808080)
    splash[-1] = new_second

    day = days[local_datetime.weekday()]
    alarm_hour, alarm_minute = TIMES[day].split(":")
    if dt_hour == int(alarm_hour):
        if (dt_minute == int(alarm_minute) and ENABLED[day] and not ALARM
                and WAIT < time.monotonic()):
            mqtt_client.publish(
                f"{secrets['aio_username']}/feeds/alarm-clock.alarm", "True")
            get("alarm-clock.alarm")
    gc.collect()
Пример #6
0
def display_status(screen_h, status_text, font):
    """Show the status string at the bottom."""

    line_header = Line(0, 105, 296, 105, color=e_dk_grey)
    screen_h.append(line_header)

    out_label = label.Label(
        font,
        x=5,
        y=115,
        color=e_black,
        text=status_text + text_pad,
        line_spacing=0.0,
        background_color=e_white,
    )
    screen_h.append(out_label)
Пример #7
0
    def __init__(self, display, layout_json):
        self.json = layout_json
        if "view_type" not in layout_json:
            raise MissingTypeError
        if layout_json["view_type"] != "Line":
            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))

            _color = 0xFFFFFF
            if "color" in layout_json["attributes"]:
                _color = int(layout_json["attributes"]["color"], 16)

            _x0 = 0
            if "x0" in layout_json["attributes"]:
                _x0 = self.keyword_compiler(layout_json["attributes"]["x0"])

            _x1 = 0
            if "x1" in layout_json["attributes"]:
                _x1 = self.keyword_compiler(layout_json["attributes"]["x1"])

            _y0 = 0
            if "y0" in layout_json["attributes"]:
                _y0 = self.keyword_compiler(layout_json["attributes"]["y0"])

            _y1 = 0
            if "y1" in layout_json["attributes"]:
                _y1 = self.keyword_compiler(layout_json["attributes"]["y1"])

            self.line = Line(_x0, _y0, _x1, _y1, color=_color)
            self.view = self.line
        else:
            raise MissingAttributesError()
Пример #8
0
def update_display():
    # clear out existing icons
    while len(storm_icons):
        _ = storm_icons.pop()

    # get latest storm data
    try:
        storm_data = pyportal.fetch()
    except RuntimeError:
        return
    print("Number of storms:", len(storm_data))

    # parse the storm data
    for storm in storm_data:
        # don't exceed max
        if len(storm_icons) >= MAX_STORMS:
            continue
        # get lat/lon
        lat = storm["latitudeNumeric"]
        lon = storm["longitudeNumeric"]
        # check if on map
        if (not LAT_RANGE[0] >= lat >= LAT_RANGE[1]
                or not LON_RANGE[0] <= lon <= LON_RANGE[1]):
            continue
        # OK, let's make a group for all the graphics
        storm_gfx = displayio.Group(max_size=3)  # icon + label + arrow
        # convert to sreen coords
        x = int(
            map_range(lon, LON_RANGE[0], LON_RANGE[1], 0,
                      board.DISPLAY.width - 1))
        y = math.radians(lat)
        y = math.tan(math.pi / 4 + y / 2)
        y = math.log(y)
        y = (VIRTUAL_WIDTH * y) / (2 * math.pi)
        y = VIRTUAL_HEIGHT / 2 - y
        y = int(y - Y_OFFSET)
        # icon type
        if storm["classification"] in STORM_CLASS:
            storm_type = STORM_CLASS.index(storm["classification"])
        else:
            storm_type = 0
        # create storm icon
        icon = displayio.TileGrid(
            icons_bmp,
            pixel_shader=icons_pal,
            width=1,
            height=1,
            tile_width=16,
            tile_height=16,
            default_tile=storm_type,
            x=x - 8,
            y=y - 8,
        )
        # add storm icon
        storm_gfx.append(icon)
        # add a label
        name = Label(
            terminalio.FONT,
            text=storm["name"],
            color=NAME_COLOR,
            background_color=NAME_BG_COLOR,
        )
        name.anchor_point = (0.0, 1.0)
        name.anchored_position = (x + 8, y - 8)
        storm_gfx.append(name)
        # add direction arrow
        angle = math.radians(storm["movementDir"])
        xd = x + int(ARROW_LENGTH * math.sin(angle))
        yd = y - int(ARROW_LENGTH * math.cos(angle))
        arrow = Line(x, y, xd, yd, color=ARROW_COLOR)
        storm_gfx.append(arrow)
        # add the storm graphics
        storm_icons.append(storm_gfx)
        # update time
        info_update.text = storm["lastUpdate"]
        # debug
        print("{} @ {},{}".format(storm["name"], storm["latitudeNumeric"],
                                  storm["longitudeNumeric"]))

    # no storms? at least say something
    if not len(storm_icons):
        print("No storms in map area.")
        storm_icons.append(
            Label(
                terminalio.FONT,
                scale=4,
                x=50,
                y=110,
                text="NO STORMS\n IN AREA",
                color=NAME_COLOR,
                background_color=NAME_BG_COLOR,
            ))
# 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),
Пример #10
0
    def _plotline(self, x_1, last_value, x_2, value, y_bottom, y_top):

        y_2 = int(self.height * (y_top - value) / (y_top - y_bottom))
        y_1 = int(self.height * (y_top - last_value) / (y_top - y_bottom))
        self.append(Line(x_1, y_1, x_2, y_2, self.color))  # plot the line
Пример #11
0
            color=0x000000,
            text=event_name,
            line_spacing=0.65,
        )
        magtag.splash.append(label_event_desc)


# Create a new MagTag object
magtag = MagTag()
r = rtc.RTC()

# DisplayIO Setup
magtag.set_background(0xFFFFFF)

# Add the header
line_header = Line(0, 30, 320, 30, color=0x000000)
magtag.splash.append(line_header)

font_h1 = bitmap_font.load_font("fonts/Arial-18.pcf")
label_header = label.Label(font_h1, x=5, y=15, color=0x000000, max_glyphs=30)
magtag.splash.append(label_header)

# Set up calendar event fonts
font_event = bitmap_font.load_font("fonts/Arial-12.pcf")

if not google_auth.refresh_access_token():
    raise RuntimeError(
        "Unable to refresh access token - has the token been revoked?")
access_token_obtained = int(time.monotonic())

while True:
label2 = label.Label(font,
                     text="Cool light",
                     anchor_point=(0, 0.5),
                     anchored_position=(235, 170))
splash.append(label2)

menu = [label1, label2]

# Set up clock
circle = Circle(114, 128, 96, outline=0xFFFFFF)
splash.append(circle)

circle = Circle(114, 128, 3, outline=0xFFFFFF, fill=0xFFFFFF)
splash.append(circle)

twelve = Line(114, 32, 114, 16, 0xFFFFFF)
splash.append(twelve)

for i in range(-2, 9):
    y0 = int((96 * math.sin(math.pi * (i / 6))) + 128)
    x0 = int((96 * math.cos(math.pi * (i / 6))) + 114)
    y1 = int((108 * math.sin(math.pi * (i / 6))) + 128)
    x1 = int((108 * math.cos(math.pi * (i / 6))) + 114)
    hour = Line(x0, y0, x1, y1, 0xFFFFFF)
    splash.append(hour)

hour = Line(114, 128, 114, 128, 0xFFFFFF)
splash.append(hour)

minute = Line(114, 128, 114, 128, 0xFFFFFF)
splash.append(minute)
Пример #13
0
# Make the display context
splash = displayio.Group(max_size=20)
display.show(splash)

# Make a background color fill
color_bitmap = displayio.Bitmap(display.width, display.height, 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(5, 74, 10, 110, 0x000000))
splash.append(Line(15, 74, 20, 110, 0x000000))
splash.append(Line(25, 74, 30, 110, 0x000000))
splash.append(Line(35, 74, 40, 110, 0x000000))

# Draw star
polygon = Polygon(
    [
        (255, 40),
        (262, 62),
        (285, 62),
        (265, 76),
        (275, 100),
        (255, 84),
        (235, 100),
        (245, 76),
Пример #14
0
my_group = displayio.Group(max_size=20)

my_group.append(sparkline1)
my_group.append(text_label1a)
my_group.append(text_label1b)
my_group.append(bounding_rectangle)

total_ticks = 10

for i in range(total_ticks + 1):
    x_start = sparkline1.x - 5
    x_end = sparkline1.x
    y_both = int(round(sparkline1.y + (i * (chart_height) / (total_ticks))))
    if y_both > sparkline1.y + chart_height - 1:
        y_both = sparkline1.y + chart_height - 1
    my_group.append(Line(x_start, y_both, x_end, y_both, color=line_color))

# Set the display to show my_group that contains the sparkline and other graphics
display.show(my_group)

# Start the main loop
while True:

    # Turn off auto_refresh to prevent partial updates of the screen during updates
    # of the sparkline drawing
    display.auto_refresh = False

    # add_value: add a new value to a sparkline
    # Note: The y-range for mySparkline1 is set to 0 to 10, so all these random
    # values (between 0 and 10) will fit within the visible range of this sparkline
    sparkline1.add_value(random.uniform(0, 10))
Пример #15
0
                                 chip_select=tft_cs,
                                 reset=tft_rst)

#构建显示屏对象,默认自动刷新
display = ST7735R(display_bus, width=128, height=160, rotation=0, bgr=True)

#设置显示元素个数,最大20个
splash = displayio.Group(max_size=20, scale=1)
display.show(splash)

########################################
# 添加元素,添加后默认自动显示
########################################

#画线
splash.append(Line(5, 10, 40, 10, 0xFFFFFF))

#画矩形
rect = Rect(5, 20, 30, 20, outline=0xFFFFFF, fill=0x0)
splash.append(rect)

#画圆
circle = Circle(20, 60, 10, fill=0x0, outline=0xFFFFFF)
splash.append(circle)

# 字符显示,使用Label对象
text_area = label.Label(terminalio.FONT,
                        text="Hello 01Studio!",
                        color=0xFFFFFF,
                        x=10,
                        y=100)
            color=0x000000,
            text=event_name,
            line_spacing=0.65,
        )
        magtag.splash.append(label_event_desc)


# Create a new MagTag object
magtag = MagTag()
r = rtc.RTC()

# DisplayIO Setup
magtag.set_background(0xFFFFFF)

# Add the header
line_header = Line(0, 25, 320, 25, color=0x000000)
magtag.splash.append(line_header)

font_h1 = bitmap_font.load_font("fonts/Arial-Bold-18.pcf")
font_h1.load_glyphs(
    b"abcdefghjiklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-,. ")
label_header = label.Label(font_h1,
                           x=(board.DISPLAY.width // 5) + 1,
                           y=10,
                           color=0x000000,
                           max_glyphs=13)
magtag.splash.append(label_header)

# Set up calendar event fonts
font_event = bitmap_font.load_font("fonts/Arial-12.pcf")
font_event.load_glyphs(
Пример #17
0
    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)
Пример #18
0
def main():
    import board  # Pi Pico Board GPIO pins
    import displayio  # Python's multi layer graphics
    import adafruit_displayio_ssd1306  # OLED Driver
    import busio  # Provides I2C support
    import time
    from adafruit_display_shapes.line import Line
    #from adafruit_display_shapes.circle import Circle
    from adafruit_display_shapes.rect import Rect
    import math
    from analogio import AnalogIn
    from digitalio import DigitalInOut, Direction, Pull
    from hari.mandelbrot import mandelbrot, MAX_ITER

    WIDTH, HEIGHT = 128, 64  #32  # Change to 64 if needed
    width2 = int(WIDTH / 2)
    height2 = int(HEIGHT / 2)

    realStart, realEnd = -2 - .8, 2
    imStart, imEnd = -1, 1

    displayio.release_displays()  # Just to be safe

    def SetupDisplay():
        # So we can communicate with our OLED via I2C
        i2c = busio.I2C(scl=board.GP3, sda=board.GP2)
        #while not i2c.try_lock():
        #    pass
        #print("i2c address is = ",i2c.scan())

        # How displayio talks to physical screen
        display_bus = displayio.I2CDisplay(
            i2c, device_address=60)  # was 0x3A, reset=oled_reset)

        # display represents the physical screen
        display = adafruit_displayio_ssd1306.SSD1306(display_bus,
                                                     width=WIDTH,
                                                     height=HEIGHT,
                                                     auto_refresh=False)

        # Group is a list of TileGrids that display would render on physical screen
        group = displayio.Group(max_size=2)

        display.show(group)

        return (display, group)

    def SetupFullScreenTileGrid():
        #-- Create a bitmap --
        bitmap = displayio.Bitmap(WIDTH, HEIGHT, 2)

        #-- Create Palette --
        palette = displayio.Palette(2)
        palette[0] = 0
        palette[1] = 0xFFFFFF

        #-- Create TileGrid --
        tileGrid = displayio.TileGrid(bitmap, pixel_shader=palette)
        return bitmap, tileGrid

    def SetupCursorTileGrid():
        #-- Create a bitmap --
        bitmap = displayio.Bitmap(WIDTH, HEIGHT, 2)

        #-- Create Palette --
        palette = displayio.Palette(2)
        palette[0] = 0
        palette[1] = 0xFFFFFF

        #-- Create TileGrid --
        tileGrid = displayio.TileGrid(bitmap, pixel_shader=palette)
        return bitmap, tileGrid

    def SetupAnalog():
        pot0 = AnalogIn(board.A0)
        pot1 = AnalogIn(board.A1)
        zoomPot = AnalogIn(board.A2)
        return (pot0, pot1, zoomPot)

    def SetupButtons():
        global buttonZoomIn, buttonZoomOut, buttonCenter
        buttonZoomIn = DigitalInOut(board.GP13)
        buttonZoomIn.direction = Direction.INPUT
        buttonZoomIn.pull = Pull.UP

        buttonZoomOut = DigitalInOut(board.GP14)
        buttonZoomOut.direction = Direction.INPUT
        buttonZoomOut.pull = Pull.UP

        buttonCenter = DigitalInOut(board.GP15)
        buttonCenter.direction = Direction.INPUT
        buttonCenter.pull = Pull.UP

    def _map(x, in_min, in_max, out_min, out_max):
        return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min

    def getCursorX(pot):
        return int(_map(pot.value, 0, 65520, 0, WIDTH))

    def getCursorY(pot):
        return int(_map(pot.value, 0, 65520, 0, HEIGHT))

    def getZoomLevel(pot):
        return int(_map(pot.value, 0, 65520, 0, HEIGHT))

    def MoveCursor(display, cursor):
        if time.monotonic() >= mNextSensorRead:
            x0 = getCursorX(mPot0)
            y0 = getCursorY(mPot1)
            z = getZoomLevel(mZoomPot)
            newHeight = int(z / 2)
            newWidth = int((z * WIDTH / HEIGHT) / 2)
            left, right = x0 - newWidth, x0 + newWidth
            top, bottom = y0 - newHeight, y0 + newHeight
            cursor.pop()
            cursor.pop()
            cursor.pop()
            cursor.pop()
            cursor.append(Line(left, top, right, top, 0X000000))  # Top Line
            cursor.append(Line(left, top, left, bottom, 0X000000))  # Left Line
            cursor.append(Line(right, top, right, bottom,
                               0X000000))  # Right Line
            cursor.append(Line(left, bottom, right, bottom,
                               0X000000))  # Bottom Line
            display.refresh()
            mNextSensorRead = time.monotonic() + 0.1

    def ZoomIn(display, bitmap):
        if (buttonZoomIn.value == False):
            print("BEFORE ZOOM IN:", realStart, realEnd, imStart, imEnd)
            x0 = getCursorX(mPot0)
            y0 = getCursorY(mPot1)
            z = getZoomLevel(mZoomPot)
            newHeight = int(z / 2)
            newWidth = int((z * WIDTH / HEIGHT) / 2)
            print(z, newWidth, newHeight)
            left, right = x0 - newWidth, x0 + newWidth
            top, bottom = y0 - newHeight, y0 + newHeight
            realRange = realEnd - realStart
            imRange = imEnd - imStart
            realStart = realStart + (realRange * left / WIDTH)
            realEnd = realStart + (right - left) * realRange / WIDTH
            imStart = imStart + (imRange * top / HEIGHT)
            imEnd = imStart + (bottom - top) * imRange / HEIGHT
            print("AFTER:", realStart, realEnd, imStart, imEnd)
            DrawMandelbrot(display, bitmap)

    def ZoomOut(display, bitmap):
        if (buttonZoomOut.value == False):
            print("BEFORE ZOOM OUT:", realStart, realEnd, imStart, imEnd)
            zoomDelta = 2
            realRange, imRange = realEnd - realStart, imEnd - imStart
            realDelta, imDelta = realRange / zoomDelta, imRange / zoomDelta
            left, right = realStart - realDelta, realEnd + realDelta
            top, bottom = imStart - imDelta, imEnd + imDelta
            realStart = left
            realEnd = right
            imStart = top
            imEnd = bottom
            print("AFTER:", realStart, realEnd, imStart, imEnd)
            DrawMandelbrot(display, bitmap)

    def Center(display, bitmap):
        if (buttonCenter.value == False):
            print("BEFORE CENTER:", realStart, realEnd, imStart, imEnd)
            realRange, imRange = realEnd - realStart, imEnd - imStart
            print("Ranges:", realRange, imRange)
            width2, height2 = WIDTH / 2, HEIGHT / 2
            xDelta = getCursorX(mPot0) - width2
            yDelta = getCursorY(mPot1) - height2
            print("Cursors:", getCursorX(mPot0), getCursorY(mPot1))
            print("Screen Deltas:", xDelta, yDelta)
            realDelta, imDelta = (realRange * xDelta /
                                  WIDTH), (imRange * yDelta / HEIGHT)
            print("Mandel Deltas:", realDelta, imDelta)
            realStart = realStart + realDelta
            realEnd = realEnd + realDelta
            imStart = imStart + imDelta
            imEnd = imEnd + imDelta
            print("AFTER:", realStart, realEnd, imStart, imEnd)
            DrawMandelbrot(display, bitmap)

    def DrawMandelbrot(display, bitmap):
        print("DRAWING:", realStart, realEnd, imStart, imEnd)
        RE_START = realStart
        RE_END = realEnd
        IM_START = imStart
        IM_END = imEnd

        MAX_ITER = 80
        for x in range(0, WIDTH):
            xx = RE_START + (x / WIDTH) * (RE_END - RE_START)
            for y in range(0, HEIGHT):
                yy = IM_START + (y / HEIGHT) * (IM_END - IM_START)
                c = complex(xx,
                            yy)  # Convert pixel coordinate to complex number
                m = mandelbrot(c)  # Compute the number of iterations
                color = 1 - int(m / MAX_ITER)
                bitmap[x, y] = 1 if color > 0 else 0  # Plot the point
            if x % 4 == 0: display.refresh()
        display.refresh()

    #=== MAIN ===
    #global mGroup
    mPot0, mPot1, mZoomPot = SetupAnalog()
    SetupButtons()
    (mDisplay, mGroup) = SetupDisplay()
    (mBitmap, mTileGrid) = SetupFullScreenTileGrid()
    (mcBitmap, mcTileGrid) = SetupCursorTileGrid()
    mGroup.append(mTileGrid)  #add the TileGrid to the group

    mCursor = displayio.Group(max_size=4)
    mCursor.append(Line(0, 0, WIDTH, 0, 0X000000))  # Top Line
    mCursor.append(Line(0, 0, 0, HEIGHT, 0X000000))  # Left Line
    mCursor.append(Line(WIDTH, 0, WIDTH, HEIGHT, 0X000000))  # Right Line
    mCursor.append(Line(0, HEIGHT, WIDTH, HEIGHT, 0X000000))  # Bottom Line
    mGroup.append(mCursor)
    mNextSensorRead = 0

    DrawMandelbrot(mDisplay, mBitmap)

    while True:
        MoveCursor(mDisplay, mCursor)
        ZoomIn(mDisplay, mBitmap)
        ZoomOut(mDisplay, mBitmap)
        Center(mDisplay, mBitmap)

    while True:
        pass
Пример #19
0
    def __init__(
            self,
            x=None,
            y=None,
            text=None,
            font=FONT,
            delta_x=-15,
            delta_y=-10,
            widget=None,
            anchor_point=(0.0, 0.0),
            anchored_position=None,
            position_offset=(0, 0),
            stroke=3,  # Not currently implemented in adafruit_display_shapes/line.py
            line_color=0xFFFFFF,
            text_color=None,
            text_offset=(0, -1),
            text_under=False,
    ):

        if widget:
            if (x is not None) or (y is not None):
                print("Note: Overriding (x,y) values with widget, anchor_point"
                      " and/or anchored_position")
            widget_width = widget.bounding_box[2]
            widget_height = widget.bounding_box[3]
            if anchor_point is not None:
                line_x0 = (widget.x + round(widget_width * anchor_point[0]) +
                           position_offset[0])
                line_y0 = (widget.y + round(widget_height * anchor_point[1]) +
                           position_offset[1])
            elif anchored_position is not None:
                line_x0 = widget.x + anchored_position[0] + position_offset[0]
                line_y0 = widget.y + anchored_position[1] + position_offset[1]
            else:
                raise ValueError(
                    "Must supply either anchor_point or anchored_position")
        elif (x is not None) and (y is not None):
            line_x0 = x
            line_y0 = y
        else:
            raise ValueError(
                "Must supply either (x,y) or widget and anchor_point or anchored_position"
            )

        line_x1 = line_x0 + delta_x
        line_y1 = line_y0 + delta_y

        text_anchor_point = (0.0, 1.0
                             )  # default: set text anchor to left corner
        underline_x_multiplier = 1

        if delta_x < 0:  # line is heading to the left, set text anchor to right corner
            text_anchor_point = (1.0, 1.0)
            underline_x_multiplier = -1

        if (
                text_under
        ):  # if text is under the line, set to text_anchor_point to upper edge
            text_anchor_point = (text_anchor_point[0], 0.0)

        if text_color is None:
            text_color = line_color

        self._label = bitmap_label.Label(
            text=text,
            font=font,
            color=text_color,
            anchor_point=text_anchor_point,
            anchored_position=(line_x1 + text_offset[0],
                               line_y1 + text_offset[1]),
        )

        label_width = self._label.bounding_box[2]
        line_x2 = line_x1 + label_width * underline_x_multiplier + text_offset[
            0]
        # lengthen the line if the text is offset
        line_y2 = line_y1

        self._line0 = Line(line_x0,
                           line_y0,
                           line_x1,
                           line_y1,
                           color=line_color)
        self._line1 = Line(line_x1,
                           line_y1,
                           line_x2,
                           line_y2,
                           color=line_color)

        super().__init__(max_size=3)
        # Group elements:
        # 0. Line0 - from (x,y) to (x+delta_x, y+delta_y)
        # 1. Line1 - horizontal line for text
        # 2. Label

        self.append(self._line0)
        self.append(self._line1)
        self.append(self._label)
Пример #20
0
    def __init__(self, tft_device, mode_config):
        self.this_tft = tft_device
        self.mode_config = mode_config
        self.screen_width = self.this_tft.display.width
        self.screen_height = self.this_tft.display.height

        self.this_group = displayio.Group(max_size=16)

        # write instructions at bottom of screen
        self.textbox_1 = label.Label(terminalio.FONT,
                                     text="",
                                     max_glyphs=36,
                                     color=mycolors.YELLOW,
                                     x=0,
                                     y=self.screen_height - 28)
        self.this_group.append(self.textbox_1)

        # write instructions at bottom of screen
        self.textbox_2 = label.Label(terminalio.FONT,
                                     text="",
                                     max_glyphs=36,
                                     color=mycolors.YELLOW,
                                     x=0,
                                     y=self.screen_height - 14)
        self.this_group.append(self.textbox_2)

        # doublesize text box for duration or countdown
        self.textbox_3 = label.Label(terminalio.FONT,
                                     text="",
                                     max_glyphs=18,
                                     color=mycolors.YELLOW,
                                     x=0,
                                     y=(LINE_POS_BOX_HEIGHT + 2),
                                     scale=2)
        self.this_group.append(self.textbox_3)

        # this box overlaps double-size box 3 but is single size; first single-size row
        self.textbox_4 = label.Label(terminalio.FONT,
                                     text="",
                                     max_glyphs=36,
                                     color=mycolors.YELLOW,
                                     x=0,
                                     y=(LINE_POS_BOX_HEIGHT + 2))
        self.this_group.append(self.textbox_4)

        # this box overlaps double-size box 3 but is single size; second single-size row
        self.textbox_5 = label.Label(terminalio.FONT,
                                     text="",
                                     max_glyphs=36,
                                     color=mycolors.YELLOW,
                                     x=0,
                                     y=(LINE_POS_BOX_HEIGHT + 2 + 14))
        self.this_group.append(self.textbox_5)

        # create white rectangle at top to serve as gage backgroundfield for line sensor ball
        self.lineposition_box = Rect(
            (THROT_BOX_WIDTH + GUTTER),
            0,
            self.screen_width - (2 * (THROT_BOX_WIDTH + GUTTER)),
            LINE_POS_BOX_HEIGHT,
            fill=mycolors.WHITE,
            outline=mycolors.WHITE)
        self.this_group.append(self.lineposition_box)

        initial_x = int(self.screen_width / 2)
        self.lineposition_marker = Circle(initial_x,
                                          BALL_RADIUS + 1,
                                          BALL_RADIUS,
                                          fill=mycolors.PASTEL_GREEN,
                                          outline=None)
        self.this_group.append(self.lineposition_marker)

        self.centerline = Line(int(self.screen_width / 2), 0,
                               int(self.screen_width / 2), LINE_POS_BOX_HEIGHT,
                               mycolors.DARK_GRAY)
        self.this_group.append(self.centerline)

        # create left and right throttle display gage boxes
        self.left_throtgage_box = Rect(0,
                                       0,
                                       THROT_BOX_WIDTH,
                                       self.screen_height,
                                       fill=mycolors.LIGHT_GRAY,
                                       outline=mycolors.LIGHT_GRAY)
        self.this_group.append(self.left_throtgage_box)

        self.right_throtgage_box = Rect(self.screen_width - THROT_BOX_WIDTH,
                                        0,
                                        THROT_BOX_WIDTH,
                                        self.screen_height,
                                        fill=mycolors.LIGHT_GRAY,
                                        outline=mycolors.LIGHT_GRAY)
        self.this_group.append(self.right_throtgage_box)

        # and corresponding left and right throttle value (initially "unfilled")
        self.left_throtval_box = Rect(1,
                                      0, (THROT_BOX_WIDTH - 2),
                                      self.screen_height,
                                      fill=mycolors.DARK_GRAY,
                                      outline=mycolors.DARK_GRAY)
        self.this_group.append(self.left_throtval_box)

        self.right_throtval_box = Rect(self.screen_width -
                                       (THROT_BOX_WIDTH - 1),
                                       0, (THROT_BOX_WIDTH - 2),
                                       self.screen_height,
                                       fill=mycolors.DARK_GRAY,
                                       outline=mycolors.DARK_GRAY)
        self.this_group.append(self.right_throtval_box)