import display
import utime
import urandom
import color
import buttons
import leds

width = 160
height = 80
bar_count = 5
led_count = 10
pattern = [bool(i % 2) for i in range(bar_count)]
led_pattern = [bool(i%2) for i in range(led_count)]
title = "CYBER"

bg_anim = True
led_anim = True

while True:

    display = display.open()
    display.clear()
    
 
    left_pressed = buttons.read( buttons.BOTTOM_LEFT )
    right_pressed = buttons.read( buttons.BOTTOM_RIGHT )

    if left_pressed:
        bg_anim = not bg_anim
 
    if right_pressed:
        led_anim = not led_anim
 
    if led_anim:
        for i in range(led_count):
            leds.prep(i, color.YELLOW if led_pattern[i] else color.BLACK)
            led_pattern[i] = not led_pattern[i]
        leds.update()
    else:
        for i in range(led_count):
            leds.prep(i, color.BLACK)
        leds.update()
        
        
    if bg_anim:
        for i in range(bar_count):
            w = width // bar_count

            col = color.BLACK if pattern[i] else color.YELLOW
            display.rect(i*w, 0, (i+1)*w, 80, col=col, filled=True)
            pattern[i] = not pattern[i]
     
  
    posx=80 - round(len(title) / 2 * 14)
    bg = color.YELLOW if pattern[2] else color.BLACK
    fg = color.BLACK if pattern[2] else color.WHITE
    display.print(title, fg=fg, bg=bg, posx=posx, posy=30)        
    
    display.update()
    display.close()

    utime.sleep(0.2)
    




    