コード例 #1
0
def drawweather(r):
    dayweather = r.get("weatherday")
    xline = 106
    xday = 115
    xevening = 5

    if (utime.localtime()[3] > 12):
        dayweather = dayweather[1]
    else:
        dayweather = dayweather[0]
        xline = 190
        xevening = 199
        xday = 5

    ugfx.thickline(xline, 0, xline, 68, ugfx.BLACK, 3, 0)

    try:
        ugfx.string(xevening + 37, 6, "17:00", "DejaVuSans20", ugfx.BLACK)
        ugfx.string(
            xevening + 37, 38,
            str(int(r.get("weatherevening").get("precipProbability") * 100)) +
            "%", "DejaVuSans20", ugfx.BLACK)

        ugfx.string(xday + 37, 22,
                    "WS:" + str(int(dayweather.get("windSpeed"))) + "mph",
                    "DejaVuSans20", ugfx.BLACK)
        sunup = utime.localtime(int(dayweather.get("sunriseTime")))
        sundown = utime.localtime(int(dayweather.get("sunsetTime")))
        ugfx.string(
            xday + 37, 44, "S:" + str(sunup[3]) + ":" + str(sunup[4]) + "-" +
            str(sundown[3]) + ":" + str(sundown[4]), "DejaVuSans20",
            ugfx.BLACK)
        ugfx.string(
            xday + 37, 0,
            "Temp:" + str(int(dayweather.get("apparentTemperatureLow"))) +
            "-" + str(int(dayweather.get("apparentTemperatureHigh"))) +
            u"\u00b0" + "C", "DejaVuSans20", ugfx.BLACK)
    except:
        print("missing precip chance")

    first = ""
    second = ""
    try:
        first = weathericon(r.get("weatherevening"), xevening, 16)
        second = weathericon(dayweather, xday, 16)
    except:
        print("no weather")

    return (first, second)
コード例 #2
0
 def draw(self):
     if not self.crashing:
         self.crashing = not (pyb.rng() % 500)
     ugfx.area(self.x-QUADCOPTER_BODY_SIZE, self.y-QUADCOPTER_BODY_SIZE, QUADCOPTER_BODY_SIZE*2, QUADCOPTER_BODY_SIZE*2, self.color)
     self.animation_frame += 1
     self.animation_frame %= 4
     for armature_x, armature_y in (
         (-QUADCOPTER_BODY_SIZE*3, -QUADCOPTER_BODY_SIZE*2),
         (QUADCOPTER_BODY_SIZE*3, -QUADCOPTER_BODY_SIZE*2),
         (-QUADCOPTER_BODY_SIZE*3, QUADCOPTER_BODY_SIZE*2),
         (QUADCOPTER_BODY_SIZE*3, QUADCOPTER_BODY_SIZE*2)
     ):
         rotor_center_x = self.x + armature_x
         rotor_center_y = self.y + armature_y
         ugfx.thickline(rotor_center_x, rotor_center_y, self.x, self.y, self.color, 2, False)
         if self.animation_frame == 0:
             ugfx.line(rotor_center_x - int(QUADCOPTER_BODY_SIZE*0.7), rotor_center_y - int(QUADCOPTER_BODY_SIZE*0.7), rotor_center_x + int(QUADCOPTER_BODY_SIZE*0.7), rotor_center_y + int(QUADCOPTER_BODY_SIZE*0.7), ugfx.BLACK)
         elif self.animation_frame == 1:
             ugfx.line(rotor_center_x, rotor_center_y - QUADCOPTER_BODY_SIZE, rotor_center_x, rotor_center_y + QUADCOPTER_BODY_SIZE, ugfx.BLACK)
         elif self.animation_frame == 2:
             ugfx.line(rotor_center_x + int(QUADCOPTER_BODY_SIZE*0.7), rotor_center_y - int(QUADCOPTER_BODY_SIZE*0.7), rotor_center_x - int(QUADCOPTER_BODY_SIZE*0.7), rotor_center_y + int(QUADCOPTER_BODY_SIZE*0.7), ugfx.BLACK)
         elif self.animation_frame == 3:
             ugfx.line(rotor_center_x + QUADCOPTER_BODY_SIZE, rotor_center_y, rotor_center_x - QUADCOPTER_BODY_SIZE, rotor_center_y, ugfx.BLACK)
     draw_crosshair(crosshair_x, crosshair_y)
