Skip to content

Commit 801475f

Browse files
authored
Merge pull request #6 from FoamyGuy/bitmaptools_scale
Bitmaptools scale examples and format all bitmaptools examples
2 parents ffab916 + d33140d commit 801475f

File tree

5 files changed

+168
-13
lines changed

5 files changed

+168
-13
lines changed

‎bitmaptools/Billie.bmp.license‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# SPDX-FileCopyrightText: Copyright (c) 2018 Adafruit Industries
22
#
3-
# SPDX-License-Identifier: MIT
3+
# SPDX-License-Identifier: MIT

‎bitmaptools/bitmaptools_rotate_bmp.py‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,25 @@
55
Use bitmaptools.rotozoom() to rotate a bmp image.
66
"""
77
importmath
8-
importbitmaptools
98
importboard
10-
importdisplayio
119
importadafruit_imageload
10+
importdisplayio
11+
importbitmaptools
1212

1313
# use the builtin display
1414
display=board.DISPLAY
1515

1616
# 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)
17+
source_bitmap, source_palette=adafruit_imageload.load(
18+
"Billie.bmp", bitmap=displayio.Bitmap,palette=displayio.Palette
19+
)
2020
# Create a TileGrid to show the bitmap
2121
source_tile_grid=displayio.TileGrid(source_bitmap, pixel_shader=source_palette)
2222

2323
# Create destination Bitmap object to hold the rotated image
24-
dest_bitmap=displayio.Bitmap(source_bitmap.height, source_bitmap.height, len(source_palette))
24+
dest_bitmap=displayio.Bitmap(
25+
source_bitmap.height, source_bitmap.height, len(source_palette)
26+
)
2527

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

‎bitmaptools/bitmaptools_rotate_bmp_animated.py‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,25 @@
55
Use bitmaptools.rotozoom() to rotate a bmp image in a circle animated.
66
"""
77
importmath
8-
importbitmaptools
98
importboard
10-
importdisplayio
119
importadafruit_imageload
10+
importbitmaptools
11+
importdisplayio
1212

1313
# use the builtin display
1414
display=board.DISPLAY
1515

1616
# 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)
17+
source_bitmap, source_palette=adafruit_imageload.load(
18+
"Billie.bmp", bitmap=displayio.Bitmap,palette=displayio.Palette
19+
)
2020
# Create a TileGrid to show the bitmap
2121
source_tile_grid=displayio.TileGrid(source_bitmap, pixel_shader=source_palette)
2222

2323
# Create destination Bitmap object to hold the rotated image
24-
dest_bitmap=displayio.Bitmap(source_bitmap.height, source_bitmap.height, len(source_palette))
24+
dest_bitmap=displayio.Bitmap(
25+
source_bitmap.height, source_bitmap.height, len(source_palette)
26+
)
2527

