예제 #1
0
def circleSimple():

    tx = "CIRCLE"

    header(tx, True)

    x = maxx // 2

    y = (maxy - miny) // 2 + (miny // 2)

    if x > y:

        r = y - miny

    else:

        r = x - miny

    while r > 0:

        color = machine.random(0xFFFFFF)

        fill = machine.random(0xFFFFFF)

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

        r -= 10

        x += 10
예제 #2
0
def drawGrid():
    for x in range(40, 121, 40):
        lcd.circle(160, 120, x, lcd.DARKGREY)
    for x in range(0, 360, 45):
        lcd.lineByAngle(160, 120, 0, 120, x, lcd.DARKGREY)
    for x in (('N', 165, 10), ('E', 295, 115), ('S', 165, 220), ('W', 15, 115)):
        lcd.print(x[0], x[1], x[2])
    for x in (('90', 155, 108), ('60', 195, 108), ('30', 235, 108), ('0', 275, 108)):
        lcd.print(x[0], x[1], x[2])
예제 #3
0
def drawSatellites(sats, sats_used):
    for k, v in sats.items():
        print(k, v[0])
        if v[0][0] != None and v[0][1] != None:
            l = int((90 - v[0][0]) / 90.0 * 120.0)
            lcd.lineByAngle(160, 120, 0, l, v[0][1])
            x = 160 + sin(radians(v[0][1])) * l
            y = 120 - cos(radians(v[0][1])) * l
            color = lcd.GREEN if k in sats_used else lcd.RED
            lcd.circle(int(x), int(y), 4, color, color)
            lcd.print(str(k), int(x) + 9, int(y) - 7)
예제 #4
0
    def _draw_once(self):
        '''最初に一度だけ描画する処理'''
        # 枠を表示 (デバッグ用)
        #lcd.rect(0, 0, self.width + 1, self.height + 1, lcd.BLACK)

        # 温度計の液溜め部分(正式には「球部」)の円を描画
        lcd.circle(self.circle_x, self.circle_y, self.circle_radius,
                   self.color, self.color)

        # 目盛りの間隔 (摂氏度)
        tick = 10

        # 目盛りとグラフの隙間のピクセル数
        m = 2

        # 目盛りの長さ (ピクセル)
        l = 8

        # 目盛りと軸の数字の隙間のピクセル数
        m2 = 4

        # フォントの設定
        lcd.font(lcd.FONT_Default, color=self.axis_color, transparent=True)

        # TODO: ラベルを描画
        label_x = self.bar_x - m - l - m2 - lcd.textWidth(self.label)
        label_y = self.y
        lcd.text(label_x, label_y, self.label)

        # フォントの設定
        lcd.font(lcd.FONT_Default, color=self.axis_color, transparent=True)

        # フォントサイズ
        font_width, font_height = lcd.fontSize()
        half_font_height = int(round(font_height / 2))

        min_ylabel = int(math.ceil(self.min_value / 10)) * 10
        for i in range(min_ylabel, self.max_value + 1, tick):
            y1 = self._calc_y(i)

            # 目盛り (左)
            lcd.line(self.bar_x - m - l, y1, self.bar_x - m, y1,
                     self.axis_color)

            # 目盛り (右)
            lcd.line(self.bar_x + self.bar_width + m, y1,
                     self.bar_x + self.bar_width + m + l, y1, self.axis_color)

            # 目盛りラベル
            tick_label = '{}'.format(i)
            lcd.print(tick_label,
                      self.bar_x - m - l - m2 - lcd.textWidth(tick_label),
                      y1 - half_font_height, self.axis_color)
예제 #5
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)
예제 #6
0
def draw_graph(resp, timeStart, timeEnd):
    # Coloured background for high/low areas
    lcd.rect(0, SCREEN_HEIGHT - GRAPH_HEIGHT, GRAPH_WIDTH,
             GRAPH_HEIGHT - WARN_HIGH_Y, YELLOW, YELLOW)
    lcd.rect(0, SCREEN_HEIGHT - WARN_LOW_Y, GRAPH_WIDTH, WARN_LOW_Y, RED, RED)

    # Prints lines between graph sections.
    # lcd.line(0, SCREEN_HEIGHT - GRAPH_HEIGHT, GRAPH_WIDTH, SCREEN_HEIGHT - GRAPH_HEIGHT)
    # lcd.line(0, SCREEN_HEIGHT - WARN_HIGH_Y, GRAPH_WIDTH, SCREEN_HEIGHT - WARN_HIGH_Y)
    # lcd.line(0, SCREEN_HEIGHT - WARN_LOW_Y, GRAPH_WIDTH, SCREEN_HEIGHT - WARN_LOW_Y)

    for idx, point in enumerate(resp):
        x = round(GRAPH_WIDTH * (int(point["date"] / 1000) - timeStart) /
                  (timeEnd - timeStart))
        y = round(min(point["sgv"] / GRAPH_MAX, 1.0) * GRAPH_HEIGHT)
        lcd.circle(x, SCREEN_HEIGHT - y, 3, BLACK, BLACK)
