FlowAWTRIX NG
Disco Visualization
On an AWTRIX display

On your display
Mirrored rainbow spectrum with a bass column and beat confetti
- Works with
- AWTRIX NG
- Topic
- Miscellaneous
- Includes
- Script
Choose your display in the next step.
Flow description
Shows a visualization of the Music played by AWTRIX
You need a ESP32-S3 with a I2S Audio DAC to use this
FXPbhLqgmH3E.ax
# @name Disco
# @desc Mirrored rainbow spectrum with a bass column and beat confetti
# @author AWTRIX NG
# @version 1.1
# @config spin slider "Rainbow speed" default=100 min=0 max=400 unit=%
# @config decay number "Bar fall time" default=300 min=100 max=2000 unit=ms
# @config bass bool "White bass column" default=true
# @config confetti bool "Beat confetti" default=true
import math
class Disco
var n # bars per side
var level # smoothed level per bar, 0..255
var hue # rainbow offset, drifts and jumps on the beat
var last # previous frame, ms
var sparks # confetti: [x, y, born]
var spin # rainbow drift, %
var decay
var bass
var confetti
def init()
self.n = width() / 2
if self.n > 32 self.n = 32 end
self.level = []
for i: 0..self.n - 1
self.level.push(0)
end
self.hue = 0
self.last = 0
self.sparks = []
self.spin = store.get("spin")
self.decay = store.get("decay")
self.bass = store.get("bass")
self.confetti = store.get("confetti")
end
def should_show()
return music.playing()
end
def draw()
var now = now_ms()
var dt = self.last > 0 ? now - self.last : 0
if dt > 100 dt = 100 end
self.last = now
var fall = dt * 255 / self.decay
var bands = music.bands(self.n, 255)
var beat = music.beat()
var h = height()
var cx = width() / 2
self.hue = (self.hue + dt * self.spin / 2500) % 360
if beat
self.hue = (self.hue + 90) % 360
if self.confetti
for k: 0..5
self.sparks.push([math.rand() % width(), math.rand() % 2, now])
end
end
end
# Bass in the middle, treble at both edges, the rainbow wrapped over the bars.
for i: 0..self.n - 1
var lv = self.level[i] - fall
if bands[i] > lv lv = bands[i] end
if lv < 0 lv = 0 end
self.level[i] = lv
var bar = (lv * lv / 255 * h + 127) / 255
var hue = (self.hue + i * 300 / self.n) % 360
for y: 0..bar - 1
var c = hsv(hue, 100, 60 + y * 5)
pixel(cx - 1 - i, h - 1 - y, c)
pixel(cx + 1 + i, h - 1 - y, c)
end
end
if self.bass
var bass = (self.level[0] * h + 127) / 255
for y: 0..bass - 1
pixel(cx, h - 1 - y, 0xFFFFFF)
end
end
# Confetti drops one row every 120 ms and is gone after 600 ms.
var keep = []
for s: self.sparks
var age = now - s[2]
if age < 600
var y = s[1] + age / 120
if y < h pixel(s[0], y, hsv((self.hue + 180) % 360, 40, 100)) end
keep.push(s)
end
end
self.sparks = keep
end
end
return Disco()
Community
Discussion 0
Ask a question, suggest a change or share how you use it.
No comments yet. Start the conversation.
More flows for AWTRIX NG Scripts or Miscellaneous
Something wrong with this flow? Report it.
Have an idea?
Sign in to ask questions and join the conversation.