Exemplo n.º 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()
Exemplo n.º 2
0
    def __init__(self, x, y, w, h, tick_s, tick_e, color, title, value_format):
        self.x = x  # メーターの表示位置
        self.y = y  # メーターの表示位置
        self.w = w  # メーターの表示幅
        self.h = h  # メーターの表示高
        self.tick_s = tick_s  # 目盛の最小値
        self.tick_e = tick_e  # 目盛の最大値
        self.title = title
        self.value_format = value_format  # 値をテキスト表示する際のフォーマット

        self.center_x = x + w // 2  # 針の原点
        self.center_y = y + int(h * 0.9)  # 針の原点
        self.prev_value = tick_s
        self.prev_angle = None

        lcd.roundrect(x, y, w, h, h // 10, lcd.BLACK, lcd.WHITE)
        lcd.arc(self.center_x, self.center_y, int(h * 0.67), int(h * 0.07),
                -50, 50, color, color)
        lcd.arc(self.center_x, self.center_y, int(h * 0.6), 2, -50, 50,
                lcd.BLACK)

        # 目盛の値表示用フォント設定
        if self.w == win_w:
            lcd.font(lcd.FONT_Default, transparent=False)
        else:
            lcd.font(lcd.FONT_DefaultSmall, transparent=True)

        fw, fh = lcd.fontSize()

        tick = tick_s
        tick_i = (tick_e - tick_s) // 4
        for r in range(-50, 51, 5):
            if r % 25 == 0:
                # 目盛の最小値から最大値を4分割して目盛値を表示
                lcd.lineByAngle(self.center_x - 1, self.center_y, int(h * 0.6),
                                int(h * 0.1), r, lcd.BLACK)
                lcd.lineByAngle(self.center_x, self.center_y, int(h * 0.6),
                                int(h * 0.1), r, lcd.BLACK)
                tick_text = str(tick)
                text_width = lcd.textWidth(tick_text)
                lcd.print(
                    tick_text, self.center_x +
                    int(math.sin(math.radians(r)) * h * 0.7) - text_width // 2,
                    self.center_y - int(math.cos(math.radians(r)) * h * 0.7) -
                    fh, lcd.BLACK)
                tick += tick_i
            else:
                # 細かい目盛線を表示
                lcd.lineByAngle(self.center_x, self.center_y, int(h * 0.6),
                                int(h * 0.05), r, lcd.BLACK)
Exemplo n.º 3
0
    def __init__(self, x, y, w, h, color):
        self.x = x  # 時計の表示位置
        self.y = y  # 時計の表示位置
        self.w = w  # 時計の表示幅
        self.h = h  # 時計の表示高
        self.center_x = x + w // 2  # 針の中心
        self.center_y = y + h // 2  # 針の中心
        self.hour_deg = 0
        self.minute_deg = 0
        self.second_deg = 0

        lcd.roundrect(x, y, w, h, h // 10, lcd.BLACK, lcd.WHITE)
        # 0 から 360 とは書けないので、半分の円弧を合わせる
        lcd.arc(self.center_x, self.center_y, int(h * 0.39), int(h * 0.08), 0,
                180, color, color)
        lcd.arc(self.center_x, self.center_y, int(h * 0.39), int(h * 0.08),
                180, 360, color, color)

        if self.w == win_w:
            lcd.font(lcd.FONT_Default, transparent=False)
        else:
            lcd.font(lcd.FONT_DefaultSmall, transparent=True)

        fw, fh = lcd.fontSize()
        hour = 12
        for r in range(0, 360, 360 // 60):
            if r % (360 // 12) == 0:
                # 1〜12の位置に黒点および数字を表示
                lcd.circle(
                    self.center_x +
                    int(math.sin(math.radians(r)) * h / 2 * 0.7),
                    self.center_y -
                    int(math.cos(math.radians(r)) * h / 2 * 0.7), 2, lcd.BLACK,
                    lcd.BLACK)
                hour_text = str(hour)
                text_width = lcd.textWidth(hour_text)
                lcd.print(
                    hour_text, self.center_x +
                    int(math.sin(math.radians(r)) * h / 2 * 0.85) -
                    text_width // 2, self.center_y -
                    int(math.cos(math.radians(r)) * h / 2 * 0.85) - fh // 2,
                    lcd.BLACK)
                hour = (hour + 1) % 12
            else:
                lcd.pixel(
                    self.center_x +
                    int(math.sin(math.radians(r)) * h / 2 * 0.7),
                    self.center_y -
                    int(math.cos(math.radians(r)) * h / 2 * 0.7), lcd.BLACK)