pxt-calliope/libs/core/icons.ts

273 lines
11 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="arrow north"
//% jres=icons.arrownorth
ArrowNorth,
//% block="arrow north east"
//% jres=icons.arrownortheast
ArrowNorthEast,
//% block="arrow East"
//% jres=icons.arroweast
ArrowEast,
//% block="arrow south east"
//% jres=icons.arrowsoutheast
ArrowSouthEast,
//% block="arrow south"
//% jres=icons.arrowsouth
ArrowSouth,
//% block="arrow south west"
//% jres=icons.arrowsouthwest
ArrowSouthWest,
//% block="arrow west"
//% jres=icons.arrowwest
ArrowWest,
//% block="arrow north west"
//% jres=icons.arrownorthwest
ArrowNorthWest
2017-02-28 18:50:29 +01:00
}
namespace basic {
/**
* Draws the selected icon on the LED screen
* @param icon the predefined icon id
V4 updates for beta testing (#147) * change simulator svg * change radio image * Remove google fonts cdn * change color of 'advanced' button * font fix * font fix 2 * display fix * change fullsceen simulator bg * Continuous servo * handle continuous state * adding shims * update rendering for continuous servos * fixing sim * fix sig * typo * fix sim * bump pxt * bump pxt * rerun travis * Input blocks revision - add Button and Pin event types - merge onPinPressed & onPinReleased in new onPinEvent function - create new onButtonEvent function * update input blocks in docs and tests * remove device_pin_release block * Hide DAL.x behind Enum * bring back deprecated blocks, but hide them * shims and locales files * fix input.input. typing * remove buildpr * bump V3 * update simulator aspect ratio * add Loudness Block * revoke loudness block * Adds soundLevel To be replaced by pxt-common-packages when DAL is updated. * Remove P0 & P3 from AnalogPin * Fix Sound and replace AnalogPin.P0 * remove approved extensions * V4 Updates from remote Repo * locales * add storage functions * fix storage functions * fix int/float values * decrease decimal precision * reorder blocks * Update BLE Settings and Storage Blocks * Fetch MicroBit changes up to v4.0.18 * Update timing for LED Matrix usage * use 32kb ram (mini v2) * resize gatt table * Revert "use 32kb ram (mini v2)" This reverts commit 4b15592f0f0eacfc1a2e826f34682bc589faf16e. * fix missleading indentation * add support for 32kb and 16kb ram * only MIT extensions in preferredRepos * remove extensions without MIT License file * add updated extensions * add extensions with MIT license Co-authored-by: Juri <gitkraken@juriwolf.de> Co-authored-by: Juri <info@juriwolf.de>
2022-03-22 17:36:19 +01:00
* @param interval the amount of time (milliseconds) to block the LED Matrix for showing the icon. Default is 200.
2017-02-28 18:50:29 +01:00
*/
//% weight=90 blockGap=8
2017-12-14 20:04:59 +01:00
//% blockId=basic_show_icon
V4 updates for beta testing (#147) * change simulator svg * change radio image * Remove google fonts cdn * change color of 'advanced' button * font fix * font fix 2 * display fix * change fullsceen simulator bg * Continuous servo * handle continuous state * adding shims * update rendering for continuous servos * fixing sim * fix sig * typo * fix sim * bump pxt * bump pxt * rerun travis * Input blocks revision - add Button and Pin event types - merge onPinPressed & onPinReleased in new onPinEvent function - create new onButtonEvent function * update input blocks in docs and tests * remove device_pin_release block * Hide DAL.x behind Enum * bring back deprecated blocks, but hide them * shims and locales files * fix input.input. typing * remove buildpr * bump V3 * update simulator aspect ratio * add Loudness Block * revoke loudness block * Adds soundLevel To be replaced by pxt-common-packages when DAL is updated. * Remove P0 & P3 from AnalogPin * Fix Sound and replace AnalogPin.P0 * remove approved extensions * V4 Updates from remote Repo * locales * add storage functions * fix storage functions * fix int/float values * decrease decimal precision * reorder blocks * Update BLE Settings and Storage Blocks * Fetch MicroBit changes up to v4.0.18 * Update timing for LED Matrix usage * use 32kb ram (mini v2) * resize gatt table * Revert "use 32kb ram (mini v2)" This reverts commit 4b15592f0f0eacfc1a2e826f34682bc589faf16e. * fix missleading indentation * add support for 32kb and 16kb ram * only MIT extensions in preferredRepos * remove extensions without MIT License file * add updated extensions * add extensions with MIT license Co-authored-by: Juri <gitkraken@juriwolf.de> Co-authored-by: Juri <info@juriwolf.de>
2022-03-22 17:36:19 +01:00
//% block="show icon %i || for %interval ms" icon="\uf00a"
2017-02-28 18:50:29 +01:00
//% parts="ledmatrix"
//% help=basic/show-icon
//% icon.fieldEditor="imagedropdown"
//% icon.fieldOptions.columns="5"
//% icon.fieldOptions.width="380"
//% icon.fieldOptions.maxRows=4
V4 updates for beta testing (#147) * change simulator svg * change radio image * Remove google fonts cdn * change color of 'advanced' button * font fix * font fix 2 * display fix * change fullsceen simulator bg * Continuous servo * handle continuous state * adding shims * update rendering for continuous servos * fixing sim * fix sig * typo * fix sim * bump pxt * bump pxt * rerun travis * Input blocks revision - add Button and Pin event types - merge onPinPressed & onPinReleased in new onPinEvent function - create new onButtonEvent function * update input blocks in docs and tests * remove device_pin_release block * Hide DAL.x behind Enum * bring back deprecated blocks, but hide them * shims and locales files * fix input.input. typing * remove buildpr * bump V3 * update simulator aspect ratio * add Loudness Block * revoke loudness block * Adds soundLevel To be replaced by pxt-common-packages when DAL is updated. * Remove P0 & P3 from AnalogPin * Fix Sound and replace AnalogPin.P0 * remove approved extensions * V4 Updates from remote Repo * locales * add storage functions * fix storage functions * fix int/float values * decrease decimal precision * reorder blocks * Update BLE Settings and Storage Blocks * Fetch MicroBit changes up to v4.0.18 * Update timing for LED Matrix usage * use 32kb ram (mini v2) * resize gatt table * Revert "use 32kb ram (mini v2)" This reverts commit 4b15592f0f0eacfc1a2e826f34682bc589faf16e. * fix missleading indentation * add support for 32kb and 16kb ram * only MIT extensions in preferredRepos * remove extensions without MIT License file * add updated extensions * add extensions with MIT license Co-authored-by: Juri <gitkraken@juriwolf.de> Co-authored-by: Juri <info@juriwolf.de>
2022-03-22 17:36:19 +01:00
//% expandableArgumentMode="toggle"
//% interval.defl=200
//% group="LED matrix"
export function showIcon(icon: IconNames, interval = 200) {
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
}
}
namespace images {
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
# . . . #`);
// arrows
case IconNames.ArrowNorth: return images.createImage(`
. . # . .
. # # # .
# . # . #
. . # . .
. . # . .`);
case IconNames.ArrowNorthEast: return images.createImage(`
. . # # #
. . . # #
. . # . #
. # . . .
# . . . .`);
case IconNames.ArrowEast: return images.createImage(`
. . # . .
. . . # .
# # # # #
. . . # .
. . # . .`);
case IconNames.ArrowSouthEast: return images.createImage(`
# . . . .
. # . . .
. . # . #
. . . # #
. . # # #`);
case IconNames.ArrowSouth: return images.createImage(`
. . # . .
. . # . .
# . # . #
. # # # .
. . # . .`);
case IconNames.ArrowSouthWest: return images.createImage(`
. . . . #
. . . # .
# . # . .
# # . . .
# # # . .`);
case IconNames.ArrowWest: return images.createImage(`
. . # . .
. # . . .
# # # # #
. # . . .
. . # . .`);
case IconNames.ArrowNorthWest: return images.createImage(`
# # # . .
# # . . .
# . # . .
. . . # .
. . . . #`);
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
}
}
}