# @name Social-Handles # @desc Display YouTube, TikTok, Instagram and Twitch handles # @version 5.0 # @config youtube_enabled bool "YouTube enabled" default=true # @config youtube text "YouTube username" default="BR4ND-DJ" maxlen=32 # @config tiktok_enabled bool "TikTok enabled" default=true # @config tiktok text "TikTok username" default="BR4ND_DJ" maxlen=32 # @config instagram_enabled bool "Instagram enabled" default=true # @config instagram text "Instagram username" default="BR4ND_DJ" maxlen=32 # @config twitch_enabled bool "Twitch enabled" default=true # @config twitch text "Twitch username" default="BR4ND_DJ" maxlen=32 # @config duration number "Total duration" default=8 min=1 max=30 unit=s # @config scrollSpeed number "Scroll speed" default=100 min=10 max=300 step=10 unit=% # @config background color "Background color" default=#000000 class SocialHandles var youtube_enabled var youtube var tiktok_enabled var tiktok var instagram_enabled var instagram var twitch_enabled var twitch var duration var scrollSpeed var background var current var nextChange var handleDuration var scrollPos var lastScroll def init() self.youtube_enabled = store.get("youtube_enabled") self.youtube = store.get("youtube") self.tiktok_enabled = store.get("tiktok_enabled") self.tiktok = store.get("tiktok") self.instagram_enabled = store.get("instagram_enabled") self.instagram = store.get("instagram") self.twitch_enabled = store.get("twitch_enabled") self.twitch = store.get("twitch") self.duration = store.get("duration") self.scrollSpeed = store.get("scrollSpeed") self.background = store.get("background") # Calculate how many handles are enabled. var enabledCount = 0 if self.youtube_enabled enabledCount += 1 end if self.tiktok_enabled enabledCount += 1 end if self.instagram_enabled enabledCount += 1 end if self.twitch_enabled enabledCount += 1 end # Divide the total duration equally over all # enabled handles. if enabledCount > 0 self.handleDuration = self.duration / enabledCount else self.handleDuration = self.duration end self.current = -1 self.scrollPos = width() - 9 self.lastScroll = now_ms() self.nextEnabled() self.nextChange = now_ms() + self.handleDuration * 1000 end # ========================================================= # NEXT ENABLED PLATFORM # ========================================================= def nextEnabled() var tries = 0 while tries < 4 self.current += 1 if self.current > 3 self.current = 0 end if self.current == 0 && self.youtube_enabled self.resetScroll() return end if self.current == 1 && self.tiktok_enabled self.resetScroll() return end if self.current == 2 && self.instagram_enabled self.resetScroll() return end if self.current == 3 && self.twitch_enabled self.resetScroll() return end tries += 1 end end # ========================================================= # RESET SCROLL # ========================================================= def resetScroll() self.scrollPos = width() - 9 self.lastScroll = now_ms() end # ========================================================= # MAIN DRAW # ========================================================= def draw() clear(self.background) if now_ms() >= self.nextChange self.nextEnabled() self.nextChange = now_ms() + self.handleDuration * 1000 end if self.current == 0 && self.youtube_enabled self.drawYoutube() elif self.current == 1 && self.tiktok_enabled self.drawTiktok() elif self.current == 2 && self.instagram_enabled self.drawInstagram() elif self.current == 3 && self.twitch_enabled self.drawTwitch() end end # ========================================================= # YOUTUBE # ========================================================= def drawYoutube() self.logoYoutube() self.drawGradientText( self.youtube, 0xFF0000, 0xFF6666 ) # Restore complete logo area. rect_fill( 0, 0, 8, 7, self.background ) self.logoYoutube() # Pixel 8 is always empty. self.clearGap() end def logoYoutube() rect_fill( 0, 1, 8, 6, 0xFF0000 ) line( 1, 0, 6, 0, 0xFF0000 ) line( 1, 7, 6, 7, 0xFF0000 ) line( 3, 2, 3, 6, 0xFFFFFF ) line( 4, 3, 4, 5, 0xFFFFFF ) pixel( 5, 4, 0xFFFFFF ) end # ========================================================= # TIKTOK # ========================================================= def drawTiktok() self.drawGradientText( self.tiktok, 0x08CFF8, 0xFE2C55 ) # Completely clear logo + gap. rect_fill( 0, 0, 8, 7, self.background ) # Redraw TikTok logo. self.logoTiktok() # Pixel 8 is always empty. self.clearGap() end def logoTiktok() self.drawTikRow(0, 0x0070) self.drawTikRow(1, 0x006C) self.drawTikRow(2, 0x006B) self.drawTikRow(3, 0x0470) self.drawTikRow(4, 0x1870) self.drawTikRow(5, 0x1870) self.drawTikRow(6, 0x1AB0) self.drawTikRow(7, 0x06C0) end def drawTikRow(y, row) var c for x : 0 .. 7 c = (row >> (14 - 2 * x)) & 3 if c == 1 pixel( x, y, 0x08CFF8 ) elif c == 2 pixel( x, y, 0xFFFFFF ) elif c == 3 pixel( x, y, 0xFE2C55 ) end end end # ========================================================= # INSTAGRAM # ========================================================= def drawInstagram() self.logoInstagram() self.drawGradientText( self.instagram, 0x833AB4, 0xFCAF45 ) # Restore complete logo area. rect_fill( 0, 0, 8, 7, self.background ) self.logoInstagram() # Pixel 8 is always empty. self.clearGap() end def logoInstagram() var px = [ 0x605D5B5B, 0x64666462, 0x7F7F7F60, 0x667F7F7F, 0x62607F63, 0x6B7F7F64, 0x7F6A7F6A, 0x707F707F, 0x7F707F70, 0x737F737F, 0x090D7F77, 0x777F0305, 0x7F7F7F0C, 0x037F7F7F, 0x0D111415, 0x76010509 ] for y : 0 .. 7 for x : 0 .. 7 var i = y * 8 + x var v = ( px[i / 4] >> ((i % 4) * 8) ) & 255 pixel( x, y, v == 127 ? 0xFFFFFF : hsv(v * 3, 100, 100) ) end end end # ========================================================= # TWITCH # ========================================================= def drawTwitch() self.drawSolidText( self.twitch, 0x9146FF ) # Completely clear logo + gap. rect_fill( 0, 0, 8, 7, self.background ) self.logoTwitch() # Pixel 8 is always empty. self.clearGap() end def logoTwitch() var px = [ 0x000000, 0x9146FF, 0x9146FF, 0x9146FF, 0x9146FF, 0x9146FF, 0x9146FF, 0x9146FF, 0x9146FF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0x9146FF, 0x9146FF, 0xFFFFFF, 0xFFFFFF, 0x9146FF, 0xFFFFFF, 0x9146FF, 0xFFFFFF, 0x9146FF, 0x9146FF, 0xFFFFFF, 0xFFFFFF, 0x9146FF, 0xFFFFFF, 0x9146FF, 0xFFFFFF, 0x9146FF, 0x9146FF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0x9146FF, 0x9146FF, 0x9146FF, 0x9146FF, 0xFFFFFF, 0xFFFFFF, 0x9146FF, 0x9146FF, 0x9146FF, 0x000000, 0x000000, 0x9146FF, 0xFFFFFF, 0x9146FF, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x9146FF, 0x9146FF, 0x000000, 0x000000, 0x000000, 0x000000 ] for y : 0 .. 7 for x : 0 .. 7 var i = y * 8 + x if px[i] != 0 pixel( x, y, px[i] ) end end end end # ========================================================= # EMPTY GAP # # Pixel 8 is reserved as the empty separator. # ========================================================= def clearGap() for y : 0 .. 7 pixel( 8, y, self.background ) end end # ========================================================= # GRADIENT TEXT # # Logo: x 0..7 # Gap: x 8 # Text: x 9..31 # # Short text: # centered with gradient. # # Long text: # gradient while scrolling. # ========================================================= def drawGradientText(name, c1, c2) var avail = width() - 9 var w = text_ink_width(name) # Text fits: center it like the original counters. if w <= avail ramp_text( 9 + (avail - w) / 2, 6, name, [c1, c2] ) return end # Update scroll position. var now = now_ms() if now - self.lastScroll >= 20 self.scrollPos -= self.scrollSpeed / 100.0 self.lastScroll = now end # Let the complete text disappear. if self.scrollPos < -w - 8 self.scrollPos = avail end # Draw gradient scrolling text. ramp_text( 9 + self.scrollPos, 6, name, [c1, c2] ) end # ========================================================= # TWITCH TEXT # ========================================================= def drawSolidText(name, color) var avail = width() - 9 var w = text_ink_width(name) # Text fits: center it. if w <= avail text( 9 + (avail - w) / 2, 6, name, color ) return end var now = now_ms() if now - self.lastScroll >= 20 self.scrollPos -= self.scrollSpeed / 100.0 self.lastScroll = now end if self.scrollPos < -w - 8 self.scrollPos = avail end text( 9 + self.scrollPos, 6, name, color ) end end return SocialHandles()