Radial equalizer · Round 1.28" touch watch
Showcase 5 - Radial equalizer: 24 bars around the circle dancing like a music visualizer
You’ll learn: rotated bars, HSV colours
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 5 - Radial equalizer: 24 bars around the circle dancing like a music visualizer
import math
import lvgl as lv
import display
display.init() # start the display and touch (does nothing if already on)
LINE = 0x24452F
def ring(parent, size, width, color, value=100, bg_color=LINE):
"""An lv.arc used as a progress ring (no knob, not touchable)."""
a = lv.arc(parent)
a.set_size(size, size)
a.center()
a.set_rotation(270) # start at 12 o'clock
a.set_bg_angles(0, 360)
a.set_range(0, 100)
a.set_value(value)
a.remove_style(None, lv.PART.KNOB)
a.remove_flag(lv.obj.FLAG.CLICKABLE)
a.set_style_arc_width(width, lv.PART.MAIN)
a.set_style_arc_width(width, lv.PART.INDICATOR)
a.set_style_arc_color(lv.color_hex(bg_color), lv.PART.MAIN)
a.set_style_arc_color(lv.color_hex(color), lv.PART.INDICATOR)
return a
def polar(radius, degrees):
"""(x, y) from the centre for a point on a circle; 0 deg = 12 o'clock, clockwise."""
r = math.radians(degrees - 90)
return int(radius * math.cos(r)), int(radius * math.sin(r))
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(0x050208), 0)
scr.remove_flag(lv.obj.FLAG.SCROLLABLE)
N = 24
bars = []
for i in range(N):
ang = i * 360 / N
b = lv.obj(scr)
b.remove_style_all()
b.set_size(6, 20)
b.set_style_radius(3, 0)
b.set_style_bg_opa(lv.OPA.COVER, 0)
hue = int(i * 360 / N)
b.set_style_bg_color(lv.color_hsv_to_rgb(hue, 80, 100), 0)
x, y = polar(70, ang)
b.align(lv.ALIGN.CENTER, x, y)
b.set_style_transform_pivot_x(3, 0)
b.set_style_transform_pivot_y(10, 0)
b.set_style_transform_rotation(int(ang * 10), 0)
bars.append(b)
center = ring(scr, 90, 4, 0xFFFFFF, 0)
t = [0.0]
def frame(_):
t[0] += 0.18
level = 0
for i, b in enumerate(bars):
v = (math.sin(t[0] + i * 0.55) + math.sin(t[0] * 1.7 + i * 0.3) + 2) / 4 # 0..1
h = 10 + int(v * 40)
b.set_height(h)
b.set_style_transform_pivot_y(h // 2, 0)
level += v
center.set_value(int(level / N * 100))
frame_timer = lv.timer_create(frame, 40, None)
Comments