def runThreadFunc(self): offscreen_canvas = self.matrix.CreateFrameCanvas() fontUP = graphics.Font() fontDOWN = graphics.Font() fontUP.LoadFont("../rpi-rgb-led-matrix/fonts/korean2.bdf") fontDOWN.LoadFont("../rpi-rgb-led-matrix/fonts/korean2.bdf") textColorTop = graphics.Color(20, 10, 0) textColorBtm = graphics.Color(10, 30, 0) posTop = 0 posBtm = offscreen_canvas.width while True: offscreen_canvas.Clear() lengTop = graphics.DrawText(offscreen_canvas, fontUP, posTop, 12, textColorTop, self.msgctrltower.get_msg()) lengBtm = graphics.DrawText(offscreen_canvas, fontDOWN, posBtm, 27, textColorBtm, mybook.get_msg()) if (lengTop < offscreen_canvas.width): posTop = (offscreen_canvas.width - lengTop) / 2 if (lengTop >= offscreen_canvas.width): posTop -= 1 if (posTop + lengTop < 0): posTop = offscreen_canvas.width posBtm -= 1 if (posBtm + lengBtm < 0): posBtm = offscreen_canvas.width mybook.go_next() time.sleep(0.03) offscreen_canvas = self.matrix.SwapOnVSync(offscreen_canvas)
def run(self): offscreen_canvas = self.matrix.CreateFrameCanvas() font = graphics.Font() font.LoadFont("fonts/10x20.bdf") textColorR = graphics.Color(255, 0, 0) textColorG = graphics.Color(0, 255, 0) textColorB = graphics.Color(0, 0, 255) pos = offscreen_canvas.width my_text = "Hallo Tante Dorli! :-)" counter = 0 while True: offscreen_canvas.Clear() if counter % 60 < 20: textColor = textColorR elif counter % 60 < 40: textColor = textColorG elif counter % 60 < 60: textColor = textColorB counter += 1 len = graphics.DrawText(offscreen_canvas, font, pos, 20, textColor, my_text) pos -= 1 if (pos + len < 0): pos = offscreen_canvas.width time.sleep(0.03) offscreen_canvas = self.matrix.SwapOnVSync(offscreen_canvas)
def __init__(self, lx, rx, symoffset, font, defaulttextcolor, symdict, bgcolor_t=None, initial_pretext=2, initial_posttext=5, pretext_zero_if_no_symbol=True, add_end_spacer=True, last_char_separated=False, fixedy: Optional[int] = None): # attributes self.lx = lx self.rx = rx self.symoffset = symoffset self.font = font self.defaulttextcolor = defaulttextcolor self.symdict = symdict self.bgcolor = graphics.Color(*bgcolor_t) if bgcolor_t else graphics.Color() self.initial_posttext = initial_posttext self.initial_pretext = initial_pretext self.pretext_zero_if_no_symbol = pretext_zero_if_no_symbol self.add_end_spacer = add_end_spacer self.last_char_separated = last_char_separated self.fixedy = fixedy # self.staticleftsymtextspacing = staticleftsymtextspacing # self.forcescroll = forcescroll # self.noscroll = noscroll # state self.meldungs: List[Meldung] = [] self.elements: List[MultisymbolScrollline.__Element] = [] self.currfirstelemi = None self.currlastelemi = None self.shownelems = 0 self.startpos = rx
def run(self): offscreen_canvas = self.matrix.CreateFrameCanvas() font = graphics.Font() font_date = graphics.Font() font.LoadFont("./a-otf24.bdf") font_date.LoadFont("./a-otf20.bdf") textColor = graphics.Color(245, 0, 111) timeColor = graphics.Color(61, 147, 215) pos = offscreen_canvas.width my_text = self.args.text start = time.time() while True: if (time.time() - start) > 30: exit() else: d = datetime.now() h = (" " + str(d.hour))[-2:] date_text = d.strftime("%a %m.%d") time_text = d.strftime("%H:%M:%S") offscreen_canvas.Clear() len = graphics.DrawText(offscreen_canvas, font_date, 4, 24, textColor, date_text) len1 = graphics.DrawText(offscreen_canvas, font, 4, 56, timeColor, time_text) offscreen_canvas = self.matrix.SwapOnVSync(offscreen_canvas)
def drawScreen(self): canvas = self.matrix.CreateFrameCanvas() if not (self.alarmInstance.alarmActive): canvas.Clear() self.displayClock( canvas, graphics.Color(self.alarmDB.time_red, self.alarmDB.time_green, self.alarmDB.time_blue), self.alarmDB.time_record["position"]) self.displayWeather( canvas, self.weather.weatherString, graphics.Color(self.alarmDB.weather_red, self.alarmDB.weather_green, self.alarmDB.weather_blue), self.alarmDB.weather_record["position"]) self.displayText( canvas, self.alarmDB.text_record["text"], graphics.Color(self.alarmDB.text_red, self.alarmDB.text_green, self.alarmDB.text_blue), 3, self.alarmDB.text_record["position"]) self.displayDate( canvas, graphics.Color(self.alarmDB.date_red, self.alarmDB.date_green, self.alarmDB.date_blue), self.alarmDB.date_record["position"]) self.displayNextAlarmTime( canvas, graphics.Color(self.alarmDB.nextalarm_red, self.alarmDB.nextalarm_green, self.alarmDB.nextalarm_blue), self.alarmDB.nextalarm_record["position"]) else: self.matrix.Fill(255, 0, 0) canvas = self.matrix.SwapOnVSync(canvas)
def run(options): """run the countdown clock""" matrix = RGBMatrix(options=options) offscreen_canvas = matrix.CreateFrameCanvas() font = graphics.Font() font.LoadFont("rpi-rgb-led-matrix/fonts/9x18B.bdf") time_color = graphics.Color(255, 217, 25) co2_color = graphics.Color(153, 0, 230) while True: offscreen_canvas.Clear() # calculate remaining seconds and co2 now = datetime.now() seconds_since_start = (now - START_DATE).total_seconds() remaining_co2 = START_BUDGET - seconds_since_start * TONS_PER_SEC remaining_seconds = remaining_co2 / TONS_PER_SEC # format text remaining_time_text = seconds_to_timestring(remaining_seconds) remaining_co2_text = "{:,} TONS".format(int(remaining_co2)) # draw to screen graphics.DrawText(offscreen_canvas, font, 1, 14, time_color, remaining_time_text) graphics.DrawText(offscreen_canvas, font, 1, 28, co2_color, remaining_co2_text) offscreen_canvas = matrix.SwapOnVSync(offscreen_canvas) time.sleep(PAUSE)
def draw_a(self, location, canvas): if location == 'top': text_offset = 0 circle_offset = 2 else: text_offset = 15 circle_offset = 17 blue = graphics.Color(0, 57, 166) black = graphics.Color(0, 0, 0) white = graphics.Color(255, 255, 255) yellow = graphics.Color(252, 204, 10) self.drawCircle(canvas, circle_offset, blue) graphics.DrawLine(canvas, 7, 7 + text_offset, 7, 11 + text_offset, white) graphics.DrawLine(canvas, 11, 7 + text_offset, 11, 11 + text_offset, white) graphics.DrawLine(canvas, 8, 6 + text_offset, 8, 6 + text_offset, white) graphics.DrawLine(canvas, 9, 5 + text_offset, 9, 5 + text_offset, white) graphics.DrawLine(canvas, 10, 6 + text_offset, 10, 6 + text_offset, white) graphics.DrawLine(canvas, 8, 9 + text_offset, 10, 9 + text_offset, white)
def run(self): offscreen_canvas = self.matrix.CreateFrameCanvas() font = graphics.Font() font.LoadFont(os.path.join(FONTS_PATH, "5x8.bdf")) green_color = graphics.Color(0, 128, 0) red_color = graphics.Color(255, 0, 0) btc_price_old = 0 eth_price_old = 0 coinbase = Coinbase() while True: offscreen_canvas.Clear() btc_price = coinbase.ticker('BTC-USD')['bid'] eth_price = coinbase.ticker('ETH-USD')['bid'] if btc_price > btc_price_old: btc_color = green_color else: btc_color = red_color if eth_price > eth_price_old: eth_color = green_color else: eth_color = red_color btc_price_old = btc_price eth_price_old = eth_price graphics.DrawText(offscreen_canvas, font, 2, 12, btc_color, f"BTC:{btc_price}") graphics.DrawText(offscreen_canvas, font, 2, 24, eth_color, f"ETH:{eth_price}") offscreen_canvas = self.matrix.SwapOnVSync(offscreen_canvas)
def color(self): if(self.sign == "u"): self.color = graphics.Color(0,255,0) elif(self.sign == "d"): self.color = graphics.Color(255,0,0) else: self.color = graphics.Color(0,0,255)
def __render_team_text(self): away_team = self.scoreboard.game_data['away_team'] away_text_color = self.colors[away_team.lower()].get( 'text', { 'r': 255, 'g': 255, 'b': 255 }) away_text_color_graphic = graphics.Color(away_text_color['r'], away_text_color['g'], away_text_color['b']) away_text = '{:3s}'.format(away_team.upper()) + ' ' + str( self.scoreboard.game_data['inning']['at_bat']['away_team_runs']) home_team = self.scoreboard.game_data['home_team'] home_text_color = self.colors[home_team.lower()].get( 'text', { 'r': 255, 'g': 255, 'b': 255 }) home_text_color_graphic = graphics.Color(home_text_color['r'], home_text_color['g'], home_text_color['b']) home_text = '{:3s}'.format(home_team.upper()) + ' ' + str( self.scoreboard.game_data['inning']['at_bat']['home_team_runs']) graphics.DrawText(self.canvas, self.font, 1, 6, away_text_color_graphic, away_text) graphics.DrawText(self.canvas, self.font, 1, 13, home_text_color_graphic, home_text)
def __init__(self, rootView, defaults=None): self.__rootView__ = rootView if defaults == None: #set default values here defaults = { "homeScore": "00", "awayScore": "00", "eventColor": { "R": 0, "G": 255, "B": 255 }, "heatColor": { "R": 0, "G": 255, "B": 255 }, } # Views self.eventLabel = RGBLabel(self.__rootView__, 0, 0, "EVENT") self.eventScore = RGBLabel(self.__rootView__, 0, 12, defaults["awayScore"], TextStyle.IMAGE) self.heatLabel = RGBLabel(self.__rootView__, 63, 0, "HEAT") self.heatScore = RGBLabel(self.__rootView__, 60, 12, defaults["homeScore"], TextStyle.IMAGE) defEvent = defaults["eventColor"] defHeat = defaults["heatColor"] self.eventLabel.setColor( graphics.Color(defEvent["R"], defEvent["G"], defEvent["B"])) self.heatLabel.setColor( graphics.Color(defHeat["R"], defHeat["G"], defHeat["B"]))
def Run(self): offscreenCanvas = self.matrix.CreateFrameCanvas() font = graphics.Font() font.LoadFont("/home/pi/rgb-led-array-stuff/fonts/7x13.bdf") randomRed = random.randint(0,255) randomBlue = random.randint(0,255) randomGreen = random.randint(0,255) textColor = graphics.Color(randomRed, randomBlue, randomGreen) pos = offscreenCanvas.width #myText = time.strftime ('%l:%M%p')#self.args["text"] height = random.randint(10,32) while True: offscreenCanvas.Clear() len = graphics.DrawText(offscreenCanvas, font, pos, height, textColor, time.strftime ('%l:%M %p %b %d')) pos -= 1 if (pos + len < 0): pos = offscreenCanvas.width height = random.randint(10,32) randomRed = random.randint(0,255) randomBlue = random.randint(0,255) randomGreen = random.randint(0,255) textColor = graphics.Color(randomRed, randomBlue, randomGreen) time.sleep(0.10) offscreenCanvas = self.matrix.SwapOnVSync(offscreenCanvas)
def set_alerts(self, matrix, pos, spotted_bird): font = self.__load_font() bird_time = self.__parse_date(spotted_bird) textColor = graphics.Color(255, 255, 255) # time of spot graphics.DrawText(matrix, font, 32, 7, graphics.Color(255, 255, 255), bird_time) # type of bird bird_length = graphics.DrawText( matrix, font, pos, 20, graphics.Color(255, 255, 255), spotted_bird.bird_name ) # location bird_loc = graphics.DrawText( matrix, font, pos, 30, textColor, spotted_bird.bird_loc ) pos -= 1 time.sleep(0.05) total_length = self.__clean_scroll(bird_length, bird_loc) return pos, total_length
def run(self): canvas = self.matrix font = graphics.Font() font.LoadFont("../../../fonts/5x8.bdf") blue = graphics.Color(0, 0, 255) red = graphics.Color(255, 0, 0) redcolor = graphics.Color(255,0,0) greencolor = graphics.Color(0, 255, 0) while asd == True: try: graphics.DrawText(canvas, font, 11, 7, redcolor, subwaytimeslist[0]) graphics.DrawText(canvas, font, 11, 15, greencolor, subwaytimeslist[1]) graphics.DrawText(canvas, font, 11, 23, redcolor, subwaytimeslist[2]) graphics.DrawText(canvas, font, 11, 31, greencolor, subwaytimeslist[3]) except: canvas.Clear() graphics.DrawText(canvas, font, 11, 7, redcolor, "Error") graphics.DrawText(canvas, font, 11, 15, redcolor, "Connecting") graphics.DrawText(canvas, font, 11, 23, redcolor, "To Server") # graphics.DrawText(canvas, font, 42, 16, blue, "RAWR") # graphics.DrawText(canvas, font, 42, 25, blue, "XC") subwaytimeslist.clear() try: runall() time.sleep(10) canvas.Clear() except (KeyboardInterrupt, SystemExit): raise except: canvas.Clear() graphics.DrawText(canvas, font, 11, 7, redcolor, "Error") graphics.DrawText(canvas, font, 11, 15, redcolor, "Connecting") graphics.DrawText(canvas, font, 11, 23, redcolor, "To Server")
def draw_m(self, location, canvas): if location == 'top': text_offset = 0 circle_offset = 2 else: text_offset = 15 circle_offset = 17 orange = graphics.Color(255, 99, 25) black = graphics.Color(0, 0, 0) self.drawCircle(canvas, circle_offset, orange) graphics.DrawLine(canvas, 6, 5 + text_offset, 6, 11 + text_offset, black) graphics.DrawLine(canvas, 12, 5 + text_offset, 12, 11 + text_offset, black) graphics.DrawLine(canvas, 7, 6 + text_offset, 7, 6 + text_offset, black) graphics.DrawLine(canvas, 8, 7 + text_offset, 8, 7 + text_offset, black) graphics.DrawLine(canvas, 9, 8 + text_offset, 9, 8 + text_offset, black) graphics.DrawLine(canvas, 10, 7 + text_offset, 10, 7 + text_offset, black) graphics.DrawLine(canvas, 11, 6 + text_offset, 11, 6 + text_offset, black)
def display_time_remaining(self, primary_time_remaining, secondary_time_remaining=None): self.offscreen_canvas.Clear() # Set the default Y offset for primary timer to middle of display outTextPrimaryYOffset = 27 # Display Secondary timer (if one is set) if secondary_time_remaining is not None: outTextSecondary = self.format_time_remaining( secondary_time_remaining, True) #outTextSecondary = " " + outTextSecondary textColor = graphics.Color(128, 0, 0) graphics.DrawText(self.offscreen_canvas, self.fontSmall, 4, 31, textColor, outTextSecondary) # We change the Y offset of primary timer to top of display to leave room for secondary timer outTextPrimaryYOffset = 22 # Display Primary Timer outTextPrimary = self.format_time_remaining(primary_time_remaining) textColor = graphics.Color(255, 0, 0) graphics.DrawText(self.offscreen_canvas, self.font, 2, outTextPrimaryYOffset, textColor, outTextPrimary) self.offscreen_canvas = self.matrix.SwapOnVSync(self.offscreen_canvas)
def __init__(self, chain=4, bright=50): #デフォルト設定(引数なしの場合) #Options self.options = RGBMatrixOptions() self.options.rows = 32 self.options.chain_length = chain self.options.parallel = 1 self.options.hardware_mapping = 'adafruit-hat-pwm' self.options.brightness = bright self.options.show_refresh_rate = 0 self.matrix = RGBMatrix(options=self.options) self.canvas = self.matrix.CreateFrameCanvas() # 時計用フォント読み込み self.clcfont = graphics.Font() self.clcfont.LoadFont("Resources/Metroclock.bdf") #LED長さ self._width = self.canvas.width self._height = self.canvas.height #Colors self.orange = graphics.Color(255, 110, 0) self.blue = graphics.Color(0, 220, 255) self.white = graphics.Color(255, 255, 255) self.red = graphics.Color(255, 0, 0) self.green = graphics.Color(0, 255, 0) #ループ制御用変数 self.stopper = False
def run(self): offscreen_canvas = self.matrix.CreateFrameCanvas() font = graphics.Font() font_time = graphics.Font() #font.LoadFont("../../../fonts/mplus_h12r.bdf") font_time.LoadFont("./fonts/21-Adobe-Helvetica.bdf") #font.LoadFont("../../../fonts/15-Adobe-Helvetica.bdf") font.LoadFont("./fonts/16-Adobe-Helvetica-Bold.bdf") textColor = graphics.Color(245, 0, 111) timeColor = graphics.Color(61, 147, 215) pos = offscreen_canvas.width my_text = self.args.text while True: d = datetime.now() h = (" " + str(d.hour))[-2:] #スペースを頭に着けて最後から2文字背取得。1-9時の間も真ん中に時計が表示されるようにする考慮 #date_text = d.strftime("%a %b %d %Y") date_text = d.strftime("%a %m.%d") time_text = d.strftime("%H:%M") #logger.debug(my_text) offscreen_canvas.Clear() len = graphics.DrawText(offscreen_canvas, font, 0, 14, textColor, date_text) len1 = graphics.DrawText(offscreen_canvas, font_time, 7, 30, timeColor, time_text) #time.sleep(60) offscreen_canvas = self.matrix.SwapOnVSync(offscreen_canvas)
def draw_4(self, location, canvas): if location == 'top': text_offset = 0 circle_offset = 2 else: text_offset = 15 circle_offset = 17 green = graphics.Color(0, 120, 60) white = graphics.Color(255, 255, 255) self.drawCircle(canvas, circle_offset, green) graphics.DrawLine(canvas, 10, 5 + text_offset, 10, 5 + text_offset, white) graphics.DrawLine(canvas, 9, 6 + text_offset, 10, 6 + text_offset, white) graphics.DrawLine(canvas, 8, 7 + text_offset, 8, 7 + text_offset, white) graphics.DrawLine(canvas, 10, 7 + text_offset, 10, 7 + text_offset, white) graphics.DrawLine(canvas, 7, 8 + text_offset, 7, 8 + text_offset, white) graphics.DrawLine(canvas, 10, 8 + text_offset, 10, 8 + text_offset, white) graphics.DrawLine(canvas, 7, 9 + text_offset, 11, 9 + text_offset, white) graphics.DrawLine(canvas, 10, 10 + text_offset, 10, 10 + text_offset, white) graphics.DrawLine(canvas, 10, 11 + text_offset, 10, 11 + text_offset, white)
def __init__(self): threading.Thread.__init__(self) # Setup GPIO buttons GPIO.setwarnings(False) GPIO.setmode(GPIO.BCM) GPIO.setup(SENSOR, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(UP, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(DOWN, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(SOUND, GPIO.IN, pull_up_down=GPIO.PUD_UP) self.font_day = graphics.Font() self.font_day.LoadFont(BASE_DIR + "fonts/4x6.bdf") self.font_time = graphics.Font() self.font_time.LoadFont(BASE_DIR + "fonts/5x8.bdf") self.color_day = graphics.Color(255, 179, 0) self.color_time = graphics.Color(154, 240, 0) self.color_pixel = graphics.Color(0, 149, 67) self.font_alarm = graphics.Font() self.font_alarm.LoadFont(BASE_DIR + "fonts/7x13.bdf") self.color_alarm = graphics.Color(234, 0, 52) self.color_alarm_colon = graphics.Color(255, 130, 42) self.player = Player() self.alarm = Alarm(7, 30, self.player) self.done = False return
def run(self): font_size_key = "7x13" font_size_val = "9x15B" font_size_small = "6x10" offscreen_canvas = self.matrix.CreateFrameCanvas() font_key = graphics.Font() font_key.LoadFont("../../../fonts/{}.bdf".format(font_size_key)) font_val = graphics.Font() font_small = graphics.Font() font_small.LoadFont("../../../fonts/{}.bdf".format(font_size_small)) color_key = graphics.Color(255, 255, 255) color_val = graphics.Color(110, 255, 255) x_pos_key = 2 x_pos_val = offscreen_canvas.width # Temporary value. Will changed based on length of values # y_pos of each item in the list (only 2nd & 3rd row since 1st is for header) y_pos_list = [13, 28] while True: with open("data-files/data_keys.txt", 'r') as f: list_keys = f.readlines() with open("data-files/data_values.txt", 'r') as f: list_values = f.readlines() font_val.LoadFont("../../../fonts/{}.bdf".format(font_size_val)) for i in range(len(list_keys)): list_keys[i] = list_keys[i].replace("\n", "") for i in range(len(list_values)): list_values[i] = list_values[i].replace("\n", "") offscreen_canvas.Clear() # Light up keys length_key_1 = self.light_keys(offscreen_canvas, list_keys[2], font_key, font_small, x_pos_key, y_pos_list[0], color_key, 1) length_key_2 = self.light_keys(offscreen_canvas, list_keys[3], font_key, font_small, x_pos_key, y_pos_list[1], color_key, 2) # Light up borders self.light_borders(offscreen_canvas) # Light up values self.light_values(offscreen_canvas, font_val, font_small, color_val, list_values[2], x_pos_key, length_key_1, y_pos_list[0], 1) self.light_values(offscreen_canvas, font_val, font_small, color_val, list_values[3], x_pos_key, length_key_2, y_pos_list[1], 2) offscreen_canvas = self.matrix.SwapOnVSync(offscreen_canvas) time.sleep(0.05)
def draw_offday(self, font): for x in range(self.matrix.height): graphics.DrawLine(self.matrix, 0, x, self.matrix.width, x, graphics.Color(0, 0, 0)) nhl_logo_img = Image.open("nhl_logo.png") nhl_logo_img.thumbnail((self.matrix.height, self.matrix.height), Image.ANTIALIAS) self.matrix.SetImage(nhl_logo_img.convert('RGB')) graphics.DrawText(self.matrix, font, 40, 10, graphics.Color(255, 255, 255), "No") graphics.DrawText(self.matrix, font, 31, 17, graphics.Color(255, 255, 255), "games") graphics.DrawText(self.matrix, font, 40, 26, graphics.Color(255, 255, 255), ":(")
def __init__(self, *args, **kwargs): super(RunText, self).__init__(*args, **kwargs) self.parser.add_argument("-t", "--text", help="The text to scroll on the RGB LED panel", default="Hello world!") self.cryptoData = {} # Place your cryptos here self.cryptos = ['BTC', 'NYC', 'ETH', 'TRX', 'LTC'] self.blueColor = graphics.Color(4, 66, 165) self.greenColor = graphics.Color(0, 168, 36) self.redColor = graphics.Color(153, 6, 1)
def _draw(self, canvas): canvas.Clear() graphics.DrawText(canvas, self._font_large, 1, 13, self._white, time.strftime("%H:%M")) graphics.DrawText(canvas, self._font_small, 53, 13, self._pink, time.strftime("%S")) graphics.DrawText(canvas, self._font_small, 2, 22, self._green, time.strftime("%a %-d %b")) #Format to 2 digits and no subdigits sTempOutside = "%2.0f" % self._weather.TempOutside sTempInside = "%2.0f" % self._weather.TempInside #sHumidityOutside = "%2.0f" % self._weather.HumidityOutside sHumidityInside = "%2.0f" % self._weather.HumidityInside if self._weather.TempOutside > -10.0 and self._weather.TempOutside < 10.0: # temperature only one digit: move output to left (reduce space after 'A:')) self._posOffset = -7 else: self._posOffset = 0 graphics.DrawText(canvas, self._font_small, 1, 31, self._amber, "A") graphics.DrawText(canvas, self._font_tiny, 6, 31, self._amber, ":") graphics.DrawText(canvas, self._font_small, 16 + self._posOffset, 31, self._white, sTempOutside) graphics.DrawText(canvas, self._font_tiny, 28 + self._posOffset, 28, self._white, "o") graphics.DrawText(canvas, self._font_small, 39, 31, self._amber, "I") graphics.DrawText(canvas, self._font_tiny, 43, 31, self._amber, ":") if time.strftime("%S") not in ('09', '19', '29', '39', '49', '59', '08', '18', '28', '38', '48', '58'): # show temperature if self._weather.TempInside < 20.0 or self._weather.TempInside > 23.4: # red color if not in optimum range self._color_temp = graphics.Color(255, 0, 0) else: # optimum range is 20 ... 23 degrees Celsius self._color_temp = graphics.Color(255, 255, 255) graphics.DrawText(canvas, self._font_small, 47, 31, self._color_temp, sTempInside) graphics.DrawText(canvas, self._font_tiny, 59, 28, self._color_temp, "o") else: # show humidity if self._weather.HumidityInside < 40 or self._weather.HumidityInside > 60: # red color if not in optimum range self._color_humidity = graphics.Color(255, 0, 0) else: # optimum range is 40 ... 60 % self._color_humidity = graphics.Color(255, 255, 255) graphics.DrawText(canvas, self._font_small, 47, 31, self._color_humidity, sHumidityInside) graphics.DrawText(canvas, self._font_small, 59, 31, self._color_humidity, "%")
def drawStartScreen(self, startingPlayer): self.matrix.Clear() # show the start screen along with who is going first font = graphics.Font() font.LoadFont("./fonts/6x12.bdf") graphics.DrawText(self.matrix, font, 5, 25, graphics.Color(200, 200, 200), "Player {}".format(startingPlayer)) graphics.DrawText(self.matrix, font, 5, 60, graphics.Color(200, 200, 200), "starts")
def get_color(self, color_str): color_str = color_str.lower() if color_str == "white": return graphics.Color(255, 255, 255) elif color_str == "green": return graphics.Color(0, 255, 0) elif color_str == "red": return graphics.Color(255, 0, 0) elif color_str == "blue": return graphics.Color(0, 0, 255)
def render_ticker_canvas(self, symbol): key = symbol.replace('-', '').upper() if not key in self.data: return data = self.data[key] if not self.canvas: self.canvas = self.matrix.CreateFrameCanvas() self.canvas.Clear() priceChangePercent = float(data["change"]) price = float(data["price"]) prefix = '' if data['change'].startswith('-') else '+' change_width = sum([ self.fonts['change'].CharacterWidth(ord(c)) for c in f'{prefix}{priceChangePercent:.2f}' ]) change_x = 64 - change_width change_color = (graphics.Color(220, 47, 2) if data['change'].startswith('-') else graphics.Color( 0, 255, 0)) prefixes = ['K', 'M', 'B'] self.ctr += 1 n = self.refresh / 2 if self.ctr >= n: vol_txt = 'B:' + millify( data['vol'], precision=3, prefixes=prefixes) if self.ctr < n: vol_txt = 'Q:' + millify( data['qoute'], precision=3, prefixes=prefixes) if self.ctr == self.refresh: self.ctr = 0 graphics.DrawText(self.canvas, self.fonts['change'], change_x, 9, change_color, f'{prefix}{priceChangePercent:.2f}') graphics.DrawText(self.canvas, self.fonts['price'], 3, 20, graphics.Color(203, 243, 240), vol_txt) graphics.DrawText(self.canvas, self.fonts['symbol'], 3, 11, graphics.Color(255, 209, 102), symbol[0:3].upper()) graphics.DrawText(self.canvas, self.fonts['price'], 3, 30, change_color, f'{price:,.5f}') self.matrix.SwapOnVSync(self.canvas)
def run(self): global t0 canvas = self.matrix font = graphics.Font() font.LoadFont("fonts/5x8.bdf") #blue = graphics.Color(0, 0, 255) green = graphics.Color(0, 255, 0) red = graphics.Color(255, 0, 0) white = graphics.Color(100, 100, 100) orange = graphics.Color(255, 128, 0) brown = graphics.Color(102, 51, 0) #set_t0() get_t0() interval = 1 next_time = round(time.time() + interval) + 0.1 while True: t1 = datetime.now() tdiff = t0 - t1 if tdiff < timedelta(hours=-24): tdiff = timedelta(0) timecolor = white get_t0() elif tdiff < timedelta(0): tdiff = timedelta(0) timecolor = red else: timecolor = green tdiff_dhms = dt_dhms(tdiff) top_msg = f'{tdiff_dhms[0]:2d} {tdiff_dhms[1]:2d}' bot_msg = f'{tdiff_dhms[2]:2d} {tdiff_dhms[3]:2d}' day_msg = 'd' hour_msg = 'h' min_msg = 'm' sec_msg = 's' canvas.Clear() graphics.DrawText(canvas, font, 1, 7, timecolor, top_msg) graphics.DrawText(canvas, font, 1, 14, timecolor, bot_msg) graphics.DrawText(canvas, font, 11, 7, red, day_msg) graphics.DrawText(canvas, font, 26, 7, red, hour_msg) graphics.DrawText(canvas, font, 11, 14, red, min_msg) graphics.DrawText(canvas, font, 26, 14, red, sec_msg) # Force time updates to happen on uniform intervals\ sleep_time = next_time - time.time() if sleep_time < 0.1: next_time = round(time.time() + interval) + 0.1 sleep_time = 0.2 # print(f'sleep:{sleep_time} next{next_time} time{time_temp}') time.sleep(sleep_time) next_time += interval
def __init__(self): self.options = RGBMatrixOptions() self.options.rows = 16 self.options.chain_length = 2 self.options.parallel = 1 self.options.hardware_mapping = 'adafruit-hat' # If you have an Adafruit HAT: 'adafruit-hat' self.matrix = RGBMatrix(options=self.options) self.outlineColor = graphics.Color(128, 128, 128) self.textColor = graphics.Color(0, 128, 255) self.font = graphics.Font() self.font.LoadFont(FONT)
def draw_incident(canvas, font_file, message): logging.info("Got to draw incident") height_delta = 8 width_delta = 6 total_width = 128 font = graphics.Font() font.LoadFont(font_file) red_color = graphics.Color(255, 0, 0) yellow_color = graphics.Color(200, 125, 0) green_color = graphics.Color(50, 150, 0) canvas.Clear() for y in range(0, 8): for x in range(0, 32): x0 = x * 4 x1 = x0 + 3 if x % 2 == 0 and y <= 3: graphics.DrawLine(canvas, x0, y, x1, y, yellow_color) elif x % 2 != 0 and y > 3: graphics.DrawLine(canvas, x0, y, x1, y, yellow_color) logging.info("Got past drawing squares") if "scheduled maintenance" in message or "scheduled track work" in message: graphics.DrawText(canvas, font, 1, 15, red_color, "SCHEDULED") graphics.DrawText(canvas, font, 1, 23, red_color, "TRACK WORK") logging.info("Drawing scheduled track workd") else: logging.info("Drawing service advisory") service = "SERVICE" advisory = "ADVISORY" graphics.DrawText(canvas, font, compute_offset(service), 15, red_color, service) graphics.DrawText(canvas, font, compute_offset(advisory), 23, red_color, advisory) for y in range(24, 32): for x in range(0, 32): x0 = x * 4 x1 = x0 + 3 if x % 2 == 0 and y <= 27: graphics.DrawLine(canvas, x0, y, x1, y, yellow_color) elif x % 2 != 0 and y > 27: graphics.DrawLine(canvas, x0, y, x1, y, yellow_color) logging.info("Got past drawing other squares") time.sleep(5) canvas.Clear() draw_message(canvas, message, font_file)