예제 #7
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()
예제 #8
0
    def update(self):
        def needle(n, m, deg, l, color):
            for i in range(n, n + m):
                if deg >= 315 or deg < 45 or deg >= 135 and deg < 225:
                    x, y = i, 0
                else:
                    x, y = 0, i
                lcd.lineByAngle(self.center_x + x, self.center_y + y, 0, l,
                                deg, color)

        # 時分秒の各針の角度を計算
        (year, month, mday, hour, minute, second, weekday,
         yearday) = time.localtime()
        second_deg = second * 6
        minute_deg = minute * 6 + second_deg // 60
        hour_deg = hour % 12 * 30 + minute_deg // 12

        # 時針の消去(角度が変わっていないときは消さない)
        if hour_deg != self.hour_deg:
            needle(-2, 4, self.hour_deg, int(self.h / 2 * 0.3), lcd.WHITE)
        # 分針の消去(角度が変わっていないときは消さない)
        if minute_deg != self.minute_deg:
            needle(-1, 2, self.minute_deg, int(self.h / 2 * 0.45), lcd.WHITE)
        # 秒針の消去
        needle(0, 1, self.second_deg, int(self.h / 2 * 0.6), lcd.WHITE)

        self.second_deg = second_deg
        self.minute_deg = minute_deg
        self.hour_deg = hour_deg

        # 時針の描画(4本線)
        needle(-2, 4, hour_deg, int(self.h / 2 * 0.3), lcd.BLACK)
        # 分針の描画(2本線)
        needle(-1, 2, minute_deg, int(self.h / 2 * 0.45), lcd.BLACK)
        # 秒針の描画(1本線)
        needle(0, 1, self.second_deg, int(self.h / 2 * 0.6), lcd.RED)
        # 中心に赤丸
        lcd.circle(self.center_x, self.center_y, 3, lcd.RED, lcd.RED)
예제 #9
0
from m5stack import lcd

# LCD

# setup
lcd.clear(0xC70039)
lcd.fill(0x222222)

# lcd.arc(0, 0, 10, 30, 40, 0)
lcd.circle(290, 150, 20)
lcd.ellipse(260, 50, 10, 10) #comment
# lcd.font(lcd.FONT_Comic) // not working
# fontSize = lcd.fontSize(); // not working
lcd.line(10, 100, 50, 40)
lcd.lineByAngle(100, 100, 5, 50, 180)
lcd.pixel(200, 200, 0xAABBFF)
# lcd.polygon(10, 10, 30, 30, 10)
# comment
lcd.print('hello world', 130, 50)
lcd.rect(50, 100, 150, 100, 0xEEFFFF)
lcd.triangle(200, 0, 10, 20, 50, 80, 0xFFFFFF) 

예제 #10
0
from machine import I2C
from mpu9250 import MPU9250
import time

i2c = I2C(sda=21, scl=22)
sensor = MPU9250(i2c)

lcd.clear()

x, y = 0, 0

while True:
    ax, ay, az = sensor.acceleration
    ax = ax * -1  # original is left negative

    # clear previous ball
    lcd.circle(x, y, 5, lcd.BLACK, lcd.BLACK)

    # g-bowl
    lcd.circle(160, 120, 110, lcd.WHITE)
    lcd.circle(160, 120, 55, lcd.WHITE)
    lcd.line(50, 120, 270, 120, lcd.WHITE)
    lcd.line(160, 10, 160, 230, lcd.WHITE)

    # plot ball
    x = int(ax * (55 / 10)) + 160
    y = int(ay * (55 / 10)) + 120
    lcd.circle(x, y, 5, lcd.RED, lcd.RED)

    time.sleep_ms(20)