MantisIDE

Neon rings · Round 1.28" touch watch

Project by MantisIDE Team · Fri Nov 27 2026 · 0 points · 0 comments

Showcase 2 - Neon rings: counter-rotating arc segments with a breathing glow

You’ll learn: counter-rotating arcs, breathing

Board: Waveshare ESP32-S3-Touch-LCD-1.28 (ESP32-S3R2). Part of the kit’s Showcase and benchmarks. Needs the board’s LVGL firmware: flash it from the notebook’s Flash button, then press Open in Full IDE.

# Showcase 2 - Neon rings: counter-rotating arc segments with a breathing glow
import lvgl as lv
import display

display.init()                     # start the display and touch (does nothing if already on)

TEXT = 0xE3EFE6
ACCENT = 0x46E07C
BLUE = 0x6CB8FF
AMBER = 0xF2B84B
VIOLET = 0xB593FF
keep = []                             # styles, buffers and callbacks LVGL uses must stay referenced

FONTS = {12: lv.font_montserrat_12, 14: lv.font_montserrat_14, 16: lv.font_montserrat_16}


def label(parent, text="", color=TEXT, font=16, align=lv.ALIGN.CENTER, x=0, y=0, zoom=0):
    """lv.label with a colour and a Montserrat 12/14/16 font. zoom=2 draws it twice as big."""
    lb = lv.label(parent)
    lb.set_text(text)
    lb.set_style_text_color(lv.color_hex(color), 0)
    lb.set_style_text_font(FONTS.get(font, lv.font_montserrat_16), 0)
    if zoom:
        lb.set_style_transform_scale(int(256 * zoom), 0)   # 256 = 100 %
        lb.update_layout()
        lb.set_style_transform_pivot_x(lb.get_width() // 2, 0)
        lb.set_style_transform_pivot_y(lb.get_height() // 2, 0)
    lb.align(align, int(x), int(y))
    return lb


def anim(obj, start, end, ms, setter, path=None, repeat=1, playback=0, delay=0, done=None):
    """Animate start -> end over ms, calling setter(obj, value). repeat=-1 loops forever."""
    a = lv.anim_t()
    a.init()
    a.set_var(obj)
    a.set_values(start, end)
    a.set_duration(ms)
    a.set_delay(delay)
    a.set_custom_exec_cb(lambda _a, v: setter(obj, v))
    a.set_path_cb(path or lv.anim_t.path_ease_in_out)
    if repeat < 0:
        a.set_repeat_count(lv.ANIM_REPEAT_INFINITE)
    elif repeat > 1:
        a.set_repeat_count(repeat)
    if playback:
        a.set_reverse_duration(playback)  # play back to start
    if done:
        a.set_completed_cb(lambda _a: done())
    a.start()
    keep.append(a)
    return a

scr = lv.screen_active()             # the screen LVGL is showing
scr.clean()                           # remove what the last program drew
scr.set_style_bg_color(lv.color_hex(0x03020A), 0)
scr.remove_flag(lv.obj.FLAG.SCROLLABLE)

RINGS = [(226, 6, ACCENT, 90, 1600), (196, 10, VIOLET, 140, -2300), (162, 4, BLUE, 60, 1100),
         (132, 12, 0xFF4FA3, 200, -3100), (100, 5, AMBER, 110, 1900)]
for size, width, color, length, ms in RINGS:
    a = lv.arc(scr)
    a.set_size(size, size)
    a.center()
    a.remove_style(None, lv.PART.KNOB)
    a.remove_flag(lv.obj.FLAG.CLICKABLE)
    a.set_bg_angles(0, 0)                                  # no background track
    a.set_angles(0, length)
    a.set_style_arc_width(width, lv.PART.INDICATOR)
    a.set_style_arc_color(lv.color_hex(color), lv.PART.INDICATOR)
    a.set_style_arc_rounded(True, lv.PART.INDICATOR)
    a.set_style_arc_width(0, lv.PART.MAIN)
    start, end = (0, 360) if ms > 0 else (360, 0)
    anim(a, start, end, abs(ms), lambda o, v: o.set_rotation(v), path=lv.anim_t.path_linear, repeat=-1)
    # each ring also "breathes" its length
    anim(a, length // 2, length, abs(ms) // 2, lambda o, v: o.set_angles(0, v), repeat=-1,
            playback=abs(ms) // 2)

center = label(scr, "NEON", 0xFFFFFF, 16, zoom=1.6)
anim(center, 80, 255, 1200, lambda o, v: o.set_style_opa(v, 0), repeat=-1, playback=1200)
Loading post…

Dialog