Skip to content

Commit 1d71251

Browse files
authored
Merge pull request #27 from FoamyGuy/adding_more_examples
Adding more examples
2 parents 784322c + fa19aa5 commit 1d71251

File tree

4 files changed

+7459
-1
lines changed

4 files changed

+7459
-1
lines changed

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,5 @@ bundles
99
.eggs
1010
dist
1111
**/*.egg-info
12-
*.bdf
1312
*.pcf
1413
*.ttf
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
"""
2+
This example runs on PyPortal, or any Circuit Python device
3+
with a built-in screen that is at least 320x240 pixels.
4+
5+
It will use adafruit_bitmap_font to load a font and fill a
6+
bitmap with pixels matching glyphs from a given String
7+
"""
8+
9+
10+
import board
11+
from adafruit_bitmap_font import bitmap_font # pylint: disable=wrong-import-position
12+
import displayio
13+
14+
font = bitmap_font.load_font("fonts/Arial-16.bdf")
15+
16+
bitmap = displayio.Bitmap(320, 240, 2)
17+
18+
palette = displayio.Palette(2)
19+
20+
palette[0] = 0x000000
21+
palette[1] = 0xFFFFFF
22+
23+
_, height, _, dy = font.get_bounding_box()
24+
for y in range(height):
25+
pixels = []
26+
for c in "Adafruit CircuitPython":
27+
glyph = font.get_glyph(ord(c))
28+
if not glyph:
29+
continue
30+
glyph_y = y + (glyph.height - (height + dy)) + glyph.dy
31+
32+
if 0 <= glyph_y < glyph.height:
33+
for i in range(glyph.width):
34+
value = glyph.bitmap[i, glyph_y]
35+
pixel = 0
36+
if value > 0:
37+
pixel = 1
38+
pixels.append(pixel)
39+
else:
40+
# empty section for this glyph
41+
for i in range(glyph.width):
42+
pixels.append(0)
43+
44+
# one space between glyph
45+
pixels.append(0)
46+
47+
if pixels:
48+
for x, pixel in enumerate(pixels):
49+
bitmap[x, y] = pixel
50+
51+
# Create a TileGrid to hold the bitmap
52+
tile_grid = displayio.TileGrid(bitmap, pixel_shader=palette)
53+
54+
# Create a Group to hold the TileGrid
55+
group = displayio.Group()
56+
57+
group.x = 20
58+
# Add the TileGrid to the Group
59+
group.append(tile_grid)
60+
61+
# Add the Group to the Display
62+
board.DISPLAY.show(group)
63+
64+
while True:
65+
pass
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"""
2+
This example uses addfruit_display_text.label to display text using a custom font
3+
loaded by adafruit_bitmap_font
4+
"""
5+
6+
import board
7+
from adafruit_bitmap_font import bitmap_font
8+
from adafruit_display_text import label
9+
10+
display = board.DISPLAY
11+
12+
# Set text, font, and color
13+
text = "HELLO WORLD"
14+
font = bitmap_font.load_font("fonts/Arial-16.bdf")
15+
color = 0xFF00FF
16+
17+
# Create the tet label
18+
text_area = label.Label(font, text=text, color=color)
19+
20+
# Set the location
21+
text_area.x = 20
22+
text_area.y = 20
23+
24+
# Show it
25+
display.show(text_area)
26+
27+
while True:
28+
pass

0 commit comments

Comments
 (0)