Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Surfacing more image blocks #1371

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions libs/screen/image.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,46 @@ interface Image {
//% help=images/image/draw-rect
drawRect(x: number, y: number, w: number, h: number, c: color): void;

/**
* Draw an empty circle.
*
* @param cx The center x coordinate of the circle
* @param cy The center y coordinate of the circle
* @param r The radius of the circle
* @param c The color to draw the circle
*/
//% helper=imageDrawCircle
//% blockId=image_draw_circle
//% block="draw circle in $this at cx $cx cy $cy radius $r $c"
//% this.shadow=variables_get
//% this.defl=picture
//% c.shadow=colorindexpicker
//% inlineInputMode="inline"
//% weight=10
//% blockNamespace="images"
//% group="Drawing"
drawCircle(cx: number, cy: number, r: number, c: color): void;

/**
* Fills a circle
*
* @param cx The center x coordinate of the circle
* @param cy The center y coordinate of the circle
* @param r The radius of the circle
* @param c The color to draw the circle
*/
//% helper=imageFillCircle
//% blockId=image_fill_circle
//% block="fill circle in $this at cx $cx cy $cy radius $r $c"
//% this.shadow=variables_get
//% this.defl=picture
//% c.shadow=colorindexpicker
//% inlineInputMode="inline"
//% weight=9
//% blockNamespace="images"
//% group="Drawing"
fillCircle(cx: number, cy: number, r: number, c: color): void;

/**
* Set pixel color
*/
Expand Down Expand Up @@ -110,6 +150,19 @@ interface Image {

//% shim=ImageMethods::revision
revision(): number;

/**
* Draw given image with transparent background on the current image
*/
//% shim=ImageMethods::drawTransparentImage
//% blockNamespace="images"
//% group="Drawing"
//% block="$this draw $from at x $x y $y"
//% this.shadow=variables_get
//% this.defl="picture"
//% from.shadow=screen_image_picker
//% weight=0
drawTransparentImage(from: Image, x: int32, y: int32): void;
riknoll marked this conversation as resolved.
Show resolved Hide resolved
}

declare namespace image {
Expand Down
25 changes: 25 additions & 0 deletions libs/screen/image.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
type color = number

namespace image {
export enum Dimension {
//% block="width"
Width,
//% block="height"
Height
}

export function repeatY(count: number, image: Image) {
let arr = [image]
while (--count > 0)
Expand All @@ -24,6 +31,24 @@ namespace image {
}
return r
}

/**
* Returns the width or height of a picture.
*
* @param picture The picture to get the width or height of
* @param dimension The dimension to get
* @returns
*/
//% blockId=image_get_dimension
//% group="Create"
//% blockNamespace="images"
//% block="$picture $dimension"
//% picture.shadow=variables_get
//% picture.defl=picture
export function getDimension(picture: Image, dimension: Dimension) {
if (dimension === Dimension.Width) return picture.width;
else return picture.height;
}
}


Expand Down
22 changes: 21 additions & 1 deletion libs/screen/text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ f405100800100800 021e7c5455542800 031e007e48493000 0a1e007c45443800 0b1e00304948
611e0050586a2800 6a1e04047d040400 6b1e00083d482000 801e7c2112207c00 811e384132403800 821e7c2012217c00
831e384032413800 841e7c2110217c00 851e384230423800 f21e040972080400 f31e00b84142f800 a3207e0a7a120a00
a420a8fcaa828400 a720087e2a1c0800 ab200098a4a6bf02 ac20183c5a5a4200 af20627f22443800 9021103854101000
912108047e040800 9221101054381000 932110207e201000 9421103810103810 95212844fe442800
912108047e040800 9221101054381000 932110207e201000 9421103810103810 95212844fe442800
`,

}
Expand Down Expand Up @@ -196,7 +196,27 @@ namespace texteffects {
}

interface Image {
/**
* Prints some text to an image at a given location
*
* @param text The text to print
* @param x The pixel coordinate of the left side of the text
* @param y The pixel coordinate of the top side of the text
* @param color The color to print the text
* @param font The font to use when printing the text
* @param offsets Character offsets for text effects
*/
//% helper=imagePrint
//% blockId=image_print_text
//% blockNamespace="images"
//% inlineInputMode="inline"
//% group="Drawing"
//% block="$this print $text at x $x y $y $color"
//% this.shadow=variables_get
//% this.defl=picture
//% text.defl=abc
//% color.shadow=colorindexpicker
//% weight=5
print(text: string, x: number, y: number, color?: number, font?: image.Font, offsets?: texteffects.TextEffectState[]): void;

//% helper=imagePrintCenter
Expand Down