Wednesday, 3 August 2016

Built-in Images

The micro:bit's MicroPython has a big list of built-in images - 63 to be precise. But what do they all look like? Well, here's a handy chart! And as a bonus, we've also included a test program that cycles through all the images on the micro:bit's display.


The code is pretty straight-forward - we store all the images in a big list and the iterate through them, showing each one to the screen and the waiting for a button press before going on to the next one.

"""
 Show All Built In Images

 Show all built in images from the micro:bit library. Press the A button to switch to the next 
 image in the list.

 This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 
 International License. https://creativecommons.org/licenses/by-nc-sa/4.0/
"""


from microbit import *


# List containing all of the built im images
all_images = [
    Image.HEART,
    Image.HEART_SMALL,
    Image.DIAMOND,
    Image.DIAMOND_SMALL,
    Image.SQUARE,
    Image.SQUARE_SMALL,

    Image.HAPPY,
    Image.SMILE,
    Image.SAD,
    Image.CONFUSED,
    Image.ANGRY,
    Image.ASLEEP,
    Image.SURPRISED,
    Image.SILLY,
    Image.FABULOUS,
    Image.MEH,

    Image.YES,
    Image.NO,

    Image.CLOCK1,
    Image.CLOCK2,
    Image.CLOCK3,
    Image.CLOCK4,
    Image.CLOCK5,
    Image.CLOCK6,
    Image.CLOCK7,
    Image.CLOCK8,
    Image.CLOCK9,
    Image.CLOCK10,
    Image.CLOCK11,
    Image.CLOCK12,

    Image.ARROW_N,
    Image.ARROW_NE,
    Image.ARROW_E,
    Image.ARROW_SE,
    Image.ARROW_S,
    Image.ARROW_SW,
    Image.ARROW_W,
    Image.ARROW_NW,

    Image.TRIANGLE,
    Image.TRIANGLE_LEFT,
    Image.CHESSBOARD,
    Image.PITCHFORK,
    Image.XMAS,
    Image.TARGET,
    Image.TSHIRT,
    Image.ROLLERSKATE,
    Image.HOUSE,
    Image.SWORD,
    Image.UMBRELLA,

    Image.RABBIT,
    Image.COW,
    Image.DUCK,
    Image.TORTOISE,
    Image.BUTTERFLY,
    Image.GIRAFFE,
    Image.SNAKE,
    Image.SKULL,
    Image.STICKFIGURE,
    Image.PACMAN,
    Image.GHOST,

    Image.MUSIC_CROTCHET,
    Image.MUSIC_QUAVER,
    Image.MUSIC_QUAVERS,
]


# Main loop
for i in all_images:
    display.show(i)
    while not button_a.was_pressed():
        pass
display.clear()

Here are the Python and hex files:
show_all_built_in_images.py
show_all_built_in_images.hex

No comments:

Post a comment