Skip to content

Instantly share code, notes, and snippets.

@StilgarBF
Created October 7, 2016 13:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save StilgarBF/2ca7597acd988a82339aa4aaa161221c to your computer and use it in GitHub Desktop.
Save StilgarBF/2ca7597acd988a82339aa4aaa161221c to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# Ported from:
# https://github.com/adafruit/Adafruit_Python_SSD1306/blob/master/examples/shapes.py
from demo_opts import device
from oled.render import canvas
from PIL import ImageFont
from demo_opts import args
import time
font = ImageFont.load_default()
#with canvas(device) as draw:
# Draw some shapes.
# First define some constants to allow easy resizing of shapes.
padding = 2
shape_width = 20
top = padding
bottom = device.height - padding - 1
# Load default font.
font = ImageFont.load_default()
x = 0
# Alternatively load a TTF font.
# Some other nice fonts to try: http://www.dafont.com/bitmap.php
# font = ImageFont.truetype('../fonts/Volter__28Goldfish_29.ttf', 19)
font = ImageFont.truetype('../fonts/C&C Red Alert [INET].ttf', 25)
iteration = 0
ycenter = (device.height / 2)
offset = ycenter
operator = 3;
while iteration <= 100:
x = 0
y = round(offset)
offset = offset + operator
if offset > (device.height - 3):
operator = -3
if offset < ycenter:
operator = 3
with canvas(device) as draw:
draw.text((10, 10), 'Hello World!', font=font, fill=255)
while x <= device.width:
draw.line((x, y, (device.width / 2), 40), fill=255)
x = x + 5
iteration = iteration + 1
with canvas(device) as draw:
draw.rectangle((0, 0, device.width-1, device.height-1), outline=255, fill=0)
draw.text((10, 10), 'the end', font=font, fill=255)
time.sleep(1)
with canvas(device) as draw:
draw.rectangle((0, 0, device.width-1, device.height-1), outline=0, fill=0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment