Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
NextNext commit
bitmaptools rotate example
  • Loading branch information
@FoamyGuy
FoamyGuy committed Jun 10, 2022
commit 8df097d72a476a13208922a8f2ed683cf98d262c
Binary file addedbitmaptools/Billie.bmp
Binary file not shown.
3 changes: 3 additions & 0 deletions bitmaptools/Billie.bmp.license
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
# SPDX-FileCopyrightText: Copyright (c) 2018 Adafruit Industries
#
# SPDX-License-Identifier: MIT
49 changes: 49 additions & 0 deletions bitmaptools/bitmaptools_rotate_bmp.py
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
# SPDX-FileCopyrightText: Copyright (c) 2022 Tim Cocks
#
# SPDX-License-Identifier: MIT
"""
Use bitmaptools.rotozoom() to rotate a bmp image.
"""
import math
import bitmaptools
import board
import displayio
import adafruit_imageload

# use the builtin display
display = board.DISPLAY

# load bmp image into a Bitmap and Palette objects
source_bitmap, source_palette = adafruit_imageload.load("Billie.bmp",
bitmap=displayio.Bitmap,
palette=displayio.Palette)
# Create a TileGrid to show the bitmap
source_tile_grid = displayio.TileGrid(source_bitmap, pixel_shader=source_palette)

# Create destination Bitmap object to hold the rotated image
dest_bitmap = displayio.Bitmap(source_bitmap.height, source_bitmap.height, len(source_palette))

# Create a TileGrid to show the destination Bitmap with the rotated image in it
dest_tile_grid = displayio.TileGrid(dest_bitmap, pixel_shader=source_palette)

# take from source bitmap, put into destination bitmap.
# default values for x,y locations and clipping so whole image is used
# angle argument accepts radians. You can use math module to convert from degrees
bitmaptools.rotozoom(dest_bitmap, source_bitmap, angle=math.radians(270))

# move the rotated image tilegrid over to the right some
dest_tile_grid.x = 100

# Create a Group to show the TileGrids
group = displayio.Group()

# Add the TileGrids to the Group
group.append(source_tile_grid)
group.append(dest_tile_grid)

# Add the Group to the Display
display.show(group)

# Loop forever so you can enjoy your image
while True:
pass