pxt-calliope/libs/core/icons.ts

545 lines
22 KiB
TypeScript
Raw Normal View History

2017-01-31 01:51:40 +01:00
/*
The MIT License (MIT)
Copyright (c) 2013-2016 The MicroPython-on-micro:bit Developers, as listed
in the accompanying AUTHORS file
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
// Images from file microbitconstimage.cpp https://github.com/bbcmicrobit/micropython
2017-01-31 01:42:48 +01:00
enum IconNames {
2017-02-01 23:08:23 +01:00
//% block="heart"
//% jres=icons.heart
2017-01-31 00:03:50 +01:00
Heart = 0,
2017-02-01 00:54:23 +01:00
//% block="small heart"
//% jres=icons.smallheart
2017-01-31 00:03:50 +01:00
SmallHeart,
2017-02-01 00:54:23 +01:00
//% block="yes"
//% jres=icons.yes
2017-01-31 00:33:33 +01:00
Yes,
2017-02-01 00:54:23 +01:00
//% block="no"
//% jres=icons.no
2017-01-31 00:33:33 +01:00
No,
2017-02-01 00:54:23 +01:00
//% block="happy"
//% jres=icons.happy
2017-01-31 00:03:50 +01:00
Happy,
2017-02-01 00:54:23 +01:00
//% block="sad"
//% jres=icons.sad
2017-01-31 00:03:50 +01:00
Sad,
2017-02-01 00:54:23 +01:00
//% block="confused"
//% jres=icons.confused
2017-01-31 00:03:50 +01:00
Confused,
2017-02-01 00:54:23 +01:00
//% block="angry"
//% jres=icons.angry
2017-01-31 00:03:50 +01:00
Angry,
2017-02-01 00:54:23 +01:00
//% block="asleep"
//% jres=icons.asleep
2017-01-31 00:03:50 +01:00
Asleep,
2017-02-01 00:54:23 +01:00
//% block="surprised"
//% jres=icons.surprised
2017-01-31 00:03:50 +01:00
Surprised,
2017-02-01 00:54:23 +01:00
//% block="silly"
//% jres=icons.silly
2017-01-31 00:03:50 +01:00
Silly,
2017-02-01 00:54:23 +01:00
//% block="fabulous"
//% jres=icons.fabulous
2017-01-31 00:03:50 +01:00
Fabulous,
2017-02-01 00:54:23 +01:00
//% block="meh"
//% jres=icons.meh
2017-01-31 00:03:50 +01:00
Meh,
2017-02-01 00:54:23 +01:00
//% block="t-shirt"
//% jres=icons.tshirt
2017-01-31 00:03:50 +01:00
TShirt,
2017-02-01 00:54:23 +01:00
//% block="roller skate"
//% jres=icons.rollerskate
2017-01-31 00:03:50 +01:00
Rollerskate,
2017-02-01 00:54:23 +01:00
//% block="duck"
//% jres=icons.duck
2017-01-31 00:03:50 +01:00
Duck,
2017-02-01 00:54:23 +01:00
//% block="house"
//% jres=icons.house
2017-01-31 00:03:50 +01:00
House,
2017-02-01 00:54:23 +01:00
//% block="tortoise"
//% jres=icons.tortoise
2017-01-31 00:03:50 +01:00
Tortoise,
2017-02-01 00:54:23 +01:00
//% block="butterfly"
//% jres=icons.butterfly
2017-01-31 00:03:50 +01:00
Butterfly,
2017-02-01 00:54:23 +01:00
//% block="stick figure"
//% jres=icons.stickfigure
2017-01-31 00:03:50 +01:00
StickFigure,
2017-02-01 00:54:23 +01:00
//% block="ghost"
//% jres=icons.ghost
2017-01-31 00:03:50 +01:00
Ghost,
2017-02-01 00:54:23 +01:00
//% block="sword"
//% jres=icons.sword
2017-01-31 00:03:50 +01:00
Sword,
2017-02-01 00:54:23 +01:00
//% block="giraffe"
//% jres=icons.giraffe
2017-01-31 00:03:50 +01:00
Giraffe,
2017-02-01 00:54:23 +01:00
//% block="skull"
//% jres=icons.skull
2017-01-31 00:03:50 +01:00
Skull,
2017-02-01 00:54:23 +01:00
//% block="umbrella"
//% jres=icons.umbrella
2017-01-31 00:03:50 +01:00
Umbrella,
2017-02-01 00:54:23 +01:00
//% block="snake"
//% jres=icons.snake
2017-01-31 00:03:50 +01:00
Snake,
2017-02-01 00:54:23 +01:00
//% block="rabbit"
//% jres=icons.rabbit
2017-01-31 00:03:50 +01:00
Rabbit,
2017-02-01 00:54:23 +01:00
//% block="cow"
//% jres=icons.cow
2017-01-31 00:03:50 +01:00
Cow,
2017-02-01 00:54:23 +01:00
//% block="quarter note"
//% jres=icons.quarternote
2017-01-31 00:03:50 +01:00
QuarterNote,
2017-02-01 00:54:23 +01:00
//% block="eigth note"
//% jres=icons.eigthnote
2017-01-31 00:03:50 +01:00
EigthNote,
2017-02-01 00:54:23 +01:00
//% block="pitchfork"
//% jres=icons.pitchfork
2017-01-31 00:03:50 +01:00
Pitchfork,
2017-02-01 00:54:23 +01:00
//% block="target"
//% jres=icons.target
2017-01-31 00:33:33 +01:00
Target,
2017-02-01 00:54:23 +01:00
//% block="triangle"
//% jres=icons.triangle
2017-01-31 00:33:33 +01:00
Triangle,
2017-02-01 00:54:23 +01:00
//% block="left triangle"
//% jres=icons.lefttriangle
2017-01-31 00:33:33 +01:00
LeftTriangle,
2017-02-01 00:54:23 +01:00
//% block="chess board"
//% jres=icons.chessboard
2017-01-31 00:33:33 +01:00
Chessboard,
2017-02-01 00:54:23 +01:00
//% block="diamond"
//% jres=icons.diamond
2017-01-31 00:33:33 +01:00
Diamond,
2017-02-01 00:54:23 +01:00
//% block="small diamond"
//% jres=icons.smalldiamond
2017-01-31 00:33:33 +01:00
SmallDiamond,
2017-02-01 00:54:23 +01:00
//% block="square"
//% jres=icons.square
2017-01-31 00:33:33 +01:00
Square,
2017-02-01 00:54:23 +01:00
//% block="small square"
//% jres=icons.smallsquare
SmallSquare,
//% block="scissors"
//% jres=icons.scissors
Scissors
2017-01-31 00:03:50 +01:00
}
2017-02-01 23:08:23 +01:00
enum ArrowNames {
//% blockIdentity=images.arrowNumber block="North"
2017-02-01 23:08:23 +01:00
North = 0,
//% blockIdentity=images.arrowNumber block="North East"
2017-02-01 23:08:23 +01:00
NorthEast,
//% blockIdentity=images.arrowNumber block="East"
2017-02-01 23:08:23 +01:00
East,
//% blockIdentity=images.arrowNumber block="South East"
2017-02-01 23:08:23 +01:00
SouthEast,
//% blockIdentity=images.arrowNumber block="South"
2017-02-01 23:08:23 +01:00
South,
//% blockIdentity=images.arrowNumber block="South West"
2017-02-01 23:08:23 +01:00
SouthWest,
//% blockIdentity=images.arrowNumber block="West"
2017-02-01 23:08:23 +01:00
West,
//% blockIdentity=images.arrowNumber block="North West"
2017-02-01 23:08:23 +01:00
NorthWest,
}
2017-01-31 01:42:48 +01:00
namespace basic {
2017-01-31 02:05:06 +01:00
/**
* Draws the selected icon on the LED screen
* @param icon the predifined icon id
* @param interval the amount of time (milliseconds) to show the icon. Default is 600.
2017-01-31 02:05:06 +01:00
*/
//% weight=90 blockGap=8
//% blockId=basic_show_icon
2017-01-31 02:05:06 +01:00
//% block="show icon %i" icon="\uf00a"
//% parts="ledmatrix"
//% help=basic/show-icon
//% icon.fieldEditor="imagedropdown"
//% icon.fieldOptions.columns="5"
export function showIcon(icon: IconNames, interval = 600) {
2017-01-31 02:05:06 +01:00
let res = images.iconImage(icon)
res.showImage(0, interval)
2017-01-31 02:05:06 +01:00
}
/**
* Shows an arrow on screent
* @param direction the direction of the arrow
* @param interval the amount of time (milliseconds) to show the icon. Default is 600.
*/
2017-02-01 00:54:23 +01:00
//% weight=50 blockGap=8
//% blockId=basic_show_arrow
2017-02-01 00:54:23 +01:00
//% block="show arrow %i=device_arrow"
//% parts="ledmatrix"
//% advanced=true
//% help=basic/show-arrow
export function showArrow(direction: number, interval = 600) {
let res = images.arrowImage(direction)
res.showImage(0, interval)
2017-01-31 01:42:48 +01:00
}
}
2017-01-31 02:05:06 +01:00
2017-01-31 01:42:48 +01:00
namespace images {
//% weight=50 blockGap=8
//% help=images/arrow-image
//% blockId=builtin_arrow_image block="arrow image %i=device_arrow"
export function arrowImage(i: ArrowNames): Image {
switch (i) {
// compass directions
case ArrowNames.North: return images.createImage(`
. . # . .
. # # # .
# . # . #
. . # . .
. . # . .`);
case ArrowNames.NorthEast: return images.createImage(`
. . # # #
. . . # #
. . # . #
. # . . .
# . . . .`);
case ArrowNames.East: return images.createImage(`
. . # . .
. . . # .
# # # # #
. . . # .
. . # . .`);
case ArrowNames.SouthEast: return images.createImage(`
# . . . .
. # . . .
. . # . #
. . . # #
. . # # #`);
case ArrowNames.South: return images.createImage(`
. . # . .
. . # . .
# . # . #
. # # # .
. . # . .`);
case ArrowNames.SouthWest: return images.createImage(`
. . . . #
. . . # .
# . # . .
# # . . .
# # # . .`);
case ArrowNames.West: return images.createImage(`
. . # . .
. # . . .
# # # # #
. # . . .
. . # . .`);
case ArrowNames.NorthWest: return images.createImage(`
# # # . .
# # . . .
# . # . .
. . . # .
. . . . #`);
default: return images.createImage(`
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
`);
}
}
//% weight=50 blockGap=8
//% help=images/icon-image
//% blockId=builtin_image block="icon image %i"
//% i.fieldEditor="imagedropdown"
//% i.fieldOptions.width="400" i.fieldOptions.columns="5"
export function iconImage(i: IconNames): Image {
switch (i) {
case IconNames.Heart: return images.createImage(`
. # . # .
# # # # #
# # # # #
. # # # .
. . # . .`);
case IconNames.SmallHeart: return images.createImage(`
. . . . .
. # . # .
. # # # .
. . # . .
. . . . .`);
//faces
case IconNames.Happy: return images.createImage(`
. . . . .
. # . # .
. . . . .
# . . . #
. # # # .`);
case IconNames.Sad: return images.createImage(`
. . . . .
. # . # .
. . . . .
. # # # .
# . . . #`);
case IconNames.Confused: return images.createImage(`
. . . . .
. # . # .
. . . . .
. # . # .
# . # . #`);
case IconNames.Angry: return images.createImage(`
# . . . #
. # . # .
. . . . .
# # # # #
# . # . #`);
case IconNames.Asleep: return images.createImage(`
. . . . .
# # . # #
. . . . .
. # # # .
. . . . .`);
case IconNames.Surprised: return images.createImage(`
. # . # .
. . . . .
. . # . .
. # . # .
. . # . .`);
case IconNames.Silly: return images.createImage(`
# . . . #
. . . . .
# # # # #
. . . # #
. . . # #`);
case IconNames.Fabulous: return images.createImage(`
# # # # #
# # . # #
. . . . .
. # . # .
. # # # .`);
case IconNames.Meh: return images.createImage(`
# # . # #
. . . . .
. . . # .
. . # . .
. # . . .`);
case IconNames.Yes: return images.createImage(`
. . . . .
. . . . #
. . . # .
# . # . .
. # . . .`);
case IconNames.No: return images.createImage(`
# . . . #
. # . # .
. . # . .
. # . # .
# . . . #`);
case IconNames.Triangle: return images.createImage(`
. . . . .
. . # . .
. # . # .
# # # # #
. . . . .`);
case IconNames.LeftTriangle: return images.createImage(`
# . . . .
# # . . .
# . # . .
# . . # .
# # # # #`);
case IconNames.Chessboard: return images.createImage(`
. # . # .
# . # . #
. # . # .
# . # . #
. # . # .`);
case IconNames.Diamond: return images.createImage(`
. . # . .
. # . # .
# . . . #
. # . # .
. . # . .`);
case IconNames.SmallDiamond: return images.createImage(`
. . . . .
. . # . .
. # . # .
. . # . .
. . . . .`);
case IconNames.Square: return images.createImage(`
# # # # #
# . . . #
# . . . #
# . . . #
# # # # #`);
case IconNames.SmallSquare: return images.createImage(`
. . . . .
. # # # .
. # . # .
. # # # .
. . . . .`);
case IconNames.Scissors: return images.createImage(`
# # . . #
# # . # .
. . # . .
# # . # .
# # . . #`);
// The following images were designed by Abbie Brooks.
case IconNames.TShirt: return images.createImage(`
# # . # #
# # # # #
. # # # .
. # # # .
. # # # .`);
case IconNames.Rollerskate: return images.createImage(`
. . . # #
. . . # #
# # # # #
# # # # #
. # . # .`);
case IconNames.Duck: return images.createImage(`
. # # . .
# # # . .
. # # # #
. # # # .
2017-06-08 01:43:29 +02:00
. . . . .`);
case IconNames.House: return images.createImage(`
. . # . .
. # # # .
# # # # #
. # # # .
. # . # .`);
case IconNames.Tortoise: return images.createImage(`
. . . . .
. # # # .
# # # # #
. # . # .
. . . . .`);
case IconNames.Butterfly: return images.createImage(`
# # . # #
# # # # #
. . # . .
# # # # #
# # . # #`);
case IconNames.StickFigure: return images.createImage(`
. . # . .
# # # # #
. . # . .
. # . # .
# . . . #`);
case IconNames.Ghost: return images.createImage(`
. # # # .
# . # . #
# # # # #
# # # # #
# . # . #`);
case IconNames.Sword: return images.createImage(`
. . # . .
. . # . .
. . # . .
. # # # .
. . # . .`);
case IconNames.Giraffe: return images.createImage(`
# # . . .
. # . . .
. # . . .
. # # # .
. # . # .`);
case IconNames.Skull: return images.createImage(`
. # # # .
# . # . #
# # # # #
. # # # .
. # # # .`);
case IconNames.Umbrella: return images.createImage(`
. # # # .
# # # # #
. . # . .
# . # . .
# # # . .`);
case IconNames.Snake: return images.createImage(`
# # . . .
# # . # #
. # . # .
. # # # .
. . . . .`);
// animals
case IconNames.Rabbit: return images.createImage(`
# . # . .
# . # . .
# # # # .
# # . # .
# # # # .`);
case IconNames.Cow: return images.createImage(`
# . . . #
# . . . #
# # # # #
. # # # .
. . # . .`);
// musical notes
case IconNames.QuarterNote: return images.createImage(`
. . # . .
. . # . .
. . # . .
# # # . .
# # # . .`);
case IconNames.EigthNote: return images.createImage(`
. . # . .
. . # # .
. . # . #
# # # . .
# # # . .`);
// other icons
case IconNames.Pitchfork: return images.createImage(`
# . # . #
# . # . #
# # # # #
. . # . .
. . # . .`);
case IconNames.Target: return images.createImage(`
. . # . .
. # # # .
# # . # #
. # # # .
. . # . .`);
default: return images.createImage(`
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
`);
}
}
2017-01-31 00:03:50 +01:00
2017-02-01 00:54:23 +01:00
//% weight=50 blockGap=8
//% help=images/arrow-number
2017-01-31 00:03:50 +01:00
//% blockId=device_arrow block="%arrow"
//% shim=TD_ID
export function arrowNumber(arrow: ArrowNames): number {
return arrow;
}
}