def initialize(self, width, height, double_buffer): if self.level == 0: self.font1 = graphics.Font() self.font2 = graphics.Font() self.font3 = graphics.Font() self.font4 = graphics.Font() #self.font1.LoadFont("/home/pi/rpi-rgb-led-matrix/fonts/extra/Mermaid-Bold-16.bdf") self.font1.LoadFont("/home/pi/rpi-rgb-led-matrix/fonts/extra/75dpi/timR14.bdf") self.font2.LoadFont("/home/pi/rpi-rgb-led-matrix/fonts/extra/RingbearerMedium-12.bdf") self.font3.LoadFont("/home/pi/rpi-rgb-led-matrix/fonts/10x20.bdf") self.font4.LoadFont("/home/pi/rpi-rgb-led-matrix/fonts/extra/75dpi/helvR12.bdf") self.textColor = graphics.Color(255, 255, 0) self.pos = double_buffer.width self.index = 0 self.my_text = [("All we have to decide is what to do with the time that is given us.", self.font2, YELLOW), ("There is some good in this world, and it's worth fighting for.", self.font2, YELLOW), ("Made by the CCS Computer Club", self.font1, BLUEWHITE), ("Commit your work to the Lord, and your plans will be established. - Proverbs 16:3", self.font1, YELLOW), ("For God so loved the world, that He gave His only Son, that whoever believes in him should not perish but have eternal life", self.font3, GREEN), ("Made by the Computer Club. You should join us!", self.font1, BLUEWHITE), ("Take my instruction instead of silver, and knowledge rather than choice gold, for wisdom is better than jewels, and all that you may desire cannot compare with her. - Proverbs 8:10-11", self.font4, REDISH) ] print("Len of my_text:", len(self.my_text)) self.length = len(self.my_text) elif self.level == 1: self.pos = 32 self.index = 0 self.images = ["/path/to/image/image1.png", "/path/to/image/image2.png", "/path/to/image/image3.png", "/path/to/image/image4.png"] self.image = Image.open(self.images[self.index]).convert('RGB') double_buffer.SetImage(self.image, 0, self.pos) self.length = len(self.images) print(self.image.height)
def run(self): offscreen_canvas = self.matrix.CreateFrameCanvas() small_font = graphics.Font() small_font.LoadFont("../../../fonts/nanum9.bdf") large_font = graphics.Font() large_font.LoadFont("../../../fonts/nanum18.bdf") textColor = graphics.Color(255, 0, 0) pos = offscreen_canvas.width my_text = self.args.text wait_txt = ['탐스에오신걸환영합니다.'.encode('utf-8')] wait_txt.append('안전운전하세요.'.encode('utf-8')) wait_txt.append('TOMS'.encode('utf-8')) a = 0 i = 0 while True: offscreen_canvas.Clear() len = graphics.DrawText(offscreen_canvas, large_font, pos, 25, textColor, my_text) pos = pos - 10 if (pos + len < 0): a = a + 1 if a % 2 == 0: i = i + 1 pos = offscreen_canvas.width time.sleep(0.1) offscreen_canvas = self.matrix.SwapOnVSync(offscreen_canvas) if a == 2: break
def initialize(): global options, matrix, canvas, store global default_font, light_font options = RGBMatrixOptions() options.rows = led_rows options.cols = led_cols options.chain_length = led_chain options.parallel = led_parallel options.brightness = led_brightness options.hardware_mapping = led_hardware_mapping options.disable_hardware_pulsing = True options.pwm_lsb_nanoseconds = 130 # if you're not using raspberry pi 3 comment line below options.gpio_slowdown = 2 matrix = RGBMatrix(options=options) canvas = matrix.CreateFrameCanvas() default_font = graphics.Font() default_font.LoadFont(default_font_path) light_font = graphics.Font() light_font.LoadFont(light_font_path) store = redis.StrictRedis(host='localhost', port=6379, db=0)
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 __init__(self, weather, dimmer): threading.Thread.__init__(self) self.setDaemon(True) self._weather = weather self._dimmer = dimmer # Configure LED matrix driver # RGBMatrix(Rows,Chained,?) self._matrix = RGBMatrix(32, 2, 1) self._matrix.pwmBits = 11 self._matrix.brightness = 25 # Load fonts self._font_large = graphics.Font() self._font_large.LoadFont("rpi-rgb-led-matrix/fonts/10x20.bdf") self._font_small = graphics.Font() self._font_small.LoadFont("rpi-rgb-led-matrix/fonts/6x10.bdf") self._font_tiny = graphics.Font() self._font_tiny.LoadFont("rpi-rgb-led-matrix/fonts/4x6.bdf") # Define colors self._white = graphics.Color(255, 255, 255) self._amber = graphics.Color(200, 50, 0) self._red = graphics.Color(255, 120, 120) self._blue = graphics.Color(120, 120, 255) self._green = graphics.Color(150, 255, 100) self._pink = graphics.Color(255, 0, 120)
def createOtherDay(self, doubleBuffer, num=0): if num == 0: self.DrawBox(doubleBuffer, 0, 0, 63, 31, graphics.Color(255, 255, 0)) font = graphics.Font() font.LoadFont("/home/pi/rpi-rgb-led-matrix/fonts/6x13.bdf") color = graphics.Color(0, 128, 128) graphics.DrawText(doubleBuffer, font, 14, 12, color, "Have a") graphics.DrawText(doubleBuffer, font, 6, 26, color, "Great Day") elif num == 1: self.DrawBox(doubleBuffer, 0, 0, 63, 31, graphics.Color(180, 250, 255)) font = graphics.Font() font.LoadFont("/home/pi/rpi-rgb-led-matrix/fonts/6x13.bdf") color = graphics.Color(255, 255, 0) graphics.DrawText(doubleBuffer, font, 14, 11, color, "Have a") graphics.DrawText(doubleBuffer, font, 18, 21, color, "Great") graphics.DrawText(doubleBuffer, font, 11, 30, color, "Weekend") elif num == 2: self.DrawBox(doubleBuffer, 0, 0, 63, 31, graphics.Color(255, 225, 77)) font = graphics.Font() font.LoadFont("/home/pi/rpi-rgb-led-matrix/fonts/6x13.bdf") color = graphics.Color(25, 217, 255) graphics.DrawText(doubleBuffer, font, 17, 11, color, "Enjoy") graphics.DrawText(doubleBuffer, font, 21, 21, color, "Your") graphics.DrawText(doubleBuffer, font, 11, 30, color, "Weekend") return True
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 display_stats(self, matrix): for i in range(10): cpu_perc = int(psutil.cpu_percent()) cpu_temp = int(psutil.sensors_temperatures()['cpu_thermal'][0].current) mem_perc = int(psutil.virtual_memory().percent) swap = matrix.CreateFrameCanvas() font = graphics.Font() font.LoadFont(settings.FONT_PATH + "6x13B.bdf") font2 = graphics.Font() font2.LoadFont(settings.FONT_PATH + "6x13.bdf") graphics.DrawText(swap, font, 5, font.baseline - 2, graphics.Color(100, 100, 100), " Pi Stat") graphics.DrawText(swap, font, 0, font.baseline * 2, graphics.Color(0, 180, 120), "CPU") graphics.DrawText(swap, font2, 0, font.baseline * 3 - 1, graphics.Color(0, 150, 40), str(cpu_perc) + '%') graphics.DrawText(swap, font, 24, font.baseline * 2, graphics.Color(130, 100, 10), "MEM") graphics.DrawText(swap, font2, 24, font.baseline * 3 - 1, graphics.Color(100, 50, 0), str(mem_perc) + '%') graphics.DrawText(swap, font, 46, font.baseline * 2, graphics.Color(140, 10, 10), "TMP") graphics.DrawText(swap, font2, 46, font.baseline * 3 - 1, graphics.Color(100, 0, 0), str(cpu_temp) + '°') matrix.SwapOnVSync(swap) matrix.SetImage(self.rgb_image, -1, -1, unsafe=False) matrix.SetImage(self.rgb_image, 55, -1, unsafe=False) time.sleep(0.7)
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 display_stats(self, matrix): try: image = Image.open(settings.IMAGES_PATH + 'pi-hole.png') image = image.resize((8, 9)) except FileNotFoundError: print('Pi-Hole image not found') return for i in range(4): swap = matrix.CreateFrameCanvas() font = graphics.Font() font.LoadFont(settings.FONT_PATH + "6x13B.bdf") font2 = graphics.Font() font2.LoadFont(settings.FONT_PATH + "6x13.bdf") graphics.DrawText(swap, font, 5, font.baseline - 2, graphics.Color(120, 120, 120), " Pi Hole") try: response = requests.get("http://" + settings.PI_HOLE_IP + "/admin/api.php?summaryRaw") json = response.json() queries_today = json['dns_queries_today'] percentage_blocked = int(json['ads_percentage_today']) graphics.DrawText(swap, font, 0, font.baseline * 2 - 2, graphics.Color(0, 180, 120), "Query") graphics.DrawText(swap, font2, 35, font.baseline * 2 - 2, graphics.Color(0, 180, 20), str(queries_today)) graphics.DrawText(swap, font, 0, font.baseline * 3 - 1, graphics.Color(140, 10, 10), "Blocked") graphics.DrawText(swap, font2, 47, font.baseline * 3 - 1, graphics.Color(120, 0, 0), str(percentage_blocked) + '%') except requests.exceptions.ConnectionError: graphics.DrawText(swap, font, 11, font.baseline * 3 - 1, graphics.Color(180, 10, 10), "Offline") matrix.SwapOnVSync(swap) matrix.SetImage(image.convert('RGB'), unsafe=False) time.sleep(2)
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 _set_screen_params(self): offscreen_canvas = self.matrix.CreateFrameCanvas() large_font = graphics.Font() large_font.LoadFont("../../fonts/7x14.bdf") small_font = graphics.Font() small_font.LoadFont("../../fonts/6x10.bdf") textColor = graphics.Color(255, 0, 0) return offscreen_canvas, large_font, small_font, textColor
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 led_display(): matrix = RGBMatrix(options=options) offscreen_canvas = matrix.CreateFrameCanvas() pos = offscreen_canvas.width font_path = "fonts/" count = 0 # Kolonial delivery = delivery_status() clock_color = graphics.Color(255, 165, 20) clock_font = graphics.Font() clock_font.LoadFont(os.path.join(font_path, "6x9.bdf")) k_header = "Kolonial.no Delivery Tracker" k_header_color = graphics.Color(255, 165, 20) k_header_font = graphics.Font() k_header_font.LoadFont(os.path.join(font_path, "6x9.bdf")) d_title = delivery.get("title") d_title_color = graphics.Color(0, 255, 0) d_title_font = graphics.Font() d_title_font.LoadFont(os.path.join(font_path, "clR6x12.bdf")) d_status = delivery.get("status") d_status_color = graphics.Color(238, 238, 228) d_status_font = graphics.Font() d_status_font.LoadFont(os.path.join(font_path, "6x12.bdf")) while True: clock = str(datetime.now().strftime("%H:%M:%S")) count += 1 if count == refresh_rate: count = 0 print(f"{datetime.now()} - Refreshing data...") delivery = delivery_status() d_title = delivery.get("title") d_status = delivery.get("status") offscreen_canvas.Clear() graphics.DrawText(offscreen_canvas, k_header_font, 0, 6, k_header_color, k_header) graphics.DrawText(offscreen_canvas, clock_font, 207, 6, clock_color, clock) graphics.DrawText( offscreen_canvas, d_title_font, 12, 19, d_title_color, d_title) len = graphics.DrawText(offscreen_canvas, d_status_font, pos, 31, d_status_color, d_status) pos -= 1 if pos + len < 0: pos = offscreen_canvas.width time.sleep(text_speed) offscreen_canvas = matrix.SwapOnVSync(offscreen_canvas)
def RenderScene(self, scene): scene.Home_Team_Logo_Image.thumbnail( (self.matrix.width - 33, self.matrix.height - 33), Image.ANTIALIAS) scene.Away_Team_Logo_Image.thumbnail( (self.matrix.width - 33, self.matrix.height - 33), Image.ANTIALIAS) size = scene.Away_Team_Logo_Image.size width = size[0] self.Away_Team_Logo_X = 27 - width font = graphics.Font() font.LoadFont(x + "/fonts/7x13.bdf") bigfont = graphics.Font() bigfont.LoadFont(x + "/fonts/10x20.bdf") textColor = graphics.Color(255, 255, 255) my_text = "@" score = scene.Away_Team_Score + "-" + scene.Home_Team_Score scorePositionOffset = (score.index("-") + 1) * 8 self.buffer.Clear() graphics.DrawText(self.buffer, bigfont, 32 - scorePositionOffset, 32, textColor, score) graphics.DrawText(self.buffer, font, 29, 50, textColor, my_text) self.buffer.SetImage(scene.Away_Team_Logo_Image.convert('RGB'), self.Away_Team_Logo_X, self.Away_Team_Logo_y) self.buffer.SetImage(scene.Home_Team_Logo_Image.convert('RGB'), self.Home_Team_Logo_X, self.Home_Team_Logo_y) if scene.MainText: textFont = graphics.Font() textFont.LoadFont(x + "/fonts/6x13.bdf") positionOffset = (len(scene.MainText) / 2) * 6 graphics.DrawText(self.buffer, textFont, 32 - positionOffset, 13, textColor, scene.MainText) else: textFont = graphics.Font() textFont.LoadFont(x + "/fonts/5x7.bdf") y_pos = 7 for line in scene.AdditionalText: positionOffset = (len(line) / 2) * 4 if len(line) % 2 == 0: positionOffset += 4 graphics.DrawText(self.buffer, textFont, 32 - positionOffset, y_pos, textColor, line) y_pos = y_pos + 8 self.cleanUpLogos(scene) self.buffer = self.matrix.SwapOnVSync(self.buffer)
def Run(self): canvas = self.matrix.CreateFrameCanvas() height = canvas.height width = canvas.width jafont = graphics.Font() enfont = graphics.Font() pos = canvas.width count = 0 try: jafont.LoadFont("/usr/local/share/fonts/18x18ja.bdf") #enfont.LoadFont("/usr/local/share/fonts/9x18.bdf") except: print "No Fonts!" while True: canvas.Clear() #draw text #TODO: Fix text flow overlapping miku leng1 = graphics.DrawText(canvas, jafont, pos, 14, graphics.Color(0, 255, 0), myText) #leng2=graphics.DrawText(canvas,enfont,pos+leng1,12,graphics.Color(0,255,0),myEnText) #draw miku #currentSecond=datetime.now().second #if(currentSecond%2==0): if (count % 2 == 0): self.drawImage(48, 0, 'hatsune-miku2.ppm', 16, 16) #elif(currentSecond%2==1): elif (count % 2 == 1): self.drawImage(48, 0, 'hatsune-miku2-2.ppm', 16, 16) #move text #if(count%10==0): pos -= 1 # count=0 if (pos + leng1 < 0): pos = canvas.width time.sleep(0.10) canvas = self.matrix.SwapOnVSync(canvas) count += 1
def get_font(): ''' Params: font - Font for text d_font - Font for distance Returns: font -> str, d_font -> str ''' font = graphics.Font() d_font = graphics.Font() #distance font small font.LoadFont('/home/pi/Buck-Off/Buck-Off/fonts/7x13.bdf') d_font.LoadFont('/home/pi/Buck-Off/Buck-Off/fonts/6x13.bdf') return (font, d_font)
def display_status(self, matrix, device_id): try: completion = str(int(self.devices[device_id]['completion'])) + '%' need_items = str(self.devices[device_id]['needItems']) need_delete = str(self.devices[device_id]['needDeletes']) except KeyError: completion = 'Err' need_items = 'Err' need_delete = 'Err' swap = matrix.CreateFrameCanvas() font = graphics.Font() font.LoadFont(settings.FONT_PATH + "6x13B.bdf") font2 = graphics.Font() font2.LoadFont(settings.FONT_PATH + "6x13.bdf") device_name = self.devices[device_id]['name'][:6] graphics.DrawText(swap, font, 3, font.baseline - 2, graphics.Color(50, 50, 180), " Syncthing") graphics.DrawText(swap, font, 0, font.baseline * 2, graphics.Color(120, 120, 120), device_name) graphics.DrawText(swap, font2, 41, font.baseline * 2, graphics.Color(80, 100, 80), completion) if self.devices[device_id]['connected'] and not self.devices[ device_id]['paused'] and completion != '100%': graphics.DrawText(swap, font, 0, font.baseline * 3 - 1, graphics.Color(20, 20, 120), "I") graphics.DrawText(swap, font2, 8, font.baseline * 3 - 1, graphics.Color(50, 50, 170), need_items) graphics.DrawText(swap, font, 38, font.baseline * 3 - 1, graphics.Color(100, 20, 20), "D") graphics.DrawText(swap, font2, 47, font.baseline * 3 - 1, graphics.Color(170, 60, 60), need_delete) elif self.devices[device_id]['paused']: graphics.DrawText(swap, font, 0, font.baseline * 3 - 1, graphics.Color(150, 85, 0), "Paused") elif not self.devices[device_id]['connected']: graphics.DrawText(swap, font, 0, font.baseline * 3 - 1, graphics.Color(120, 10, 0), "Offline") elif completion == '100%': graphics.DrawText(swap, font, 0, font.baseline * 3 - 1, graphics.Color(10, 120, 10), "Up to Date") matrix.SwapOnVSync(swap) matrix.SetImage(self.image, unsafe=False)
def __init__(self, *args, **kwargs): if "color" in kwargs: self.color = kwargs["color"] else: self.color = BaseColor(255, 255, 255) if "pos" in kwargs: self.pos = kwargs.pos else: self.pos = 0 if "font" not in kwargs: raise TextLineException("Missing Font") self.font = graphics.Font() self.font.LoadFont(kwargs["font"]) if "height" in kwargs: self.height = kwargs["height"] else: self.height = self.font.height if "align" in kwargs: self.align = kwargs["align"] else: self.align = "left" if "text" in kwargs: self.text = kwargs["text"] else: self.text = "" self.alignText() self.display = None
def Run(self): #Change to take request as a arguement. Request contains text,colour,font. offscreenCanvas = self.matrix.CreateFrameCanvas() font = graphics.Font() font.LoadFont("matrix/fonts/7x13.bdf") red = request.json['colour']['red'] green = request.json['colour']['green'] blue = request.json['colour']['blue'] textColor = graphics.Color(red, green, blue) pos = offscreenCanvas.width myText = request.json['text'] while True: offscreenCanvas.Clear() len = graphics.DrawText(offscreenCanvas, font, pos, 10, textColor, myText) pos -= 1 if (pos + len < 0): pos = offscreenCanvas.width time.sleep(0.05) offscreenCanvas = self.matrix.SwapOnVSync(offscreenCanvas)
def __init__(self, canvas, scoreboard): self.canvas = canvas self.scoreboard = scoreboard self.colors = json.load(open('Assets/colors.json')) self.font = graphics.Font() self.font.LoadFont('Assets/tom-thumb.bdf')
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 run(self): offscreen_canvas = self.matrix.CreateFrameCanvas() font = graphics.Font() font.LoadFont("./BPdots.bdf") textColor = graphics.Color(0, 255, 255) def centered(message, color=textColor): msg_width = graphics.DrawText(offscreen_canvas, font, offscreen_canvas.width, 0, color, message) start_x = (offscreen_canvas.width - msg_width) // 2 graphics.DrawText(offscreen_canvas, font, start_x, 24, color, message) for line in each_line(sys.stdin): for w in each_word(line): offscreen_canvas.Clear() centered(w) offscreen_canvas = self.matrix.SwapOnVSync(offscreen_canvas) time.sleep(0.25) offscreen_canvas.Clear() offscreen_canvas = self.matrix.SwapOnVSync(offscreen_canvas) time.sleep(1.00)
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 run(self): canvas = self.matrix.CreateFrameCanvas() font = graphics.Font() font.LoadFont("../../../fonts/6x12.bdf") textColor = graphics.Color(0, 89, 100) pos = 2 while True: canvas.Clear() seconds_diff = int(time.time()) - int(SPECIAL_TIME) days_diff = (Decimal(seconds_diff) / Decimal(86400)) years_diff = (Decimal(seconds_diff) / Decimal(31536000)) seconds_text = str(seconds_diff) + " s" days_text = str( days_diff.quantize(Decimal('0.1'), rounding=ROUND_DOWN)) + " days" years_text = str( years_diff.quantize(Decimal('.0001'), rounding=ROUND_DOWN)) + " yrs" seconds_line = graphics.DrawText(canvas, font, pos, 10, textColor, seconds_text) days_line = graphics.DrawText(canvas, font, pos, 19, textColor, days_text) years_line = graphics.DrawText(canvas, font, pos, 28, textColor, years_text) time.sleep(0.1) canvas = self.matrix.SwapOnVSync(canvas)
def led_scroll_text(): matrix = RGBMatrix(options=options) offscreen_canvas = matrix.CreateFrameCanvas() cwd = os.path.dirname(__file__) font_path = os.path.join(cwd, font_filename) font = graphics.Font() font.LoadFont(font_path) textColor = graphics.Color(*text_color) pos = offscreen_canvas.width scroll_text = grab_scores() count = 0 while True: offscreen_canvas.Clear() len = graphics.DrawText(offscreen_canvas, font, pos, 13, textColor, scroll_text) pos -= 1 if pos + len < 0: pos = offscreen_canvas.width count += 1 if count >= 1: count = 0 print("Refreshing scores...") scroll_text = grab_scores() time.sleep(ticker_speed) offscreen_canvas = matrix.SwapOnVSync(offscreen_canvas)
def run(self): offscreen_canvas = self.matrix.CreateFrameCanvas() font = graphics.Font() font.LoadFont("../../../fonts/7x13.bdf") textColor = graphics.Color(255, 255, 255) #white pos = offscreen_canvas.width my_text = self.args.text while True: offscreen_canvas.Clear() len = graphics.DrawText(offscreen_canvas, font, pos, 10, textColor, my_text) pos -= 1 if (pos + len < 0): pos = offscreen_canvas.width time.sleep(0.05) current_time = datetime.datetime.now() str_time = strftime(current_time.hour) + ":" + strftime( current_time.minute) # Reset the text to the current time my_text = str_time # Set the offscreen info to on screen offscreen_canvas = self.matrix.SwapOnVSync(offscreen_canvas)
def run(self): offscreen_canvas = self.matrix.CreateFrameCanvas() font = graphics.Font() font.LoadFont("/home/pi/git/rpi-rgb-led-matrix/fonts/" + settings.get("ticker_display_font")) c = settings.get("ticker_display_color") text_color = graphics.Color(c[0], c[1], c[2]) text_y_axis = settings.get("ticker_y_axis") ticker_sleep = settings.get("ticker_sleep_time") while True: try: response = get_json_payload(get_data()) for i in response: payload = i.get('payload') if i.get('display_type') == 'delta': origin = i.get('origin_system') _display_message_delta(self, payload, origin, offscreen_canvas, font, text_color, text_y_axis, ticker_sleep) else: _display_message(self, payload, offscreen_canvas, font, text_color, text_y_axis, ticker_sleep) except urllib3.exceptions.MaxRetryError as me: _log.error("Max retry error, %s", me) pass
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 initialize(self, width, height, doubleBuffer): self.font = graphics.Font() self.fontTime = graphics.Font() self.fontTime.LoadFont("/home/pi/rpi-rgb-led-matrix/fonts/7x14.bdf") self.font.LoadFont("/home/pi/rpi-rgb-led-matrix/fonts/10x20.bdf") self.now = datetime.now() currentTime = self.now.strftime("%-I:%M") currentMonth = self.now.strftime("%b %d") offset = 20 if self.now.hour % 12 == 0 or self.now.hour % 12 > 9: offset = 13 doubleBuffer.Clear() length = graphics.DrawText(doubleBuffer, self.fontTime, offset, 12, graphics.Color(225, 255, 0), currentTime) length = graphics.DrawText(doubleBuffer, self.font, 2, 28, graphics.Color(0, 255, 0), currentMonth)