hub.Image
– Image¶
The Image
class lets you create and modify images that you can show
on the hub matrix display using the hub.display
module.
-
class
hub.
Image
(string: str)¶ -
class
hub.
Image
(width: int, height: int) -
class
hub.
Image
(width: int, height: int, buffer: bytes) Create a new image object for use with the
hub.display.show()
function.You can use one of the signatures above to initialize an image, depending on what you need.
- Parameters
string – String of the form
"00900:09990:99999:09990:09090:"
, representing the brightness of each pixel (0 to 9). Pixels are listed row by row, separated by a colon (:
) or line break (\n
).width – Number of pixels in one row of the new image.
height – Number of pixels in one column of the new image.
buffer – Bytes representing the brightness values of each pixel in the new image. The buffer size must be equal to
width
*height
. If you give a with and height but no buffer, you will get an image where all pixels are zero.
-
width
() → int¶ Gets the width of the image as a number of pixels.
-
height
() → int¶ Gets the width of the image as a number of pixels.
-
shift_left
(n: int) → hub.Image¶ Shifts the image to the left.
- Parameters
n – By how many pixels to shift the image.
- Returns
A new, shifted image.
-
shift_right
(n: int) → hub.Image¶ Shifts the image to the right.
- Parameters
n – By how many pixels to shift the image.
- Returns
A new, shifted image.
-
shift_up
(n: int) → hub.Image¶ Shifts the image up.
- Parameters
n – By how many pixels to shift the image.
- Returns
A new, shifted image.
-
shift_down
(n: int) → hub.Image¶ Shifts the image down.
- Parameters
n – By how many pixels to shift the image.
- Returns
A new, shifted image.
-
get_pixel
(x: int, y: int, brightness: int) → int¶ Gets the brightness of one pixel in the image.
- Parameters
x – Pixel position counted from the left, starting at zero.
y – Pixel position counted from the top, starting at zero.
- Returns
Brightness (0–9) of the requested pixel.
-
set_pixel
(x: int, y: int, brightness: int) → None¶ Sets the brightness of one pixel in the image.
- Parameters
x – Pixel position counted from the left, starting at zero.
y – Pixel position counted from the top, starting at zero.
brightness – Brightness between
0
(fully off) and9
(fully on).
- Raises
ValueError – If x or y are negative or larger than the image size.
TypeError – If you try to modify a built-in image such as
hub.Image.HEART
.
Built-in images
-
hub.Image.
ANGRY
= Image('90009:09090:00000:99999:90909:')¶
-
hub.Image.
ARROW_E
= Image('00900:00090:99999:00090:00900:')¶
-
hub.Image.
ARROW_N
= Image('00900:09990:90909:00900:00900:')¶
-
hub.Image.
ARROW_NE
= Image('00999:00099:00909:09000:90000:')¶
-
hub.Image.
ARROW_NW
= Image('99900:99000:90900:00090:00009:')¶
-
hub.Image.
ARROW_S
= Image('00900:00900:90909:09990:00900:')¶
-
hub.Image.
ARROW_SE
= Image('90000:09000:00909:00099:00999:')¶
-
hub.Image.
ARROW_SW
= Image('00009:00090:90900:99000:99900:')¶
-
hub.Image.
ARROW_W
= Image('00900:09000:99999:09000:00900:')¶
-
hub.Image.
ASLEEP
= Image('00000:99099:00000:09990:00000:')¶
-
hub.Image.
BUTTERFLY
= Image('99099:99999:00900:99999:99099:')¶
-
hub.Image.
CHESSBOARD
= Image('09090:90909:09090:90909:09090:')¶
-
hub.Image.
CLOCK1
= Image('00090:00090:00900:00000:00000:')¶
-
hub.Image.
CLOCK2
= Image('00000:00099:00900:00000:00000:')¶
-
hub.Image.
CLOCK3
= Image('00000:00000:00999:00000:00000:')¶
-
hub.Image.
CLOCK4
= Image('00000:00000:00900:00099:00000:')¶
-
hub.Image.
CLOCK5
= Image('00000:00000:00900:00090:00090:')¶
-
hub.Image.
CLOCK6
= Image('00000:00000:00900:00900:00900:')¶
-
hub.Image.
CLOCK7
= Image('00000:00000:00900:09000:09000:')¶
-
hub.Image.
CLOCK8
= Image('00000:00000:00900:99000:00000:')¶
-
hub.Image.
CLOCK9
= Image('00000:00000:99900:00000:00000:')¶
-
hub.Image.
CLOCK10
= Image('00000:99000:00900:00000:00000:')¶
-
hub.Image.
CLOCK11
= Image('09000:09000:00900:00000:00000:')¶
-
hub.Image.
CLOCK12
= Image('00900:00900:00900:00000:00000:')¶
-
hub.Image.
CONFUSED
= Image('00000:09090:00000:09090:90909:')¶
-
hub.Image.
COW
= Image('90009:90009:99999:09990:00900:')¶
-
hub.Image.
DIAMOND
= Image('00900:09090:90009:09090:00900:')¶
-
hub.Image.
DIAMOND_SMALL
= Image('00000:00900:09090:00900:00000:')¶
-
hub.Image.
DUCK
= Image('09900:99900:09999:09990:00000:')¶
-
hub.Image.
FABULOUS
= Image('99999:99099:00000:09090:09990:')¶
-
hub.Image.
GHOST
= Image('99999:90909:99999:99999:90909:')¶
-
hub.Image.
GIRAFFE
= Image('99000:09000:09000:09990:09090:')¶
-
hub.Image.
GO_DOWN
= Image('00000:99999:09990:00900:00000:')¶
-
hub.Image.
GO_LEFT
= Image('00090:00990:09990:00990:00090:')¶
-
hub.Image.
GO_RIGHT
= Image('09000:09900:09990:09900:09000:')¶
-
hub.Image.
GO_UP
= Image('00000:00900:09990:99999:00000:')¶
-
hub.Image.
HAPPY
= Image('00000:09090:00000:90009:09990:')¶
-
hub.Image.
HEART
= Image('09090:99999:99999:09990:00900:')¶
-
hub.Image.
HEART_SMALL
= Image('00000:09090:09990:00900:00000:')¶
-
hub.Image.
HOUSE
= Image('00900:09990:99999:09990:09090:')¶
-
hub.Image.
MEH
= Image('09090:00000:00090:00900:09000:')¶
-
hub.Image.
MUSIC_CROTCHET
= Image('00900:00900:00900:99900:99900:')¶
-
hub.Image.
MUSIC_QUAVER
= Image('00900:00990:00909:99900:99900:')¶
-
hub.Image.
MUSIC_QUAVERS
= Image('09999:09009:09009:99099:99099:')¶
-
hub.Image.
NO
= Image('90009:09090:00900:09090:90009:')¶
-
hub.Image.
PACMAN
= Image('09999:99090:99900:99990:09999:')¶
-
hub.Image.
PITCHFORK
= Image('90909:90909:99999:00900:00900:')¶
-
hub.Image.
RABBIT
= Image('90900:90900:99990:99090:99990:')¶
-
hub.Image.
ROLLERSKATE
= Image('00099:00099:99999:99999:09090:')¶
-
hub.Image.
SAD
= Image('00000:09090:00000:09990:90009:')¶
-
hub.Image.
SILLY
= Image('90009:00000:99999:00909:00999:')¶
-
hub.Image.
SKULL
= Image('09990:90909:99999:09990:09990:')¶
-
hub.Image.
SMILE
= Image('00000:00000:00000:90009:09990:')¶
-
hub.Image.
SNAKE
= Image('99000:99099:09090:09990:00000:')¶
-
hub.Image.
SQUARE
= Image('99999:90009:90009:90009:99999:')¶
-
hub.Image.
SQUARE_SMALL
= Image('00000:09990:09090:09990:00000:')¶
-
hub.Image.
STICKFIGURE
= Image('00900:99999:00900:09090:90009:')¶
-
hub.Image.
SURPRISED
= Image('09090:00000:00900:09090:00900:')¶
-
hub.Image.
SWORD
= Image('00900:00900:00900:09990:00900:')¶
-
hub.Image.
TARGET
= Image('00900:09990:99099:09990:00900:')¶
-
hub.Image.
TORTOISE
= Image('00000:09990:99999:09090:00000:')¶
-
hub.Image.
TRIANGLE
= Image('00000:00900:09090:99999:00000:')¶
-
hub.Image.
TRIANGLE_LEFT
= Image('90000:99000:90900:90090:99999:')¶
-
hub.Image.
TSHIRT
= Image('99099:99999:09990:09990:09990:')¶
-
hub.Image.
UMBRELLA
= Image('09990:99999:00900:90900:09900:')¶
-
hub.Image.
XMAS
= Image('00900:09990:00900:09990:99999:')¶
-
hub.Image.
YES
= Image('00000:00009:00090:90900:09000:')¶
Built-in tuples of images
-
Image.
ALL_CLOCKS
= (Image('00900:00900:00900:00000:00000:'), Image('00090:00090:00900:00000:00000:'), Image('00000:00099:00900:00000:00000:'), Image('00000:00000:00999:00000:00000:'), Image('00000:00000:00900:00099:00000:'), Image('00000:00000:00900:00090:00090:'), Image('00000:00000:00900:00900:00900:'), Image('00000:00000:00900:09000:09000:'), Image('00000:00000:00900:99000:00000:'), Image('00000:00000:99900:00000:00000:'), Image('00000:99000:00900:00000:00000:'), Image('09000:09000:00900:00000:00000:'))¶
-
Image.
ALL_ARROWS
= (Image('00900:09990:90909:00900:00900:'), Image('00999:00099:00909:09000:90000:'), Image('00900:00090:99999:00090:00900:'), Image('90000:09000:00909:00099:00999:'), Image('00900:00900:90909:09990:00900:'), Image('00009:00090:90900:99000:99900:'), Image('00900:09000:99999:09000:00900:'), Image('99900:99000:90900:00090:00009:'))¶