Add missing Image methods
This commit is contained in:
@ -25,6 +25,14 @@ namespace images {
|
||||
}
|
||||
|
||||
namespace ImageMethods {
|
||||
/**
|
||||
* Plots the image at a given column to the screen
|
||||
*/
|
||||
//% help=images/plot-image
|
||||
void plotImage(Image i, int xOffset = 0) {
|
||||
uBit.display.print(MicroBitImage(i), -xOffset, 0, 0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows an frame from the image at offset ``x offset``.
|
||||
* @param xOffset TODO
|
||||
@ -35,6 +43,16 @@ namespace ImageMethods {
|
||||
uBit.display.print(MicroBitImage(i), -xOffset, 0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the ``index``-th frame of the image on the screen.
|
||||
* @param xOffset TODO
|
||||
*/
|
||||
//% help=images/plot-frame weight=80
|
||||
void plotFrame(Image i, int xOffset) {
|
||||
// TODO showImage() used in original implementation
|
||||
plotImage(i, xOffset * 5);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scrolls an image .
|
||||
* @param frameOffset x offset moved on each animation step, eg: 5, 1, -1
|
||||
@ -51,14 +69,6 @@ namespace ImageMethods {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Plots the image at a given column to the screen
|
||||
*/
|
||||
//% help=images/plot-image
|
||||
void plotImage(Image i, int xOffset = 0) {
|
||||
uBit.display.print(MicroBitImage(i), -xOffset, 0, 0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets all pixels off.
|
||||
*/
|
||||
@ -85,4 +95,52 @@ namespace ImageMethods {
|
||||
if (pix < 0) return 0;
|
||||
return pix;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the width in columns
|
||||
*/
|
||||
//% help=functions/width
|
||||
int width(Image i) {
|
||||
return i->width;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the height in rows (always 5)
|
||||
*/
|
||||
//% shim=
|
||||
int height(Image i) {
|
||||
return i->height;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a pixel state at position ``(x,y)``
|
||||
* @param x TODO
|
||||
* @param y TODO
|
||||
* @param value TODO
|
||||
*/
|
||||
//% help=functions/set-pixel
|
||||
void setPixel(Image i, int x, int y, bool value) {
|
||||
setPixelBrightness(i, x, y, value ? 255 : 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the pixel state at position ``(x,y)``
|
||||
* @param x TODO
|
||||
* @param y TODO
|
||||
*/
|
||||
//% help=functions/pixel
|
||||
bool pixel(Image i, int x, int y) {
|
||||
return pixelBrightness(i, x, y) > 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Shows a particular frame of the image strip.
|
||||
* @param frame TODO
|
||||
*/
|
||||
//% weight=70 help=functions/show-frame
|
||||
void showFrame(Image i, int frame) {
|
||||
showImage(i, frame * 5);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user