added showimage

This commit is contained in:
Peli de Halleux 2017-11-16 22:46:51 -08:00
parent f27fb4d93c
commit b2768b1099
3 changed files with 32 additions and 0 deletions

View File

@ -20,6 +20,8 @@
"brick.Button.onEvent": "Do something when a button or sensor is clicked, up or down.",
"brick.Button.onEvent|param|body": "code to run when the event is raised",
"brick.Button.wasPressed": "See if the button was pressed again since the last time you checked.",
"brick._imagePicker": "An image",
"brick._imagePicker|param|image": "the image",
"brick.buttonDown": "Down button on the EV3 Brick.",
"brick.buttonEnter": "Enter button on the EV3 Brick.",
"brick.buttonLeft": "Left button on the EV3 Brick.",
@ -37,6 +39,8 @@
"brick.setPixel|param|y": "the starting position's x coordinate, eg: 0",
"brick.setStatusLight": "Set lights.",
"brick.setStatusLight|param|pattern": "the lights pattern to use.",
"brick.showImage": "Shows an image on screen",
"brick.showImage|param|image": "image to draw",
"control": "Program controls and events.",
"control.allocateNotifyEvent": "Allocates the next user notification event",
"control.deviceFirmwareVersion": "Determine the version of system software currently running.",

View File

@ -35,6 +35,7 @@
"brick.Button.isPressed|block": "%button|is pressed",
"brick.Button.onEvent|block": "on %button|%event",
"brick.Button.wasPressed|block": "%button|was pressed",
"brick._imagePicker|block": "%image",
"brick.buttonDown|block": "button down",
"brick.buttonEnter|block": "button enter",
"brick.buttonLeft|block": "button left",
@ -44,6 +45,7 @@
"brick.print|block": "print %text| at x: %x| y: %y",
"brick.setPixel|block": "set pixel %on| at x: %x| y: %y",
"brick.setStatusLight|block": "set status light %pattern=led_pattern",
"brick.showImage|block": "show image %image=scren_image_picker",
"brick|block": "brick",
"control.raiseEvent|block": "raise event|from %src|with value %value",
"control|block": "control",

View File

@ -133,6 +133,32 @@ namespace brick {
}
}
/**
* Shows an image on screen
* @param image image to draw
*/
//% blockId=screen_show_image block="show image %image=scren_image_picker"
//% weight=95 group="Screen" blockGap=8
export function showImage(image: Image, delay: number = 400) {
if (!image) return;
image.draw(0, 0, Draw.Normal);
delay = Math.max(0, delay);
loops.pause(delay);
}
/**
* An image
* @param image the image
*/
//% blockId=scren_image_picker block="%image" shim=TD_ID
//% image.fieldEditor="imagedropdown"
//% image.fieldOptions.columns=8
//% block.fieldOptions.hasSearchBar=true
//% group="Screen" weight=0 blockHidden=1
export function _imagePicker(image: Image): Image {
return image;
}
export function drawRect(x: number, y: number, w: number, h: number, mode = Draw.Normal) {
x |= 0;
y |= 0;