Загрузка данных


import Pico_LCD_1_3
import time

lcd = Pico_LCD_1_3.LCD_1inch3()

# Цвета
BLACK = 0x0000
EYE_COLOR = 0x0F0F
HEART_COLOR = 0x001F  # Синий для сердец
TEAR_COLOR = 0x07FF   # Голубой для слез

current_emotion = "normal"

def draw_eyes(rx, ry):
    lcd.ellipse(80, 120, rx, ry, EYE_COLOR, True)
    lcd.ellipse(160, 120, rx, ry, EYE_COLOR, True)

def draw_heart(cx, cy, size):
    # size - коэффициент увеличения (например, 1.0, 1.5, 2.0)
    # Круги (верхняя часть сердца)
    lcd.ellipse(int(cx - 8*size), int(cy - 5*size), int(8*size), int(8*size), HEART_COLOR, True)
    lcd.ellipse(int(cx + 8*size), int(cy - 5*size), int(8*size), int(8*size), HEART_COLOR, True)
    # Треугольник (нижняя часть) - рисуем закрашенным через вертикальные линии
    for i in range(int(30*size)):
        lcd.line(int(cx - 15*size + i/2), int(cy - 2*size + i), 
                 int(cx + 15*size - i/2), int(cy - 2*size + i), HEART_COLOR)

def set_emotion(emotion):
    global current_emotion
    current_emotion = emotion
    
    if emotion == "normal":
        lcd.fill(BLACK)
        draw_eyes(25, 40)
        lcd.show()

    elif emotion == "blink":
        # Моргание
        for i in range(40, 0, -10):
            lcd.fill(BLACK)
            draw_eyes(25, i)
            lcd.show()
            time.sleep(0.05)
        for i in range(0, 41, 10):
            lcd.fill(BLACK)
            draw_eyes(25, i)
            lcd.show()
            time.sleep(0.05)
            
    elif emotion == "heart":
        # Анимация роста сердца (5 кадров)
        for s in [0.5, 0.8, 1.2, 1.6, 2.0]:
            lcd.fill(BLACK)
            draw_heart(80, 120, s)
            draw_heart(160, 120, s)
            lcd.show()
            time.sleep(0.1)

    elif emotion == "sad":
        eye_idx = 0
        while current_emotion == "sad":
            x = 80 if eye_idx == 0 else 160
            for y in range(130, 240, 15):
                if current_emotion != "sad": break
                lcd.fill(BLACK)
                draw_eyes(30, 20)
                lcd.ellipse(x, y, 5, 8, TEAR_COLOR, True)
                lcd.show()
                time.sleep(0.1)
            eye_idx = 1 - eye_idx