|
| 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