|
4 | 4 | """
|
5 | 5 | Use bitmaptools.rotozoom() to scale a bmp image and show multiple sizes of it on the display.
|
6 | 6 | """
|
7 |
| -import bitmaptools |
8 | 7 | import board
|
9 |
| -import displayio |
10 | 8 | import adafruit_imageload
|
| 9 | +import bitmaptools |
| 10 | +import displayio |
11 | 11 |
|
12 | 12 | # use the builtin display
|
13 | 13 | display = board.DISPLAY
|
14 | 14 |
|
15 | 15 | # load bmp image into a Bitmap and Palette objects
|
16 |
| -source_bitmap, source_palette = adafruit_imageload.load("Billie.bmp", |
17 |
| - bitmap=displayio.Bitmap, |
18 |
| - palette=displayio.Palette) |
| 16 | +source_bitmap, source_palette = adafruit_imageload.load( |
| 17 | + "Billie.bmp", bitmap=displayio.Bitmap, palette=displayio.Palette |
| 18 | +) |
19 | 19 |
|
20 | 20 | # Create destination Bitmap object to hold the rotated image
|
21 |
| -dest_bitmap = displayio.Bitmap(source_bitmap.height * 2, source_bitmap.height * 2, |
22 |
| - len(source_palette)) |
| 21 | +dest_bitmap = displayio.Bitmap( |
| 22 | + source_bitmap.height * 2, source_bitmap.height * 2, len(source_palette) |
| 23 | +) |
23 | 24 |
|
24 | 25 | # Create a TileGrid to show the destination Bitmap with the rotated image in it
|
25 | 26 | dest_tile_grid = displayio.TileGrid(dest_bitmap, pixel_shader=source_palette)
|
|
30 | 31 | # the scale factor.
|
31 | 32 |
|
32 | 33 | # Big Billie
|
33 |
| -big_billie_scale = 1.75 |
34 |
| -bitmaptools.rotozoom(dest_bitmap, source_bitmap, |
35 |
| - ox=int(dest_bitmap.width - ((source_bitmap.width / 2) * big_billie_scale)), |
36 |
| - oy=int((source_bitmap.height / 2) * big_billie_scale), |
37 |
| - scale=big_billie_scale) |
| 34 | +BIG_BILLIE_SCALE = 1.75 |
| 35 | +bitmaptools.rotozoom( |
| 36 | + dest_bitmap, |
| 37 | + source_bitmap, |
| 38 | + ox=int(dest_bitmap.width - ((source_bitmap.width / 2) * BIG_BILLIE_SCALE)), |
| 39 | + oy=int((source_bitmap.height / 2) * BIG_BILLIE_SCALE), |
| 40 | + scale=BIG_BILLIE_SCALE, |
| 41 | +) |
38 | 42 |
|
39 | 43 | # Normal sized Billie
|
40 |
| -normal_billie_scale = 1.0 |
41 |
| -bitmaptools.rotozoom(dest_bitmap, source_bitmap, |
42 |
| - ox=int(dest_bitmap.width/2) - 24, |
43 |
| - oy=int((source_bitmap.height / 2) * normal_billie_scale), |
44 |
| - scale=normal_billie_scale) |
| 44 | +NORMAL_BILLIE_SCALE = 1.0 |
| 45 | +bitmaptools.rotozoom( |
| 46 | + dest_bitmap, |
| 47 | + source_bitmap, |
| 48 | + ox=int(dest_bitmap.width / 2) - 24, |
| 49 | + oy=int((source_bitmap.height / 2) * NORMAL_BILLIE_SCALE), |
| 50 | + scale=NORMAL_BILLIE_SCALE, |
| 51 | +) |
45 | 52 |
|
46 | 53 | # Little Billie
|
47 |
| -little_billie_scale = 0.5 |
48 |
| -bitmaptools.rotozoom(dest_bitmap, source_bitmap, |
49 |
| - ox=int((source_bitmap.width / 2) * little_billie_scale), |
50 |
| - oy=int((source_bitmap.height / 2) * little_billie_scale), |
51 |
| - scale=little_billie_scale) |
| 54 | +LITTLE_BILLY_SCALE = 0.5 |
| 55 | +bitmaptools.rotozoom( |
| 56 | + dest_bitmap, |
| 57 | + source_bitmap, |
| 58 | + ox=int((source_bitmap.width / 2) * LITTLE_BILLY_SCALE), |
| 59 | + oy=int((source_bitmap.height / 2) * LITTLE_BILLY_SCALE), |
| 60 | + scale=LITTLE_BILLY_SCALE, |
| 61 | +) |
52 | 62 |
|
53 | 63 | # move the destination image out of the corner a little
|
54 | 64 | dest_tile_grid.x = 10
|
|
0 commit comments