コード例 #3
0
ファイル: main.py プロジェクト: liedra/adventure-emf
def room_1():
	### Room 1 - exit north
	room=1
	
	ugfx.clear(ugfx.BLACK)
	setup_right_menu()
	
	build_room_walls(1,0,0,0)

	
	#corridor N
	ugfx.thickline(90,34,90,0,ugfx.WHITE,7,0)
	ugfx.thickline(110,34,110,0,ugfx.WHITE,7,0)

	#door
	ugfx.thickline(90,180,110,180,ugfx.BLUE,7,0)
	#PC
	ugfx.fill_circle(100,150,5,ugfx.YELLOW)
コード例 #4
0
def draw_hand(cx, cy, angle, length, thickness, color):
    x = int(math.cos(angle) * length + cx);
    y = int(math.sin(angle) * length + cy);
    ugfx.thickline(cx, cy, x, y, color, thickness, 1)
コード例 #5
0
ファイル: main.py プロジェクト: liedra/adventure-emf
def build_room_walls(north, east, south, west):
	#0 closed 1 open
	if north==0:
		ugfx.thickline(6,30,183,30,ugfx.WHITE,7,0)
	if north==1:
		ugfx.thickline(6,30,90,30,ugfx.WHITE,7,0)
		ugfx.thickline(110,30,183,30,ugfx.WHITE,7,0)
	if east==0:
		ugfx.thickline(180,30,180,180,ugfx.WHITE,7,0)
	if east==1:
		ugfx.thickline(180,27,180,100,ugfx.WHITE,7,0)
		ugfx.thickline(180,120,180,180,ugfx.WHITE,7,0)	
	if south==0:
		ugfx.thickline(6,180,183,180,ugfx.WHITE,7,0)
	if south==1:
		ugfx.thickline(10,176,90,176,ugfx.WHITE,7,0)
		ugfx.thickline(110,176,180,176,ugfx.WHITE,7,0)
	if west==0:
		ugfx.thickline(10,30,10,180,ugfx.WHITE,7,0)
	if west==1:
		ugfx.thickline(10,27,10,100,ugfx.WHITE,7,0)
		ugfx.thickline(10,120,10,180,ugfx.WHITE,7,0)
コード例 #6
0
import ugfx
import time

ugfx.init()

ugfx.clear(ugfx.BLACK)

ugfx.fill_circle(60, 60, 50, ugfx.WHITE)
ugfx.fill_circle(60, 60, 40, ugfx.BLACK)
ugfx.fill_circle(60, 60, 30, ugfx.WHITE)
ugfx.fill_circle(60, 60, 20, ugfx.BLACK)
ugfx.fill_circle(60, 60, 10, ugfx.WHITE)

ugfx.thickline(1, 1, 100, 100, ugfx.WHITE, 10, 5)
ugfx.box(30, 30, 50, 50, ugfx.WHITE)

ugfx.string(150, 25, "STILL", "Roboto_BlackItalic24", ugfx.WHITE)
ugfx.string(130, 50, "Hacking", "PermanentMarker22", ugfx.WHITE)
len = ugfx.get_string_width("Hacking", "PermanentMarker22")
ugfx.line(130, 72, 144 + len, 72, ugfx.WHITE)
ugfx.line(140 + len, 52, 140 + len, 70, ugfx.WHITE)
ugfx.string(140, 75, "Anyway", "Roboto_BlackItalic24", ugfx.WHITE)

