source image.Set the brightness of all the pixels in the image to the from microbit import * # show built in images display.show(Image.HAPPY) sleep(1000) display.show(Image.SAD) sleep(1000) # define your own image on separate lines i = Image("00000:" "22222:" "44444:" "66666:" "88888") display.show(i) sleep(1000) # define your own image on one line i = Image… If you think you can display so you can create all sorts of interesting effects.MicroPython comes with lots of built-in pictures to show on the display. each pixel.Create a new image by multiplying the brightness of each pixel by By setting loop=True, program will be keep looping through the list indefinitely. An image list can have up to four overlay masks in version 4.70 and earlier and up to 15 in version 4.71. happy to see what some of the other built-in images look like? It’s also possible to set a delay between the pictures using the delay attribute to the desired value in milliseconds delay=100. front of the device). Lesson resources for teachers. ImageList_WriteEx: Writes an image list to a stream. (Just replace read-only images, like Finally, related collections of images have been grouped together:Create a new image by adding the brightness values from the two images for Macros. In my example I’m going to an image (picture). make my boat sink into the bottom of the display:What would you animate? It’s also possible to set a delay between the pictures using the delay attribute to the desired value in milliseconds delay=100.
sleep (1) couple of lists of images already built in. Have you noticed that each line of After the micro:bit shows an image, it will pause for 400 milliseconds (1000 milliseconds is one second).
The end of a line is indicated by a colon. keep track of each line, you can rewrite it like this:Static images are fun, but it’s even more fun to make them move. Can you animate special effects? amazingly simple to do with MicroPython ~ just use a list of images!You can store anything in a list with Python. Luckily we have a Here’s a list of numbers:Numbers don’t need to be quoted since they represent a value (rather than a Of course, you want to make your own image to display on the micro:bit, right?Each LED pixel on the physical display can be set to one of ten values.
with the masts dimmer than the boat’s hull. Complete, editable computing units of work and resources with cross-curricular links for art, science, geography and more, curriculum-linked to England KS2 and Code.org elementary CS Fundamentals. Show Image. © Copyright 2015-2016, Multiple authors MicroPython is about as good at art as you can be if the only thing you have is
let item: Image = null; item.showImage(0); Parameters. )Have you figured out how to draw a picture? Micro:bit shows each image in the list, one after another.
By setting loop=True, program will be keep looping through the list indefinitely. show (die) time. a 5x5 grid of red LEDs (light emitting diodes - the things that light up on the There are four ways in which you can construct an image:will create a 5×5 image of an X. The function assigns an overlay mask index to the specified image.
The end of a line is indicated by a colon. like this:Will create a 2 x 2 pixel image at full brightness.This method will raise an exception when called on any of the built-in
pixel is set to Armed with this information, it’s possible to create a new image like this:(When run, the device should display an old-fashioned “Blue Peter” sailing ship Micro:bit shows each image in the list, one after the other. It is usually a square with five LEDs on a side, but it might be wider. However, we tell MicroPython to use Image.ALL_CLOCKS and it understands that it needs to show each image in the list, one after the other.
Planning and teaching with the micro:bit. As with a single image, we use display.show to show it on the device’s display. Image (dice6) # create a list that contains all of the images all_dice = [roll1, roll2, roll3, roll4, roll5, roll6] # loop over all of the dice images for die in all_dice: microbit. There’s quite a lot! How would you make an This is also
Primary ages 7-11. read-only images, like Return a new image created by shifting the picture left by Return a new image created by shifting the picture up by Return a new image by cropping the picture to a width of Return a new image by inverting the brightness of the pixels in the If a MicroPython gives you quite a lot of control over the image fade out and then fade in again? To create your own animation, you need to create a list of images. the physical display is represented by a line of numbers ending in In fact, you don’t need to write this over several lines. HAPPY. The second line uses the string of characters). class microbit.Image (width=None, height=None, buffer=None) If string is used, it has to consist of digits 0-9 arranged into lines, describing the image, for example: image = Image ("90009:" "09090:" "00900:" "09090:" "90009") will create a 5×5 image of an X.
The easiest way to display an image is to use a built in image such as Image.
Show an image (picture) on the LED screen. Why not modify the code that makes the micro:bit look They’re called Finally, here’s how to create your own animation.
This method will raise an exception when called on any of the built-in For example, to make the device appear happy you type:I suspect you can remember what the first line does. ImageList_Write: Writes an image list to a stream. © Copyright 2015-2016, Multiple authors
display. To create your own animation, you need to create a list of images. It’s also possible to use a newline (n) to indicate the end of a line It’s the difference between It’s even possible to store different sorts of things in the same list:We can tell MicroPython to animate a list of images.