From 240162370e7dca35e1af9691d983b103d0c2e526 Mon Sep 17 00:00:00 2001 From: Ron Hale-Evans Date: Mon, 20 Jun 2016 13:18:41 -0700 Subject: [PATCH] Rewrote in simple language. New example. --- docs/reference/images/scroll-image.md | 89 ++++++++++----------------- 1 file changed, 32 insertions(+), 57 deletions(-) diff --git a/docs/reference/images/scroll-image.md b/docs/reference/images/scroll-image.md index 0ca0f46a..19379977 100644 --- a/docs/reference/images/scroll-image.md +++ b/docs/reference/images/scroll-image.md @@ -1,70 +1,45 @@ # Scroll Image -The scroll image function. - -Scrolls the frames within an [Image](/reference/images/image) on the [LED screen](/device/screen). - -### Block Editor - -![](/static/mb/scroll-image-0.png) - -### JavaScript - -``` -export function scrollImage(_this: micro_bit.Image, xOffsetPerStep: number, interval: number) -``` +Scroll (slide) an [image](/reference/images/image) (picture) from one +side to the other of the [LED screen](/device/screen). ### Parameters -* x offset per step : [Number](/reference/types/number) - the number of columns to scroll at a time (horizontal offset). Use a positive number to scroll an image to the right and a negative number to scroll left. To jump from one image frame to the next, use an offset of 5 or -5. -* interval (ms) : [Number](/reference/types/number) - the time (in milliseconds) before scrolling by `x offset per step`; the larger the number, the slower the scroll. +* ``offset`` is a [number](/reference/types/number) that means + how many LEDs to scroll at a time, from right to left or + left to right. If you use a positive number like `2`, the image + will scroll from the right side of the screen to the left. + If you use a negative number like `-2`, the image will scroll + in the other direction. If you use `5` or `-5`, the image + will scroll one **frame** at a time. (A frame is a part of the + image. It is a square with five LEDs on a side). This is + useful for **animation**. -### ~hide +* ``interval (ms)`` is a [number](/reference/types/number) that means + how many milliseconds to wait before scrolling the amount that + ``offset`` says. (1000 milliseconds is one second.) The bigger you + make this number, the slower the image will scroll. -``` -let img = images.createImage(` -. . # . . . # # # . . # # # . -. . # . . . . . # . . . . # . -. . # . . . . # . . . # # # . -. . # . . . # . . . . . . # . -. . # . . . # # # . . # # # . -`) -``` +### Example -### ~ +This program scrolls an image of two arrows five LEDs at a time, +with a pause of 200 milliseconds between each time it scrolls. +Because each frame is five LEDs wide, that means this program +will look like it's animating one arrow flipping and flopping. +Of course, you can use any two frames you want instead. -To scroll an image 1 column at a time to the right: -``` -img.scrollImage(1, 1000) -``` - -To scroll an image 5 columns at a time (skip from frame to frame): - -``` -img.scrollImage(5, 1000) -``` - -To scroll an image 1 column at a time to the left: - -``` -img.scrollImage(-1, 500) -``` - -### Example: scroll through frames - -This example creates an image with 3 frames, then scrolls through the 3 frames: - -``` -img = images.createImage(` -. . # . . . # # # . . # # # . -. . # . . . . . # . . . . # . -. . # . . . . # . . . # # # . -. . # . . . # . . . . . . # . -. . # . . . # # # . . # # # . -`) -img.showImage(0) -img.scrollImage(5, 1000) +```blocks +let arrows = images.createBigImage(` + . . # . . . . # . . + . # # # . . . # . . + # . # . # # . # . # + . . # . . . # # # . + . . # . . . . # . . + `); +basic.forever(() => { + arrows.scrollImage(5, 200); +}); ``` ### See also