def barometer(offset, reading): p = (max(950, min(1050, reading.pressure)) - 950) / 100 * 64 screen = array([ Color('green') if i < int(p) else Color('green') * Green(p - int(p)) if i < p else Color('black') for i in range(64) ]) screen = np.flipud(screen) text = image_to_rgb(draw_text(int(round(reading.pressure)), 'small.pil', foreground=Color('gray'), padding=(0, 0, 8, 3))) screen[:text.shape[0], :] += text[:, offset:offset + 8] return screen.clip(0, 1)
def thermometer(offset, reading): t = max(0, min(50, reading.temperature)) / 50 * 64 screen = array([ Color('red') if i < int(t) else Color('red') * Red(t - int(t)) if i < t else Color('black') for i in range(64) ]) screen = np.flipud(screen) text = image_to_rgb(draw_text(int(round(reading.temperature)), 'small.pil', foreground=Color('gray'), padding=(0, 0, 0, 3))) screen[:text.shape[0], :text.shape[1]] += text return screen.clip(0, 1)
def hygrometer(offset, reading): h = reading.humidity / 100 * 64 screen = array([ Color('#008') if i < int(h) else Color('#008') * Blue(h - int(h)) if i < h else Color('black') for i in range(64) ]) screen = np.flipud(screen) text = image_to_rgb(draw_text('^^' if reading.humidity > 99 else int(round(reading.humidity)), 'small.pil', foreground=Color('gray'), padding=(0, 0, 0, 3))) screen[:text.shape[0], :text.shape[1]] += text return screen.clip(0, 1)