missing images blocks

This commit is contained in:
Peli de Halleux 2016-05-26 20:42:15 -07:00
parent 21280f41bc
commit f4afa773ad
3 changed files with 36 additions and 35 deletions

View File

@ -35,17 +35,17 @@ namespace ImageMethods {
/**
* Shows an frame from the image at offset ``x offset``.
* @param xOffset TODO
* @param xOffset column index to start displaying the image
*/
//% help=images/show-image weight=80 async
//% BUGblockId=device_show_image_offset block="show image %sprite|at offset %offset" blockGap=8
void showImage(Image i, int xOffset = 0) {
uBit.display.print(MicroBitImage(i), -xOffset, 0, 0);
//% help=images/show-image weight=80 blockNamespace=images
//% blockId=device_show_image_offset block="show image %sprite|at offset %offset" blockGap=8
void showImage(Image sprite, int xOffset) {
uBit.display.print(MicroBitImage(sprite), -xOffset, 0, 0);
}
/**
* Draws the ``index``-th frame of the image on the screen.
* @param xOffset TODO
* @param xOffset column index to start displaying the image
*/
//% help=images/plot-frame weight=80
void plotFrame(Image i, int xOffset) {
@ -58,9 +58,9 @@ namespace ImageMethods {
* @param frameOffset x offset moved on each animation step, eg: 5, 1, -1
* @param interval time between each animation step in milli seconds, eg: 200
*/
//% help=images/show-image weight=79 async
//% BUGblockId=device_scroll_image block="scroll image %sprite|with offset %frameoffset|and interval (ms) %delay" blockGap=8
void scrollImage(Image id, int frameOffset = 0, int interval = 200) {
//% help=images/show-image weight=79 async blockNamespace=images
//% blockId=device_scroll_image block="scroll image %sprite|with offset %frameoffset|and interval (ms) %delay" blockGap=8
void scrollImage(Image id, int frameOffset, int interval) {
MicroBitImage i(id);
if (i.getWidth() <= 5)
showImage(id, 0);
@ -80,7 +80,7 @@ namespace ImageMethods {
/**
* Sets a specific pixel brightness at a given position
*/
//% help=
//%
void setPixelBrightness(Image i, int x, int y, int value) {
MicroBitImage(i).setPixelValue(x, y, value);
}
@ -89,7 +89,7 @@ namespace ImageMethods {
/**
* Gets the pixel brightness ([0..255]) at a given position
*/
//% help=
//%
int pixelBrightness(Image i, int x, int y) {
int pix = MicroBitImage(i).getPixelValue(x, y);
if (pix < 0) return 0;
@ -108,7 +108,7 @@ namespace ImageMethods {
/**
* Gets the height in rows (always 5)
*/
//% shim=
//%
int height(Image i) {
return i->height;
}
@ -119,7 +119,7 @@ namespace ImageMethods {
* @param y TODO
* @param value TODO
*/
//% help=functions/set-pixel
//% help=images/set-pixel
void setPixel(Image i, int x, int y, bool value) {
setPixelBrightness(i, x, y, value ? 255 : 0);
}
@ -129,7 +129,7 @@ namespace ImageMethods {
* @param x TODO
* @param y TODO
*/
//% help=functions/pixel
//% help=images/pixel
bool pixel(Image i, int x, int y) {
return pixelBrightness(i, x, y) > 0;
}
@ -139,7 +139,7 @@ namespace ImageMethods {
* Shows a particular frame of the image strip.
* @param frame TODO
*/
//% weight=70 help=functions/show-frame
//% weight=70 help=images/show-frame
void showFrame(Image i, int frame) {
showImage(i, frame * 5);
}

View File

@ -32,15 +32,15 @@ declare interface Image {
/**
* Shows an frame from the image at offset ``x offset``.
* @param xOffset TODO
* @param xOffset column index to start displaying the image
*/
//% help=images/show-image weight=80 async
//% BUGblockId=device_show_image_offset block="show image %sprite|at offset %offset" blockGap=8 xOffset.defl=0 shim=ImageMethods::showImage
showImage(xOffset?: number): void;
//% help=images/show-image weight=80 blockNamespace=images
//% blockId=device_show_image_offset block="show image %sprite|at offset %offset" blockGap=8 shim=ImageMethods::showImage
showImage(xOffset: number): void;
/**
* Draws the ``index``-th frame of the image on the screen.
* @param xOffset TODO
* @param xOffset column index to start displaying the image
*/
//% help=images/plot-frame weight=80 shim=ImageMethods::plotFrame
plotFrame(xOffset: number): void;
@ -50,9 +50,9 @@ declare interface Image {
* @param frameOffset x offset moved on each animation step, eg: 5, 1, -1
* @param interval time between each animation step in milli seconds, eg: 200
*/
//% help=images/show-image weight=79 async
//% BUGblockId=device_scroll_image block="scroll image %sprite|with offset %frameoffset|and interval (ms) %delay" blockGap=8 frameOffset.defl=0 interval.defl=200 shim=ImageMethods::scrollImage
scrollImage(frameOffset?: number, interval?: number): void;
//% help=images/show-image weight=79 async blockNamespace=images
//% blockId=device_scroll_image block="scroll image %sprite|with offset %frameoffset|and interval (ms) %delay" blockGap=8 shim=ImageMethods::scrollImage
scrollImage(frameOffset: number, interval: number): void;
/**
* Sets all pixels off.
@ -63,13 +63,13 @@ declare interface Image {
/**
* Sets a specific pixel brightness at a given position
*/
//% help= shim=ImageMethods::setPixelBrightness
//% shim=ImageMethods::setPixelBrightness
setPixelBrightness(x: number, y: number, value: number): void;
/**
* Gets the pixel brightness ([0..255]) at a given position
*/
//% help= shim=ImageMethods::pixelBrightness
//% shim=ImageMethods::pixelBrightness
pixelBrightness(x: number, y: number): number;
/**
@ -81,7 +81,7 @@ declare interface Image {
/**
* Gets the height in rows (always 5)
*/
//% shim= shim=ImageMethods::height
//% shim=ImageMethods::height
height(): number;
/**
@ -90,7 +90,7 @@ declare interface Image {
* @param y TODO
* @param value TODO
*/
//% help=functions/set-pixel shim=ImageMethods::setPixel
//% help=images/set-pixel shim=ImageMethods::setPixel
setPixel(x: number, y: number, value: boolean): void;
/**
@ -98,14 +98,14 @@ declare interface Image {
* @param x TODO
* @param y TODO
*/
//% help=functions/pixel shim=ImageMethods::pixel
//% help=images/pixel shim=ImageMethods::pixel
pixel(x: number, y: number): boolean;
/**
* Shows a particular frame of the image strip.
* @param frame TODO
*/
//% weight=70 help=functions/show-frame shim=ImageMethods::showFrame
//% weight=70 help=images/show-frame shim=ImageMethods::showFrame
showFrame(frame: number): void;
}

View File

@ -187,7 +187,7 @@ namespace pxsim.basic {
if (interval < 0) return;
let leds = createImageFromString(x.toString());
if (x < 0 || x >= 10) ImageMethods.scrollImage(leds, interval, 1);
if (x < 0 || x >= 10) ImageMethods.scrollImage(leds, 1, interval);
else showLeds(leds, interval * 5);
}
@ -198,7 +198,7 @@ namespace pxsim.basic {
pause(interval * 5);
} else {
if (s.length == 1) showLeds(createImageFromString(s), interval * 5)
else ImageMethods.scrollImage(createImageFromString(s + " "), interval, 1);
else ImageMethods.scrollImage(createImageFromString(s + " "), 1, interval);
}
}
@ -211,8 +211,8 @@ namespace pxsim.basic {
runtime.queueDisplayUpdate()
}
export function showAnimation(leds: Image, interval: number = 400): void {
ImageMethods.scrollImage(leds, interval, 5);
export function showAnimation(leds: Image, interval: number): void {
ImageMethods.scrollImage(leds, 5, interval);
}
export function plotLeds(leds: Image): void {
@ -674,10 +674,11 @@ namespace pxsim.ImageMethods {
return i.get(x, y);
}
export function scrollImage(leds: Image, interval: number, stride: number): void {
export function scrollImage(leds: Image, stride: number, interval: number): void {
if (!leds) panic(PanicCode.MICROBIT_NULL_DEREFERENCE);
if (stride == 0) stride = 1;
let cb = getResume()
let cb = getResume();
let off = stride > 0 ? 0 : leds.width - 1;
let display = board().image;