diff --git a/bitmaptools/Billie.bmp.license b/bitmaptools/Billie.bmp.license index d1064fb..71d35c7 100644 --- a/bitmaptools/Billie.bmp.license +++ b/bitmaptools/Billie.bmp.license @@ -1,3 +1,3 @@ # SPDX-FileCopyrightText: Copyright (c) 2018 Adafruit Industries # -# SPDX-License-Identifier: MIT \ No newline at end of file +# SPDX-License-Identifier: MIT diff --git a/bitmaptools/bitmaptools_rotate_bmp.py b/bitmaptools/bitmaptools_rotate_bmp.py index d2bf17f..8d896e8 100644 --- a/bitmaptools/bitmaptools_rotate_bmp.py +++ b/bitmaptools/bitmaptools_rotate_bmp.py @@ -5,23 +5,25 @@ Use bitmaptools.rotozoom() to rotate a bmp image. """ import math -import bitmaptools import board -import displayio import adafruit_imageload +import displayio +import bitmaptools # 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) +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)) +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) diff --git a/bitmaptools/bitmaptools_rotate_bmp_animated.py b/bitmaptools/bitmaptools_rotate_bmp_animated.py index bfa4521..d606c7b 100644 --- a/bitmaptools/bitmaptools_rotate_bmp_animated.py +++ b/bitmaptools/bitmaptools_rotate_bmp_animated.py @@ -5,23 +5,25 @@ Use bitmaptools.rotozoom() to rotate a bmp image in a circle animated. """ import math -import bitmaptools import board -import displayio import adafruit_imageload +import bitmaptools +import displayio # 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) +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)) +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) diff --git a/bitmaptools/bitmaptools_scale_bmp.py b/bitmaptools/bitmaptools_scale_bmp.py new file mode 100644 index 0000000..7a8da7b --- /dev/null +++ b/bitmaptools/bitmaptools_scale_bmp.py @@ -0,0 +1,78 @@ +# SPDX-FileCopyrightText: Copyright (c) 2022 Tim Cocks +# +# SPDX-License-Identifier: MIT +""" +Use bitmaptools.rotozoom() to scale a bmp image and show multiple sizes of it on the display. +""" +import board +import adafruit_imageload +import bitmaptools +import displayio + +# 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 destination Bitmap object to hold the rotated image +dest_bitmap = displayio.Bitmap( + source_bitmap.height * 2, source_bitmap.height * 2, 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) + +# rotozoom() takes from source bitmap, puts into destination bitmap. +# clipping is not used so whole source image is put into the destination bitmap. +# scale argument accepts a float number that will multiply the size of the source bitmap times +# the scale factor. + +# Big Billie +BIG_BILLIE_SCALE = 1.75 +bitmaptools.rotozoom( + dest_bitmap, + source_bitmap, + ox=int(dest_bitmap.width - ((source_bitmap.width / 2) * BIG_BILLIE_SCALE)), + oy=int((source_bitmap.height / 2) * BIG_BILLIE_SCALE), + scale=BIG_BILLIE_SCALE, +) + +# Normal sized Billie +NORMAL_BILLIE_SCALE = 1.0 +bitmaptools.rotozoom( + dest_bitmap, + source_bitmap, + ox=int(dest_bitmap.width / 2) - 24, + oy=int((source_bitmap.height / 2) * NORMAL_BILLIE_SCALE), + scale=NORMAL_BILLIE_SCALE, +) + +# Little Billie +LITTLE_BILLY_SCALE = 0.5 +bitmaptools.rotozoom( + dest_bitmap, + source_bitmap, + ox=int((source_bitmap.width / 2) * LITTLE_BILLY_SCALE), + oy=int((source_bitmap.height / 2) * LITTLE_BILLY_SCALE), + scale=LITTLE_BILLY_SCALE, +) + +# move the destination image out of the corner a little +dest_tile_grid.x = 10 +dest_tile_grid.y = 10 + +# Create a Group to show the TileGrid +group = displayio.Group() + +# Add the TileGrid to the Group +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 diff --git a/bitmaptools/bitmaptools_scale_bmp_animated.py b/bitmaptools/bitmaptools_scale_bmp_animated.py new file mode 100644 index 0000000..f1de025 --- /dev/null +++ b/bitmaptools/bitmaptools_scale_bmp_animated.py @@ -0,0 +1,73 @@ +# SPDX-FileCopyrightText: Copyright (c) 2022 Tim Cocks +# +# SPDX-License-Identifier: MIT +""" +Use bitmaptools.rotozoom() to scale a bmp image and show multiple sizes of it on the display. +""" +import board +import adafruit_imageload +import bitmaptools +import displayio + +# 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 destination Bitmap object to hold the rotated image +dest_bitmap = displayio.Bitmap( + source_bitmap.height * 2, source_bitmap.height * 2, 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) + +# rotozoom() takes from source bitmap, puts into destination bitmap. +# clipping is not used so whole source image is put into the destination bitmap. +# scale argument accepts a float number that will multiply the size of the source bitmap times +# the scale factor. +INITIAL_SCALE = 0.5 +bitmaptools.rotozoom(dest_bitmap, source_bitmap, scale=INITIAL_SCALE) + +# move the destination image out of the corner a little +dest_tile_grid.x = 10 +dest_tile_grid.y = 10 + +# Create a Group to show the TileGrid +group = displayio.Group() + +# Add the TileGrid to the Group +group.append(dest_tile_grid) + +# Add the Group to the Display +display.show(group) + +# we will manually refresh the display only after we make changes to our destination bitmap +display.auto_refresh = False + +# Loop forever +while True: + # loop from 0.5 to 2.0 scale factors. step size 0.1 + for scale in range(5, 21): + # empty the destination bitmap, clear out the previously drawn frame + dest_bitmap.fill(0) + + # paste in billie at the current scale size from our loop + bitmaptools.rotozoom(dest_bitmap, source_bitmap, scale=scale / 10) + + # refresh the display to draw our changes + display.refresh() + + # loop from 2.0 to 0.5 scale factors. step size 0.1 + for scale in range(20, 4, -1): + # empty the destination bitmap, clear out the previously drawn frame + dest_bitmap.fill(0) + + # paste in billie at the current scale size from our loop + bitmaptools.rotozoom(dest_bitmap, source_bitmap, scale=scale / 10) + + # refresh the display to draw our changes + display.refresh()