ugfx.flush()


def render(text, pushed):
    if (pushed):
        ugfx.string(100, 10, text, "PermanentMarker22", ugfx.WHITE)
    else:
        ugfx.string(100, 10, text, "PermanentMarker22", ugfx.BLACK)
コード例 #7
0
i2c = I2C(sda=Pin(26), scl=Pin(27), freq=100000)
sgp30 = SGP30(i2c)
history = [(0, 0)] * BADGE_EINK_WIDTH

while True:
    measurement = sgp30.air_quality()
    print(measurement)
    co2_ppm = measurement['co2_ppm']
    tvoc_ppb = measurement['tvoc_ppb']

    log_max = math.log(60000)
    co2_y = int(math.log(max(co2_ppm, 1)) / log_max * 64)
    tvoc_y = int(math.log(max(tvoc_ppb, 1)) / log_max * 64)
    _ = history.pop(0)
    history.append((co2_y, tvoc_y))

    ugfx.clear(ugfx.WHITE)
    ugfx.line(0, 64, BADGE_EINK_WIDTH, 64, ugfx.BLACK)
    ugfx.string(0, 0, 'eCO2: %d ppm' % co2_ppm, 'Roboto_Regular18', ugfx.BLACK)
    ugfx.string(0, 64, 'TVOC: %d ppb' % tvoc_ppb, 'Roboto_Regular18',
                ugfx.BLACK)

    for (x, (a, b)) in enumerate(zip(history, history[1:])):
        ugfx.thickline(x, 64 - a[0], x + 1, 64 - b[0], ugfx.BLACK, 2, 0)
        ugfx.thickline(x, (64 - a[1]) + 64, x + 1, (64 - b[1]) + 64,
                       ugfx.BLACK, 2, 0)

    ugfx.flush()

    time.sleep(1)
コード例 #8
0
def draw(r):
    # Rows: 32

    infoLine = None

    try:
        title = r.get("dates").get("summary")
        time = r.get("dates").get("start").get("dateTime")[11:16]
        infoLine = time + " - " + title
    except:
        print("no cal")

    try:
        if infoLine is None:
            infoLine = r.get("news")
    except:
        print("no news")

    try:
        if infoLine is None:
            infoLine = r.get("other")
    except:
        print("no other")

    if infoLine is not None:
        font = "DejaVuSans20"
        if (ugfx.get_string_width(infoLine, "DejaVuSans20") > 592):
            font = "Roboto_Regular12"

        firstLine = infoLine
        while (ugfx.get_string_width(firstLine, font) > 296):
            firstLine = firstLine[:-1]

        secondLine = None
        # Check for second line
        if len(firstLine) != len(infoLine):
            secondLine = infoLine[len(firstLine):]
            while (ugfx.get_string_width(secondLine, font) > 296):
                secondLine = secondLine[:-1]
            if font == "Roboto_Regular12":
                ugfx.string(2, 82, secondLine, font, ugfx.BLACK)
            else:
                ugfx.string(2, 90, secondLine, font, ugfx.BLACK)

        # Third line
        if font == "Roboto_Regular12":
            if (len(firstLine) + len(secondLine)) != len(infoLine):
                ugfx.string(2, 94, infoLine[len(firstLine) + len(secondLine):],
                            font, ugfx.BLACK)

        singleLineOffset = 0
        if secondLine is None:
            singleLineOffset += 10

        ugfx.string(2, 70 + singleLineOffset, firstLine, font, ugfx.BLACK)

    try:
        ugfx.string(2, 110, "£" + str(r.get("bank")), "DejaVuSans20",
                    ugfx.BLACK)
    except:
        print("no balance")

    ugfx.thickline(0, 68, 296, 68, ugfx.BLACK, 3, 0)

    boxes = drawweather(r)

    ugfx.flush()

    try:
        boxes[0].destroy()
        boxes[1].destroy()
    except:
        print("no weather")