pxt-calliope/libs/core/basic.ts

59 lines
1.7 KiB
TypeScript
Raw Normal View History

2016-09-27 22:35:48 +02:00
/**
Well known colors
*/
enum Colors {
//% blockIdentity=basic.color
//% block=red
2016-10-11 20:41:51 +02:00
Red = 0x00FF0000,
2016-09-27 22:35:48 +02:00
//% blockIdentity=basic.color
//% block=orange
2016-10-11 20:41:51 +02:00
Orange = 0x00FFA500,
2016-09-27 22:35:48 +02:00
//% blockIdentity=basic.color
//% block=yellow
2016-10-11 20:41:51 +02:00
Yellow = 0x00FFFF00,
2016-09-27 22:35:48 +02:00
//% blockIdentity=basic.color
//% block=green
2016-10-11 20:41:51 +02:00
Green = 0x0000FF00,
2016-09-27 22:35:48 +02:00
//% blockIdentity=basic.color
//% block=blue
2016-10-11 20:41:51 +02:00
Blue = 0x000000FF,
2016-09-27 22:35:48 +02:00
//% blockIdentity=basic.color
//% block=indigo
2016-10-11 20:41:51 +02:00
Indigo = 0x004b0082,
2016-09-27 22:35:48 +02:00
//% blockIdentity=basic.color
//% block=violet
2016-10-11 20:41:51 +02:00
Violet = 0x008a2be2,
2016-09-27 22:35:48 +02:00
//% blockIdentity=basic.color
//% block=purple
2016-10-11 20:41:51 +02:00
Purple = 0x00FF00FF,
2016-09-27 22:35:48 +02:00
//% blockIdentity=basic.color
//% block=white
2016-10-11 20:41:51 +02:00
White = 0xFF00000
2016-09-27 22:35:48 +02:00
}
/**
* Provides access to basic micro:bit functionality.
*/
//% color=#0078D7 weight=100
namespace basic {
/**
* Converts the color name to a number
*/
//% blockId=color_id block="%c" shim=TD_ID
export function color(c: Colors): number {
return c;
}
2016-10-11 20:41:51 +02:00
/**
* Converts red, green, blue channels into a RGB color
* @param red value of the red channel between 0 and 255. eg: 255
* @param green value of the green channel between 0 and 255. eg: 255
* @param blue value of the blue channel between 0 and 255. eg: 255
* @param white value of the white channel between 0 and 255. eg: 0
*/
//% weight=1
//% blockId="core_rgb" block="red %red|green %green|blue %blue|white %white"
export function rgbw(red: number, green: number, blue: number, white:number): number {
return ((white & 0xFF) << 24) | ((red & 0xFF) << 16) | ((green & 0xFF) << 8) | (blue & 0xFF);
}
2016-09-27 22:35:48 +02:00
}