def show(self): text= self.information width, height = lcd.dimensions() image = Image.new('P', (width, height)) draw = ImageDraw.Draw(image) font = ImageFont.load_default() w, h = font.getsize(text) x = (width - w) // 2 y = (height - h) // 2 draw.text((x,y), text, 1, font) for x in range(128): for y in range(64): pixel = image.getpixel((x, y)) lcd.set_pixel(x, y, pixel) lcd.show()
def displayObject(obj, x, y): lcd.clear() xp = x for y1 in obj: for x2 in y1: lenY = len(obj) lenX = len(y1) if x2 == 1: pixel = 1 else: pixel = 0 lcd.set_pixel(xp, y, pixel) xp = xp + 1 y = y + 1 lcd.set_pixel(xp, y, pixel) xp = x lcd.show()
def displayObject(obj, x, y): xp = x for y1 in obj: #print(y1) for x2 in y1: lenY = len(obj) lenX = len(y1) #print(x2) #xp = x if x2 == 1: pixel = 1 else: pixel = 0 lcd.set_pixel(xp, y, pixel) xp = xp + 1 y = y + 1 lcd.set_pixel(xp, y, pixel) xp = x lcd.show() return x, y
def displayText(text, lcd, x, y): lcd.clear() # get width and height width, height = lcd.dimensions() # create new image image = Image.new('P', (width, height)) # draw said image draw = ImageDraw.Draw(image) # get font font = ImageFont.truetype(fonts.AmaticSCBold, 24) w, h = font.getsize(text) draw.text((x, y), text, 1, font) for x1 in range(x, x + w): for y1 in range(y, y + h): pixel = image.getpixel((x1, y1)) lcd.set_pixel(x1, y1, pixel) lcd.show()
def display_character(): ch = input("Enter a character: ") x = int(input("Enter an x coordinate: ")) y = int(input("Enter a y coordinate: ")) if ch in myDict: lcd.clear() width, height = lcd.dimensions() image = Image.new('P', (width, height)) draw = ImageDraw.Draw(image) font = ImageFont.truetype(fonts.AmaticSCBold, 12) w, h = font.getsize(ch) draw.text((x, y), ch, 1, font) for x1 in range(x, x + w): for y1 in range(y, y + h): pixel = image.getpixel((x1, y1)) lcd.set_pixel(x1, y1, pixel) lcd.show() else: print("Chosen Character not Present in Dictionary")
def etchSketch(x,y): while True: key = getchar() lcd.set_pixel(x, y, 1) lcd.show() if key == 's': #restart game clearScreen(lcd) elif key == '\x1b[A': #up arrow #print("You tpye the ucd p key") y = y -1 if y == 0: y = 63 lcd.set_pixel(x, y, 1) lcd.show() elif key == '\x1b[B': # down up #print("You tpye the up key") y = y + 1 if y == 63: y = 0 lcd.set_pixel(x, y, 1) lcd.show() elif key == '\x1b[D': #left arrow #print('Left arrow <-') x = x - 1 if x == 0: x = 127 lcd.set_pixel(x, y, 1) lcd.show() elif key == '\x1b[C': #right arrow #print('Right arrow ->') x = x + 1 if x == 127: x = 0 lcd.set_pixel(x, y, 1) lcd.show() elif key == 'q': lcd.clear() lcd.show() exit() else: print("Press a valid option")
def moveObject(obj, startX=0, startY=0, vx=0, vy=0): column = len(obj) - 1 row = len(obj[0]) - 1 y = column endX = startX + vx endY = startY + vy while (startX <= endX and startY <= endY): while (y >= 0): x = row while (x >= 0): lcd.set_pixel(x + startX, y + startY, obj[y][x]) x -= 1 y -= 1 lcd.show() time.sleep(2) eraseObject(obj, startX, startY) y = column startX += vx startY += vy
def etchaske(x, y): backlight.set_pixel(0, 0, 255, 0) backlight.show() while True: key = getchar() print(key) lcd.set_pixel(x, y, 1) lcd.show() if key == 's': clearScreen(lcd) elif key == 'w': y = y - 1 if y == 0: y = 63 lcd.set_pixel(x, y, 1) lcd.show() elif key == 'x': y = y + 1 if y == 63: y = 0 lcd.set_pixel(x, y, 1) lcd.show() elif key == 'a': x = x - 1 if x == 0: x = 127 lcd.set_pixel(x, y, 1) lcd.show() elif key == 'd': x = x + 1 if x == 127: x = 0 lcd.set_pixel(x, y, 1) lcd.show() elif key == 'q': lcd.clear() lcd.show() exit() else: print("Not a valid input")
def etcha(): x = 1 y = 63 lcd.set_pixel(x, y, 1) print('start') lcd.show() #sets the intial point to bottom left running = True while running == True: char = click.getchar() if char == '\x1b[A': #UP y = y - 1 if y == 0: y = 63 lcd.set_pixel(x, y, 1) lcd.show() elif char == '\x1b[B': #DOWN y = y + 1 if y == 64: y = 1 lcd.set_pixel(x, y, 1) lcd.show() elif char == '\x1b[C': #RIGHT x = x + 1 if x == 128: x = 1 lcd.set_pixel(x, y, 1) lcd.show() elif char == '\x1b[D': #LEFT x = x - 1 if x == 0: x = 127 lcd.set_pixel(x, y, 1) lcd.show() elif char == 'q': running = False elif char == 's': lcd.clear() lcd.show() text = "etch-a-sketch" displayText(text, lcd, 25, -5)
def etchSketch(x, y): while True: key = getchar() lcd.set_pixel(x, y, 1) lcd.show() if key == 's': lcd.clear() lcd.show() elif key == '\x1b[A': y = y - 1 if y == 0: y = 63 lcd.set_pixel(x, y, 1) lcd.show() elif key == '\x1b[B': y = y + 1 if y == 63: y = 0 lcd.set_pixel(x, y, 1) lcd.show() elif key == '\x1b[D': x = x - 1 if x == 0: x = 127 lcd.set_pixel(x, y, 1) lcd.show() elif key == '\x1b[C': x = x + 1 if x == 127: x = 0 lcd.set_pixel(x, y, 1) lcd.show() elif key == 'q': lcd.clear() lcd.show() exit() else: print("chose a valid option ")
def etchSketch(x, y): while True: key = getchar() lcd.set_pixel(x, y, 1) lcd.show() if key == 's': clearScreen(lcd) x = 0 y = 0 elif key == '\x1b[A': y = y - 1 if y == 0: y = 63 lcd.set_pixel(x, y, 1) lcd.show() elif key == '\x1b[B': y = y + 1 if y == 63: y = 0 lcd.set_pixel(x, y, 1) lcd.show() elif key == '\x1b[C': x = x + 1 if x == 127: x = 0 lcd.set_pixel(x, y, 1) lcd.show() elif key == '\x1b[D': x = x - 1 if x == 0: x = 127 lcd.set_pixel(x, y, 1) lcd.show() elif key == 'q': lcd.clear() lcd.show() backlight.set_all(0, 0, 0) backlight.show() exit()
def scan_contrast(): for c in range(25, 64): draw.rectangle((0, 0, width, height), "black") message = "Contrast: {:02d}".format(c) w, h = font.getsize(message) left, top = (width - w) / 2, (height - h) / 2 draw.text((left, top), message, 1, font=font) for x in range(width): for y in range(height): pixel = image.getpixel((x, y)) lcd.set_pixel(x, y, pixel) lcd.contrast(c) lcd.show() time.sleep(0.4) lcd.clear() lcd.show()
def displayObject(obj,x,y): def aValue(obj): # returns the lenght of the main list -1. Objective: print axis Y a = (len(obj))-1 return(a) a = aValue(obj) ay = y+a # update the value of y to set the correct starting point def bValue(a, obj): # returns the lenght of the lists inside of the main list -1. Objective: print axis X b = (len(obj[a]))-1 return(b) while(a>=0): b = bValue(a, obj) bx = x+b # update the value of x to set the correct starting point while(b>=0): w = (obj[a][b]) lcd.set_pixel(bx,ay,w) lcd.show() b-=1 bx-=1 a-=1 ay-=1
def etchASketch(): c = 'p' print("Press s to start") while c!= 'q': c = getchar() if c == 's': displayText("ETCH-A-SKETCH",10,10) time.sleep(2) clearScreen() x = 63 y = 31 elif c == '\x1b[A': if y == 0: y = 63 y = (y-1) % 63 elif c == '\x1b[B': y = (y+1) % 63 elif c == '\x1b[C': x = (x+1) % 127 elif c == '\x1b[D': if x==0: x = 127 x = (x-1) % 127 else: print("Valid key are arrow keys , 'q', 's' ") lcd.set_pixel(x,y,1) lcd.show() clearScreen() turnBacklight() clearScreen() etchASketch() clearBacklight() return y = 0 if y < 0: return y = 63
def clear(self): self.width, self.height = lcd.dimensions() self.image = Image.new('P', (self.width, self.height)) self.draw = ImageDraw.Draw(self.image) self.font = ImageFont.truetype(fonts.FredokaOne, 20) self.fontLine2 = ImageFont.truetype(fonts.PressStart2P, 10) self.line1 = "" self.line2 = "" lcd.contrast(40) backlight.set_all(self.led_brightness, self.led_brightness, self.led_brightness) backlight.show() self.draw.text((0, 1), self.line1, 1, self.font) self.draw.text((0, 30), self.line2, 1, self.fontLine2) self.w, self.h = self.font.getsize(self.line1) self.x = (self.width - self.w) // 2 self.y = (self.height - self.h) // 2 for self.x in range(128): for self.y in range(64): pixel = self.image.getpixel((self.x, self.y)) lcd.set_pixel(self.x, self.y, pixel) lcd.show()
def eraseObject(obj, startX=0, startY=0): column = len(obj) - 1 row = len(obj[0]) - 1 if (startY + len(obj) > 63): startY = 64 - len(obj) if (startX + len(obj[0]) > 127): startX = 128 - len(obj[0]) y = column while (y >= 0): x = row while (x >= 0): pixel = obj[y][x] if (pixel == 1): pixel = 0 lcd.set_pixel(x + startX, y + startY, pixel) x -= 1 y -= 1 lcd.show()
def displayObject(obj, x, y): lcd.clear() xp = x # looping over y coordinate for y1 in obj: # looping over x coordinate for x2 in y1: if x2 == 1: pixel = 1 else: pixel = 0 lcd.set_pixel(xp, y, pixel) xp = xp + 1 y = y + 1 lcd.set_pixel(xp, y, pixel) xp = x lcd.show()
def drawTime(self): """Draw text showing current time on screen""" self.image = Image.new('1', (self.timeWidth, self.timeHeight)) self.draw = ImageDraw.Draw(self.image) now = datetime.datetime.now() text = now.strftime("%H:%M") w, h = self.timeFont.getsize(text) #x = (self.timeWidth - w) // 2 #y = (self.timeHeight - h) // 2 x = 0 y = 0 self.draw.text((x, y), text, 1, self.timeFont) for x in range(self.timeWidth): for y in range(self.timeHeight): pixel = self.image.getpixel((x, y)) lcd.set_pixel(x, y, pixel) lcd.contrast(38) lcd.show()
def displayObject(obj, x, y, ignoreOutOfRangeError=True): if ignoreOutOfRangeError: # Getting dimension of object pixWidth, pixHeight = 8, 8 # Checking the position on the screen according to given X coordinate if (pixWidth + x > scrWidth - 1): x = scrWidth - pixWidth # Checking the position on the screen according to given Y coordinate if (pixHeight + y > scrHeight - 1): y = scrHeight - pixHeight try: for i in range(len(obj)): for j in range(len(obj[i])): lcd.set_pixel(x + j, y + i, obj[i][j]) # Show marked pixel on the screen lcd.show() except IndexError: print( 'Your object has outed off the screen according to the coordinates you entered' )
def drawStair(coordenate, width, height, orientation): from gfxhat import lcd, backlight from time import sleep # Clear the lcd lcd.clear() lcd.show() # Convert string coordenates to int x = int(coordenate[0]) y = int(coordenate[1]) # Set the while to run only if the coordenates are inside of the gfxhat display screen while (x >= 0 and x <= 127 and y >= 0 and y <= 63): for aux in range(0, int(width)): #If the x limit is reached within the for, break to prevent gfxhat error if (x < 0 or x > 127): x = -1 y = -1 break else: lcd.set_pixel(x, y, 1) lcd.show() if (orientation == "l"): x -= 1 else: x += 1 for aux in range(0, int(height)): # If the y limit is reached within the for, break if (y < 0): y = -1 break else: lcd.set_pixel(x, y, 1) lcd.show() y -= 1 # clear screen after 4 seconds sleep(4) lcd.clear() lcd.show()
def displayObject(obj,x,y): while x < 0 or y < 0 or x > 127 or y > 63: if x < 0: x = 128+x if y < 0: y = 64+y if x > 127: x = x-128 if y > 63: y = y-63 posX = x posY = y for lines in obj: for pxl in lines: if pxl == 1: lcd.set_pixel(posX,posY,1) lcd.show() posX += 1 if posX > 127: posX = 0 posY += 1 if posY > 63: posY = 0 posX = x
def draw_object(self, object_list): padding = 2 lcd.clear() self.image = Image.new("P", (self.screen_width, self.screen_height)) self.draw = ImageDraw.Draw(self.image) for object in object_list: text = object # print(text) w, h = self.font.getsize(text) x = 2 y = (self.screen_height - h) // 6 + padding # print( # "screen height", self.screen_height, "screen width", self.screen_width # ) # print(x, y, text) self.draw.text((x, y), text, 1, self.font) for x in range(128): for y in range(64): pixel = self.image.getpixel((x, y)) lcd.set_pixel(x, y, pixel) padding += 10 lcd.show()
def Ball(message: Message): global Clock global Stop global Count global ImagePng Count=10 Stop=True Clock=False Ball = ["🎱 As I see it, yes 🎱","🎱 It is certain 🎱","🎱 It is decidedly so 🎱","🎱 Most likely 🎱","🎱 Outlook good 🎱","🎱 Signs point to yes 🎱","🎱 Without a doubt 🎱","🎱 Yes,Yes – definitely 🎱","🎱 You may rely on it 🎱","🎱 Reply hazy, try again 🎱","🎱 Ask again later 🎱","🎱 Better not tell you now 🎱","🎱 Cannot predict now 🎱","🎱 Concentrate and ask again 🎱","🎱 Don't count on it 🎱","🎱 My reply is no 🎱","🎱 My sources say no 🎱","🎱 Outlook not so good 🎱","🎱 Very doubtful 🎱"] choose=random.choice(Ball) font = ImageFont.truetype("/boot/TriggerBot-master/CCFONT.ttf", 12) width, height = lcd.dimensions() spritemap = Image.open("/boot/TriggerBot-master/Peka.png").convert("PA") image = Image.new('1', (width, height),"black") image.paste(spritemap,(width-32,33)) draw = ImageDraw.Draw(image) draw.line([(32,8),(96,8)],fill ="white",width=1) draw.line([(32,8),(64,56)],fill ="white",width=1) draw.line([(96,8),(64,56)],fill ="white",width=1) lines = textwrap.wrap(choose, width=16) y_text = 16 for line in lines: w, h = font.getsize(line) draw.text(((width-w)/2, y_text), line,1, font=font) y_text += h for x in range(128): for y in range(64): pixel = image.getpixel((x, y)) lcd.set_pixel(x, y, pixel) backlight.set_all(random.randint(0,255),random.randint(0,255),random.randint(0,255)) backlight.show() lcd.show() bot.reply_to(message, choose, parse_mode="Markdown") ImagePng=image Stop=False LedOnOff()
def displayObject(obj, x, y): while True: lcd.clear() xc = x obj = int( input( "Press 1 for ship, 2 to clear, 3 for pacman, or 4 to exit: ")) if obj == 2: clearScreen(lcd) elif obj == 1: obj = f1 for y1 in obj: for x2 in y1: if x2 == 1: pixel = 1 else: pixel = 0 lcd.set_pixel(xc, y, pixel) xc = xc + 1 y = y + 1 lcd.set_pixel(xc, y, pixel) xc = x lcd.show() elif obj == 3: obj = pm for y1 in obj: for x2 in y1: if x2 == 1: pixel = 1 else: pixel = 0 lcd.set_pixel(xc, y, pixel) xc = xc + 1 y = y + 1 lcd.set_pixel(xc, y, pixel) xc = x lcd.show() else: break
def makestep(x, y, w=20, h=20, SW=127, SH=63): for i in range(h): if y >= 0: lcd.set_pixel(x, y - i, 1) else: h = i for j in range(0, w): if x + j <= SW: lcd.set_pixel(x + j, y - h, 1) else: w = j return (x + w, y - h) if x + j <= SW: lcd.set_pixel(x + j, y - h, 1) else: w = j
pass else: if ch == 0 or ch == 1: paddle1_vel = 0 elif ch == 3 or ch == 5: paddle2_vel = 0 else: pass for x in range(6): touch.on(x, handler) while True: if not started and won: time.sleep(5) won = False if started: image = Image.new('P', (WIDTH, HEIGHT)) canvas = ImageDraw.Draw(image) draw(canvas) else: image = Image.open("pong-start-screen.png") for x in range(WIDTH): for y in range(HEIGHT): pixel = image.getpixel((x, y)) lcd.set_pixel(x, y, not pixel) lcd.show()
def vertical(y): while( x <=127) lcd.show() Create a function that displays a horizontal line at a given y coordinate. from gfxhat import lcd lcd.clear() lcd.show() y=0 x=20 While (y <=63): lcd.set_pixel(x,y,1) y=y+1 def horizantal(x): while ( y <=63) lcd.show() #Create a function that creates a staircase starting at a specific coordinate. One stair has a width of w and a height of h. from gfxhat import lcd def makestep(x, y, w=20, h=20, SW=127, SH=63): for i in range(h): if y >= 0: lcd.set_pixel(x, y - i, 1) else: h = i for j in range(0, w): if x + j <= SW: lcd.set_pixel(x + j, y - h, 1) else: w = j return (x + w, y - h) if x + j <= SW: lcd.set_pixel(x + j, y - h, 1) else: w = j return (x + w, y - h) def staircase(x=20, y=63, w=10, h=10): while (x + w < 127 and y - h >= 0): x, y = makestep() tep(x, y, w, h) lcd.clear() staircase() lcd.show() #Create a function that displays random pixel on the screen for a given period of time specifies in seconds. from gfxhat import lcd import time lcd.clear() lcd.show() y=22 for x in range(x,y,1) lcd.show() import random between o and 128 time.sleep(1 / 30.0) print (random.randin 0,128) displays random pixel def displayRandomPixel(): for i between o and 128 displayRandomPixel() #Create a function clearBacklight() that resets the backlight color. from gfx hat import backlight backlight.set_all(10.0,225) backlight.show() lcd.clear() enter lcd not defined lcd.clear() lcd.show() def clearBacklight() : backlight.set_all(10,0,0) put many values in backlight set all (225,0,0))
#Create a function that displays a vertical line at a given x coordinate on the gfx hat. from gfxhat import lcd lcd.clear() lcd.show() x=0 y=20 while( x <=127) : lcd.set_pixel(x,y,1) x = x+1 lcd.show() def vertical(y): while( x <=127) lcd.show() Create a function that displays a horizontal line at a given y coordinate. from gfxhat import lcd lcd.clear() lcd.show() y=0 x=20 While (y <=63): lcd.set_pixel(x,y,1) y=y+1
def horizontalDisplay(y=horizontalDisplayInput(), x=1): while x <= 127: lcd.set_pixel(x, y, 1) x = x + 1
if 'functions' in pin_details: scroll_y = 33 + (current_page * 10) draw.rectangle(((124, scroll_y), (126, scroll_y + 10)), 1) backlight.set_all(255, 255, 255) if 'type' in pin_details: pin_type = pin_details['type'] if pin_type == 'GPIO/I2C': backlight.set_all(255, 0, 255) if pin_type == 'GPIO/SPI': backlight.set_all(0, 0, 255) if pin_type == 'GND': backlight.set_all(128, 128, 128) if pin_type == '+5v': backlight.set_all(255, 0, 0) if pin_type == '+3v3': backlight.set_all(255, 255, 0) backlight.show() # Blit our image canvas to the LCD for x in range(width): for y in range(height): pixel = img.getpixel((x, y)) lcd.set_pixel(x, y, pixel) lcd.show() time.sleep(1 / 30.0)