pxt-calliope/libs/core/icons.ts

549 lines
22 KiB
TypeScript
Raw Normal View History

2017-02-28 18:50:29 +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
enum IconNames {
//% block="heart"
//% jres=icons.heart
2017-02-28 18:50:29 +01:00
Heart = 0,
//% block="small heart"
//% jres=icons.smallheart
2017-02-28 18:50:29 +01:00
SmallHeart,
//% block="yes"
//% jres=icons.yes
2017-02-28 18:50:29 +01:00
Yes,
//% block="no"
//% jres=icons.no
2017-02-28 18:50:29 +01:00
No,
//% block="happy"
//% jres=icons.happy
2017-02-28 18:50:29 +01:00
Happy,
//% block="sad"
//% jres=icons.sad
2017-02-28 18:50:29 +01:00
Sad,
//% block="confused"
//% jres=icons.confused
2017-02-28 18:50:29 +01:00
Confused,
//% block="angry"
//% jres=icons.angry
2017-02-28 18:50:29 +01:00
Angry,
//% block="asleep"
//% jres=icons.asleep
2017-02-28 18:50:29 +01:00
Asleep,
//% block="surprised"
//% jres=icons.surprised
2017-02-28 18:50:29 +01:00
Surprised,
//% block="silly"
//% jres=icons.silly
2017-02-28 18:50:29 +01:00
Silly,
//% block="fabulous"
//% jres=icons.fabulous
2017-02-28 18:50:29 +01:00
Fabulous,
//% block="meh"
//% jres=icons.meh
2017-02-28 18:50:29 +01:00
Meh,
//% block="t-shirt"
//% jres=icons.tshirt
2017-02-28 18:50:29 +01:00
TShirt,
//% block="roller skate"
//% jres=icons.rollerskate
2017-02-28 18:50:29 +01:00
Rollerskate,
//% block="duck"
//% jres=icons.duck
2017-02-28 18:50:29 +01:00
Duck,
//% block="house"
//% jres=icons.house
2017-02-28 18:50:29 +01:00
House,
//% block="tortoise"
//% jres=icons.tortoise
2017-02-28 18:50:29 +01:00
Tortoise,
//% block="butterfly"
//% jres=icons.butterfly
2017-02-28 18:50:29 +01:00
Butterfly,
//% block="stick figure"
//% jres=icons.stickfigure
2017-02-28 18:50:29 +01:00
StickFigure,
//% block="ghost"
//% jres=icons.ghost
2017-02-28 18:50:29 +01:00
Ghost,
//% block="sword"
//% jres=icons.sword
2017-02-28 18:50:29 +01:00
Sword,
//% block="giraffe"
//% jres=icons.giraffe
2017-02-28 18:50:29 +01:00
Giraffe,
//% block="skull"
//% jres=icons.skull
2017-02-28 18:50:29 +01:00
Skull,
//% block="umbrella"
//% jres=icons.umbrella
2017-02-28 18:50:29 +01:00
Umbrella,
//% block="snake"
//% jres=icons.snake
2017-02-28 18:50:29 +01:00
Snake,
//% block="rabbit"
//% jres=icons.rabbit
2017-02-28 18:50:29 +01:00
Rabbit,
//% block="cow"
//% jres=icons.cow
2017-02-28 18:50:29 +01:00
Cow,
//% block="quarter note"
//% jres=icons.quarternote
2017-02-28 18:50:29 +01:00
QuarterNote,
//% block="eigth note"
//% jres=icons.eigthnote
2017-02-28 18:50:29 +01:00
EigthNote,
//% block="pitchfork"
//% jres=icons.pitchfork
2017-02-28 18:50:29 +01:00
Pitchfork,
//% block="target"
//% jres=icons.target
2017-02-28 18:50:29 +01:00
Target,
//% block="triangle"
//% jres=icons.triangle
2017-02-28 18:50:29 +01:00
Triangle,
//% block="left triangle"
//% jres=icons.lefttriangle
2017-02-28 18:50:29 +01:00
LeftTriangle,
//% block="chess board"
//% jres=icons.chessboard
2017-02-28 18:50:29 +01:00
Chessboard,
//% block="diamond"
//% jres=icons.diamond
2017-02-28 18:50:29 +01:00
Diamond,
//% block="small diamond"
//% jres=icons.smalldiamond
2017-02-28 18:50:29 +01:00
SmallDiamond,
//% block="square"
//% jres=icons.square
2017-02-28 18:50:29 +01:00
Square,
//% block="small square"
//% jres=icons.smallsquare
2017-12-14 20:04:59 +01:00
SmallSquare,
//% block="scissors"
//% jres=icons.scissors
2017-12-14 20:04:59 +01:00
Scissors
2017-02-28 18:50:29 +01:00
}
enum ArrowNames {
2017-12-14 20:04:59 +01:00
//% blockIdentity=images.arrowNumber block="North"
2017-02-28 18:50:29 +01:00
North = 0,
2017-12-14 20:04:59 +01:00
//% blockIdentity=images.arrowNumber block="North East"
2017-02-28 18:50:29 +01:00
NorthEast,
2017-12-14 20:04:59 +01:00
//% blockIdentity=images.arrowNumber block="East"
2017-02-28 18:50:29 +01:00
East,
2017-12-14 20:04:59 +01:00
//% blockIdentity=images.arrowNumber block="South East"
2017-02-28 18:50:29 +01:00
SouthEast,
2017-12-14 20:04:59 +01:00
//% blockIdentity=images.arrowNumber block="South"
2017-02-28 18:50:29 +01:00
South,
2017-12-14 20:04:59 +01:00
//% blockIdentity=images.arrowNumber block="South West"
2017-02-28 18:50:29 +01:00
SouthWest,
2017-12-14 20:04:59 +01:00
//% blockIdentity=images.arrowNumber block="West"
2017-02-28 18:50:29 +01:00
West,
2017-12-14 20:04:59 +01:00
//% blockIdentity=images.arrowNumber block="North West"
2017-02-28 18:50:29 +01:00
NorthWest,
}
namespace basic {
/**
* Draws the selected icon on the LED screen
* @param icon the predefined icon id
2017-12-14 20:04:59 +01:00
* @param interval the amount of time (milliseconds) to show the icon. Default is 600.
2017-02-28 18:50:29 +01:00
*/
//% weight=90 blockGap=8
2017-12-14 20:04:59 +01:00
//% blockId=basic_show_icon
2017-02-28 18:50:29 +01:00
//% block="show icon %i" icon="\uf00a"
//% parts="ledmatrix"
//% help=basic/show-icon
//% icon.fieldEditor="imagedropdown"
//% icon.fieldOptions.columns="5"
//% icon.fieldOptions.width="380"
//% icon.fieldOptions.maxRows=4
2017-12-14 20:04:59 +01:00
export function showIcon(icon: IconNames, interval = 600) {
2017-02-28 18:50:29 +01:00
let res = images.iconImage(icon)
2017-12-14 20:04:59 +01:00
res.showImage(0, interval)
2017-02-28 18:50:29 +01:00
}
2017-12-14 20:04:59 +01:00
/**
* Draws an arrow on the LED screen
2017-12-14 20:04:59 +01:00
* @param direction the direction of the arrow
* @param interval the amount of time (milliseconds) to show the icon. Default is 600.
*/
2017-02-28 18:50:29 +01:00
//% weight=50 blockGap=8
2017-12-14 20:04:59 +01:00
//% blockId=basic_show_arrow
2017-02-28 18:50:29 +01:00
//% block="show arrow %i=device_arrow"
//% parts="ledmatrix"
//% advanced=true
//% help=basic/show-arrow
2017-12-14 20:04:59 +01:00
export function showArrow(direction: number, interval = 600) {
let res = images.arrowImage(direction)
res.showImage(0, interval)
2017-02-28 18:50:29 +01:00
}
}
namespace images {
2017-12-14 20:04:59 +01:00
//% weight=50 blockGap=8
//% help=images/arrow-image
2020-08-19 22:03:58 +02:00
//% blockId=builtin_arrow_image block="arrow image %i"
2017-12-14 20:04:59 +01:00
export function arrowImage(i: ArrowNames): Image {
switch (i) {
2017-02-28 18:50:29 +01:00
// compass directions
case ArrowNames.North: return images.createImage(`
2017-02-28 18:50:29 +01:00
. . # . .
. # # # .
# . # . #
. . # . .
2017-12-14 20:04:59 +01:00
. . # . .`);
case ArrowNames.NorthEast: return images.createImage(`
2017-02-28 18:50:29 +01:00
. . # # #
. . . # #
. . # . #
. # . . .
2017-12-14 20:04:59 +01:00
# . . . .`);
case ArrowNames.East: return images.createImage(`
2017-02-28 18:50:29 +01:00
. . # . .
. . . # .
# # # # #
. . . # .
2017-12-14 20:04:59 +01:00
. . # . .`);
case ArrowNames.SouthEast: return images.createImage(`
2017-02-28 18:50:29 +01:00
# . . . .
. # . . .
. . # . #
. . . # #
2017-12-14 20:04:59 +01:00
. . # # #`);
case ArrowNames.South: return images.createImage(`
2017-02-28 18:50:29 +01:00
. . # . .
. . # . .
# . # . #
. # # # .
2017-12-14 20:04:59 +01:00
. . # . .`);
case ArrowNames.SouthWest: return images.createImage(`
2017-02-28 18:50:29 +01:00
. . . . #
. . . # .
# . # . .
# # . . .
2017-12-14 20:04:59 +01:00
# # # . .`);
case ArrowNames.West: return images.createImage(`
2017-02-28 18:50:29 +01:00
. . # . .
. # . . .
# # # # #
. # . . .
2017-12-14 20:04:59 +01:00
. . # . .`);
case ArrowNames.NorthWest: return images.createImage(`
2017-02-28 18:50:29 +01:00
# # # . .
# # . . .
# . # . .
. . . # .
2017-12-14 20:04:59 +01:00
. . . . #`);
default: return images.createImage(`
2017-02-28 18:50:29 +01:00
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
2017-12-14 20:04:59 +01:00
`);
}
2017-02-28 18:50:29 +01:00
}
2017-12-14 20:04:59 +01:00
//% weight=50 blockGap=8
//% help=images/icon-image
//% blockId=builtin_image block="icon image %i"
//% i.fieldEditor="imagedropdown"
//% i.fieldOptions.columns="5"
//% i.fieldOptions.width="380"
//% i.fieldOptions.maxRows=4
2017-12-14 20:04:59 +01:00
export function iconImage(i: IconNames): Image {
switch (i) {
case IconNames.Heart: return images.createImage(`
2017-02-28 18:50:29 +01:00
. # . # .
# # # # #
# # # # #
. # # # .
2017-12-14 20:04:59 +01:00
. . # . .`);
2017-02-28 18:50:29 +01:00
2017-12-14 20:04:59 +01:00
case IconNames.SmallHeart: return images.createImage(`
2017-02-28 18:50:29 +01:00
. . . . .
. # . # .
. # # # .
. . # . .
2017-12-14 20:04:59 +01:00
. . . . .`);
//faces
case IconNames.Happy: return images.createImage(`
2017-02-28 18:50:29 +01:00
. . . . .
. # . # .
. . . . .
# . . . #
2017-12-14 20:04:59 +01:00
. # # # .`);
case IconNames.Sad: return images.createImage(`
2017-02-28 18:50:29 +01:00
. . . . .
. # . # .
. . . . .
. # # # .
2017-12-14 20:04:59 +01:00
# . . . #`);
case IconNames.Confused: return images.createImage(`
2017-02-28 18:50:29 +01:00
. . . . .
. # . # .
. . . . .
. # . # .
2017-12-14 20:04:59 +01:00
# . # . #`);
case IconNames.Angry: return images.createImage(`
2017-02-28 18:50:29 +01:00
# . . . #
. # . # .
. . . . .
# # # # #
2017-12-14 20:04:59 +01:00
# . # . #`);
case IconNames.Asleep: return images.createImage(`
2017-02-28 18:50:29 +01:00
. . . . .
# # . # #
. . . . .
. # # # .
2017-12-14 20:04:59 +01:00
. . . . .`);
case IconNames.Surprised: return images.createImage(`
2017-02-28 18:50:29 +01:00
. # . # .
. . . . .
. . # . .
. # . # .
2017-12-14 20:04:59 +01:00
. . # . .`);
case IconNames.Silly: return images.createImage(`
2017-02-28 18:50:29 +01:00
# . . . #
. . . . .
# # # # #
. . . # #
2017-12-14 20:04:59 +01:00
. . . # #`);
case IconNames.Fabulous: return images.createImage(`
2017-02-28 18:50:29 +01:00
# # # # #
# # . # #
. . . . .
. # . # .
2017-12-14 20:04:59 +01:00
. # # # .`);
case IconNames.Meh: return images.createImage(`
2017-02-28 18:50:29 +01:00
# # . # #
. . . . .
. . . # .
. . # . .
2017-12-14 20:04:59 +01:00
. # . . .`);
case IconNames.Yes: return images.createImage(`
2017-02-28 18:50:29 +01:00
. . . . .
. . . . #
. . . # .
# . # . .
2017-12-14 20:04:59 +01:00
. # . . .`);
case IconNames.No: return images.createImage(`
2017-02-28 18:50:29 +01:00
# . . . #
. # . # .
. . # . .
. # . # .
2017-12-14 20:04:59 +01:00
# . . . #`);
case IconNames.Triangle: return images.createImage(`
2017-02-28 18:50:29 +01:00
. . . . .
. . # . .
. # . # .
# # # # #
2017-12-14 20:04:59 +01:00
. . . . .`);
case IconNames.LeftTriangle: return images.createImage(`
2017-02-28 18:50:29 +01:00
# . . . .
# # . . .
# . # . .
# . . # .
2017-12-14 20:04:59 +01:00
# # # # #`);
case IconNames.Chessboard: return images.createImage(`
2017-02-28 18:50:29 +01:00
. # . # .
# . # . #
. # . # .
# . # . #
2017-12-14 20:04:59 +01:00
. # . # .`);
case IconNames.Diamond: return images.createImage(`
2017-02-28 18:50:29 +01:00
. . # . .
. # . # .
# . . . #
. # . # .
2017-12-14 20:04:59 +01:00
. . # . .`);
case IconNames.SmallDiamond: return images.createImage(`
2017-02-28 18:50:29 +01:00
. . . . .
. . # . .
. # . # .
. . # . .
2017-12-14 20:04:59 +01:00
. . . . .`);
case IconNames.Square: return images.createImage(`
2017-02-28 18:50:29 +01:00
# # # # #
# . . . #
# . . . #
# . . . #
2017-12-14 20:04:59 +01:00
# # # # #`);
case IconNames.SmallSquare: return images.createImage(`
2017-02-28 18:50:29 +01:00
. . . . .
. # # # .
. # . # .
. # # # .
2017-12-14 20:04:59 +01:00
. . . . .`);
case IconNames.Scissors: return images.createImage(`
# # . . #
# # . # .
. . # . .
# # . # .
# # . . #`);
// The following images were designed by Abbie Brooks.
case IconNames.TShirt: return images.createImage(`
2017-02-28 18:50:29 +01:00
# # . # #
# # # # #
. # # # .
. # # # .
2017-12-14 20:04:59 +01:00
. # # # .`);
case IconNames.Rollerskate: return images.createImage(`
2017-02-28 18:50:29 +01:00
. . . # #
. . . # #
# # # # #
# # # # #
2017-12-14 20:04:59 +01:00
. # . # .`);
case IconNames.Duck: return images.createImage(`
2017-02-28 18:50:29 +01:00
. # # . .
# # # . .
. # # # #
. # # # .
2017-12-14 20:04:59 +01:00
. . . . .`);
case IconNames.House: return images.createImage(`
2017-02-28 18:50:29 +01:00
. . # . .
. # # # .
# # # # #
. # # # .
2017-12-14 20:04:59 +01:00
. # . # .`);
case IconNames.Tortoise: return images.createImage(`
2017-02-28 18:50:29 +01:00
. . . . .
. # # # .
# # # # #
. # . # .
2017-12-14 20:04:59 +01:00
. . . . .`);
case IconNames.Butterfly: return images.createImage(`
2017-02-28 18:50:29 +01:00
# # . # #
# # # # #
. . # . .
# # # # #
2017-12-14 20:04:59 +01:00
# # . # #`);
case IconNames.StickFigure: return images.createImage(`
2017-02-28 18:50:29 +01:00
. . # . .
# # # # #
. . # . .
. # . # .
2017-12-14 20:04:59 +01:00
# . . . #`);
case IconNames.Ghost: return images.createImage(`
2017-02-28 18:50:29 +01:00
. # # # .
# . # . #
# # # # #
# # # # #
2017-12-14 20:04:59 +01:00
# . # . #`);
case IconNames.Sword: return images.createImage(`
2017-02-28 18:50:29 +01:00
. . # . .
. . # . .
. . # . .
. # # # .
2017-12-14 20:04:59 +01:00
. . # . .`);
case IconNames.Giraffe: return images.createImage(`
2017-02-28 18:50:29 +01:00
# # . . .
. # . . .
. # . . .
. # # # .
2017-12-14 20:04:59 +01:00
. # . # .`);
case IconNames.Skull: return images.createImage(`
2017-02-28 18:50:29 +01:00
. # # # .
# . # . #
# # # # #
. # # # .
2017-12-14 20:04:59 +01:00
. # # # .`);
case IconNames.Umbrella: return images.createImage(`
2017-02-28 18:50:29 +01:00
. # # # .
# # # # #
. . # . .
# . # . .
2017-12-14 20:04:59 +01:00
# # # . .`);
case IconNames.Snake: return images.createImage(`
2017-02-28 18:50:29 +01:00
# # . . .
# # . # #
. # . # .
. # # # .
2017-12-14 20:04:59 +01:00
. . . . .`);
// animals
case IconNames.Rabbit: return images.createImage(`
2017-02-28 18:50:29 +01:00
# . # . .
# . # . .
# # # # .
# # . # .
2017-12-14 20:04:59 +01:00
# # # # .`);
case IconNames.Cow: return images.createImage(`
2017-02-28 18:50:29 +01:00
# . . . #
# . . . #
# # # # #
. # # # .
2017-12-14 20:04:59 +01:00
. . # . .`);
// musical notes
case IconNames.QuarterNote: return images.createImage(`
2017-02-28 18:50:29 +01:00
. . # . .
. . # . .
. . # . .
# # # . .
2017-12-14 20:04:59 +01:00
# # # . .`);
case IconNames.EigthNote: return images.createImage(`
2017-02-28 18:50:29 +01:00
. . # . .
. . # # .
. . # . #
# # # . .
2017-12-14 20:04:59 +01:00
# # # . .`);
// other icons
case IconNames.Pitchfork: return images.createImage(`
2017-02-28 18:50:29 +01:00
# . # . #
# . # . #
# # # # #
. . # . .
2017-12-14 20:04:59 +01:00
. . # . .`);
case IconNames.Target: return images.createImage(`
2017-02-28 18:50:29 +01:00
. . # . .
. # # # .
# # . # #
. # # # .
2017-12-14 20:04:59 +01:00
. . # . .`);
default: return images.createImage(`
2017-02-28 18:50:29 +01:00
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
2017-12-14 20:04:59 +01:00
`);
2017-02-28 18:50:29 +01:00
}
}
//% weight=50 blockGap=8
2017-12-14 20:04:59 +01:00
//% help=images/arrow-number
2017-02-28 18:50:29 +01:00
//% blockId=device_arrow block="%arrow"
//% shim=TD_ID
export function arrowNumber(arrow: ArrowNames): number {
return arrow;
}
}