Skip to content

Commit ffab916

Browse files
authored
Merge pull request #5 from FoamyGuy/bitmaptools_rotate
Bitmaptools rotate examples
2 parents 2396fe6 + 9fbf780 commit ffab916

File tree

4 files changed

+104
-0
lines changed

4 files changed

+104
-0
lines changed

bitmaptools/Billie.bmp

4.26 KB
Binary file not shown.

bitmaptools/Billie.bmp.license

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2018 Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2022 Tim Cocks
2+
#
3+
# SPDX-License-Identifier: MIT
4+
"""
5+
Use bitmaptools.rotozoom() to rotate a bmp image.
6+
"""
7+
import math
8+
import bitmaptools
9+
import board
10+
import displayio
11+
import adafruit_imageload
12+
13+
# use the builtin display
14+
display = board.DISPLAY
15+
16+
# load bmp image into a Bitmap and Palette objects
17+
source_bitmap, source_palette = adafruit_imageload.load("Billie.bmp",
18+
bitmap=displayio.Bitmap,
19+
palette=displayio.Palette)
20+
# Create a TileGrid to show the bitmap
21+
source_tile_grid = displayio.TileGrid(source_bitmap, pixel_shader=source_palette)
22+
23+
# Create destination Bitmap object to hold the rotated image
24+
dest_bitmap = displayio.Bitmap(source_bitmap.height, source_bitmap.height, len(source_palette))
25+
26+
# Create a TileGrid to show the destination Bitmap with the rotated image in it
27+
dest_tile_grid = displayio.TileGrid(dest_bitmap, pixel_shader=source_palette)
28+
29+
# take from source bitmap, put into destination bitmap.
30+
# default values for x,y locations and clipping so whole image is used
31+
# angle argument accepts radians. You can use math module to convert from degrees
32+
bitmaptools.rotozoom(dest_bitmap, source_bitmap, angle=math.radians(270))
33+
34+
# move the rotated image tilegrid over to the right some
35+
dest_tile_grid.x = 100
36+
37+
# Create a Group to show the TileGrids
38+
group = displayio.Group()
39+
40+
# Add the TileGrids to the Group
41+
group.append(source_tile_grid)
42+
group.append(dest_tile_grid)
43+
44+
# Add the Group to the Display
45+
display.show(group)
46+
47+
# Loop forever so you can enjoy your image
48+
while True:
49+
pass
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2022 Tim Cocks
2+
#
3+
# SPDX-License-Identifier: MIT
4+
"""
5+
Use bitmaptools.rotozoom() to rotate a bmp image in a circle animated.
6+
"""
7+
import math
8+
import bitmaptools
9+
import board
10+
import displayio
11+
import adafruit_imageload
12+
13+
# use the builtin display
14+
display = board.DISPLAY
15+
16+
# load bmp image into a Bitmap and Palette objects
17+
source_bitmap, source_palette = adafruit_imageload.load("Billie.bmp",
18+
bitmap=displayio.Bitmap,
19+
palette=displayio.Palette)
20+
# Create a TileGrid to show the bitmap
21+
source_tile_grid = displayio.TileGrid(source_bitmap, pixel_shader=source_palette)
22+
23+
# Create destination Bitmap object to hold the rotated image
24+
dest_bitmap = displayio.Bitmap(source_bitmap.height, source_bitmap.height, len(source_palette))
25+
26+
# Create a TileGrid to show the destination Bitmap with the rotated image in it
27+
dest_tile_grid = displayio.TileGrid(dest_bitmap, pixel_shader=source_palette)
28+
29+
# move the rotated image tilegrid over to the right some
30+
dest_tile_grid.x = 100
31+
32+
# Create a Group to show the TileGrids
33+
group = displayio.Group()
34+
35+
# Add the TileGrids to the Group
36+
group.append(source_tile_grid)
37+
group.append(dest_tile_grid)
38+
39+
# Add the Group to the Display
40+
display.show(group)
41+
42+
# Loop forever so you can enjoy your image
43+
while True:
44+
# loop over all the degrees from 0-360
45+
for angle_deg in range(360):
46+
# erase previous frame
47+
dest_bitmap.fill(0)
48+
49+
# take from source bitmap, put into destination bitmap.
50+
# default values for x,y locations and clipping so whole image is used
51+
# angle argument accepts radians. You can use math module to convert from degrees
52+
bitmaptools.rotozoom(dest_bitmap, source_bitmap, angle=math.radians(angle_deg))

0 commit comments

Comments
 (0)