Пример #1
0
def roundrectDemo(sec=5, dofill=False):
    tx = "ROUND RECT"
    if dofill:
        tx = "FILLED " + tx
    header(tx, True)

    n = time.time() + sec
    while time.time() < n:
        x = machine.random(2, maxx - 18)
        y = machine.random(miny, maxy - 18)
        w = machine.random(12, maxx - x)
        h = machine.random(12, maxy - y)
        if w > h:
            r = machine.random(2, h // 2)
        else:
            r = machine.random(2, w // 2)
        color = machine.random(0xFFFFFF)
        if dofill:
            fill = machine.random(0xFFFFFF)
            lcd.roundrect(x, y, w, h, r, color, fill)
        else:
            lcd.roundrect(x, y, w, h, r, color)
        if buttonA.wasPressed():
            break
    lcd.resetwin()
Пример #2
0
def ellipseDemo(sec=5, dofill=False):
    tx = "ELLIPSE"
    if dofill:
        tx = "FILLED " + tx
    header(tx, True)

    n = time.time() + sec
    while time.time() < n:
        x = machine.random(4, maxx - 2)
        y = machine.random(miny + 2, maxy - 2)
        if x < y:
            rx = machine.random(2, x)
        else:
            rx = machine.random(2, y)
        if x < y:
            ry = machine.random(2, x)
        else:
            ry = machine.random(2, y)
        color = machine.random(0xFFFFFF)
        if dofill:
            fill = machine.random(0xFFFFFF)
            lcd.ellipse(x, y, rx, ry, 15, color, fill)
        else:
            lcd.ellipse(x, y, rx, ry, 15, color)
        if buttonA.wasPressed():
            break
    lcd.resetwin()
Пример #3
0
def fontDemo(sec=5, rot=False):
    tx = "FONTS"
    if rot:
        tx = "ROTATED " + tx
    header(tx, True)

    tx = "ESP32-MicrpPython"
    n = time.time() + sec
    while time.time() < n:
        frot = 0
        if rot:
            frot = math.floor(machine.random(359) / 5) * 5
        for font in fontnames:
            if (not rot) or (font != lcd.FONT_7seg):
                x = machine.random(maxx - 8)
                if font != lcd.FONT_7seg:
                    lcd.font(font, rotate=frot)
                    _, fsz = lcd.fontSize()
                    y = machine.random(miny, maxy - fsz)
                    lcd.text(x, y, tx, machine.random(0xFFFFFF))
                else:
                    l = machine.random(6, 12)
                    w = machine.random(1, l // 3)
                    lcd.font(font, rotate=frot, dist=l, width=w)
                    _, fsz = lcd.fontSize()
                    y = machine.random(miny, maxy - fsz)
                    lcd.text(x, y, "-12.45/", machine.random(0xFFFFFF))
        if buttonA.wasPressed():
            break
    lcd.resetwin()
Пример #4
0
def lineDemo(sec=5):

    header("LINE DEMO", True)

    n = time.time() + sec

    while time.time() < n:

        x1 = machine.random(maxx - 4)

        y1 = machine.random(miny, maxy - 4)

        x2 = machine.random(maxx - 1)

        y2 = machine.random(miny, maxy - 1)

        color = machine.random(0xFFFFFF)

        lcd.line(x1, y1, x2, y2, color)

        if btnA.wasPressed():
            speaker.tone(346, 120, 1)
            break

    lcd.resetwin()
Пример #5
0
def circleDemo(sec=5, dofill=False):

    tx = "CIRCLE"

    if dofill:

        tx = "FILLED " + tx

    header(tx, True)

    n = time.time() + sec

    while time.time() < n:

        color = machine.random(0xFFFFFF)

        fill = machine.random(0xFFFFFF)

        x = machine.random(4, maxx - 2)

        y = machine.random(miny + 2, maxy - 2)

        if x < y:

            r = machine.random(2, x)

        else:

            r = machine.random(2, y)

        if dofill:

            lcd.circle(x, y, r, color, fill)

        else:

            lcd.circle(x, y, r, color)

        if btnA.wasPressed():
            speaker.tone(346, 120, 1)
            break

    lcd.resetwin()
Пример #6
0
def rectDemo(sec=5, dofill=False):
    tx = "RECTANGLE"
    if dofill:
        tx = "FILLED " + tx
    header(tx, True)

    n = time.time() + sec
    while time.time() < n:
        x = machine.random(4, maxx - 2)
        y = machine.random(miny, maxy - 2)
        w = machine.random(2, maxx - x)
        h = machine.random(2, maxy - y)
        color = machine.random(0xFFFFFF)
        if dofill:
            fill = machine.random(0xFFFFFF)
            lcd.rect(x, y, w, h, color, fill)
        else:
            lcd.rect(x, y, w, h, color)
        if buttonA.wasPressed():
            break
    lcd.resetwin()