2628
# Create a TileGrid to show the destination Bitmap with the rotated image in it
2729
dest_tile_grid=displayio.TileGrid(dest_bitmap, pixel_shader=source_palette)
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2022 Tim Cocks
2+
#
3+
# SPDX-License-Identifier: MIT
4+
"""
5+
Use bitmaptools.rotozoom() to scale a bmp image and show multiple sizes of it on the display.
6+
"""
7+
importboard
8+
importadafruit_imageload
9+
importbitmaptools
10+
importdisplayio
11+
12+
# use the builtin display
13+
display=board.DISPLAY
14+
15+
# load bmp image into a Bitmap and Palette objects
16+
source_bitmap, source_palette=adafruit_imageload.load(
17+
"Billie.bmp", bitmap=displayio.Bitmap, palette=displayio.Palette
18+
)
19+
20+
# Create destination Bitmap object to hold the rotated image
21+
dest_bitmap=displayio.Bitmap(
22+
source_bitmap.height*2, source_bitmap.height*2, len(source_palette)
23+
)
24+
25+
# Create a TileGrid to show the destination Bitmap with the rotated image in it
26+
dest_tile_grid=displayio.TileGrid(dest_bitmap, pixel_shader=source_palette)
27+
28+
# rotozoom() takes from source bitmap, puts into destination bitmap.
29+
# clipping is not used so whole source image is put into the destination bitmap.
30+
# scale argument accepts a float number that will multiply the size of the source bitmap times
31+
# the scale factor.
32+
33+
# Big Billie
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+
)
42+
43+
# Normal sized Billie
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+
)
52+
53+
# Little Billie
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+
)
62+
63+
# move the destination image out of the corner a little
64+
dest_tile_grid.x=10
65+
dest_tile_grid.y=10
66+
67+
# Create a Group to show the TileGrid
68+
group=displayio.Group()
69+
70+
# Add the TileGrid to the Group
71+
group.append(dest_tile_grid)
72+
73+
# Add the Group to the Display
74+
display.show(group)
75+
76+
# Loop forever so you can enjoy your image
77+
whileTrue:
78+
pass
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2022 Tim Cocks
2+
#
3+
# SPDX-License-Identifier: MIT
4+
"""
5+
Use bitmaptools.rotozoom() to scale a bmp image and show multiple sizes of it on the display.
6+
"""
7+
importboard
8+
importadafruit_imageload
9+
importbitmaptools
10+
importdisplayio
11+
12+
# use the builtin display
13+
display=board.DISPLAY
14+
15+
# load bmp image into a Bitmap and Palette objects
16+
source_bitmap, source_palette=adafruit_imageload.load(
17+
"Billie.bmp", bitmap=displayio.Bitmap, palette=displayio.Palette
18+
)
19+
20+
# Create destination Bitmap object to hold the rotated image
21+
dest_bitmap=displayio.Bitmap(
22+
source_bitmap.height*2, source_bitmap.height*2, len(source_palette)
23+
)
24+
25+
# Create a TileGrid to show the destination Bitmap with the rotated image in it
26+
dest_tile_grid=displayio.TileGrid(dest_bitmap, pixel_shader=source_palette)
27+
28+
# rotozoom() takes from source bitmap, puts into destination bitmap.
29+
# clipping is not used so whole source image is put into the destination bitmap.
30+
# scale argument accepts a float number that will multiply the size of the source bitmap times
31+
# the scale factor.
32+
INITIAL_SCALE=0.5
33+
bitmaptools.rotozoom(dest_bitmap, source_bitmap, scale=INITIAL_SCALE)
34+
35+
# move the destination image out of the corner a little
36+
dest_tile_grid.x=10
37+
dest_tile_grid.y=10
38+
39+
# Create a Group to show the TileGrid
40+
group=displayio.Group()
41+
42+
# Add the TileGrid to the Group
43+
group.append(dest_tile_grid)
44+
45+
# Add the Group to the Display
46+
display.show(group)
47+
48+
# we will manually refresh the display only after we make changes to our destination bitmap
49+
display.auto_refresh=False
50+
51+
# Loop forever
52+
whileTrue:
53+
# loop from 0.5 to 2.0 scale factors. step size 0.1
54+
forscaleinrange(5, 21):
55+
# empty the destination bitmap, clear out the previously drawn frame
56+
dest_bitmap.fill(0)
57+
58+
# paste in billie at the current scale size from our loop
59+
bitmaptools.rotozoom(dest_bitmap, source_bitmap, scale=scale/10)
60+
61+
# refresh the display to draw our changes
62+
display.refresh()
63+
64+
# loop from 2.0 to 0.5 scale factors. step size 0.1
65+
forscaleinrange(20, 4, -1):
66+
# empty the destination bitmap, clear out the previously drawn frame
67+
dest_bitmap.fill(0)
68+
69+
# paste in billie at the current scale size from our loop
70+
bitmaptools.rotozoom(dest_bitmap, source_bitmap, scale=scale/10)
71+
72+
# refresh the display to draw our changes
73+
display.refresh()

0 commit comments

Comments
(0)