pxt-calliope/docs/reference/basic/show-animation.md
Sam El-Husseini e3975e65e5 pxt-microbit Accessibility PR ()
* Accessibility changes
2017-09-07 13:42:08 -07:00

1.8 KiB

show Animation

Show a group of image frames (pictures) one after another on the LED screen. It pauses the amount of time you tell it after each frame.

basic.showAnimation(`
. . # . . . # # # . . # # # .
. # # . . . . . # . . . . # .
. . # . . . . # . . . # # # .
. . # . . . # . . . . . . # .
. . # . . . # # # . . # # # .
`)

Parameters

  • leds is a string that shows which LEDs are on and off, in groups one after another.
  • interval is an optional number. It means the number of milliseconds to pause after each image frame.

Example: Animating a group of image frames

In this animation, each row is 15 spaces wide because there are three frames in the animation, and each frame is five spaces wide, just like the screen on the @boardname@.

basic.showAnimation(`
. . # . . . # # # . . # # # .
. # # . . . . . # . . . . # .
. . # . . . . # . . . # # # .
. . # . . . # . . . . . . # .
. . # . . . # # # . . # # # .
`)

~hint

If the animation is too fast, make interval bigger.

~

Example: animating frames with a pause

This example shows six frames on the screen, pausing 500 milliseconds after each frame.

In this animation, each row is 30 spaces wide because there are six frames in the animation, and each frame is five spaces wide, just like the screen.

basic.showAnimation(`
. . . . . # . . . . . . . . . . . . . # . . . . . # . . . .
. . # . . . . . . . . . # . . . . . . . . . # . . . . . . .
. # . # . . . # . . . # . # . . . # . . . # . # . . . # . .
. . # . . . . . . . . . # . . . . . . . . . # . . . . . . .
. . . . . . . . . # . . . . . # . . . . . . . . . . . . . #
`, 500)

~hint

Use forever to show an animation over and over.

~