Color
A color value used by pen, effects, and the sensing blocks. Construct one
with the Color.rgb, Color.hsv, Color.hsl, or
Color.hex helpers.
The Color engine class. Most members are available as free functions; this page documents the underlying API for advanced use.
Color.a: numberThe alpha (opacity) of this color, 0–1.
Since 1.0.0
Color.b: numberThe blue component of this color, 0–255.
Since 1.0.0
Color.g: numberThe green component of this color, 0–255.
Since 1.0.0
Color.h: numberThe hue of this color, 0–100 (wraps around).
Since 1.0.0
Color.hex(hex: string, a?: number): ColorCreate a Color from a hex string (e.g. “#ff0000” or “#f00”).
Since 1.0.0
Example
setPenColor(Color.hex("#3498db"));hexToHSL
Section titled “hexToHSL”Color.hexToHSL(hex: string): { h: number; s: number; l: number }Convert a hex color string to an HSL object.
Since 1.0.0
hexToRGB
Section titled “hexToRGB”Color.hexToRGB(hex: string): { r: number; g: number; b: number }Convert a hex color string to RGB values (0-255).
Since 1.0.0
Color.hsl(h: number, s: number, l: number, a?: number): ColorCreate a Color from HSL values.
Since 1.0.0
hslToHex
Section titled “hslToHex”Color.hslToHex(h: number, s: number, l: number): stringConvert HSL values to a hex color string.
Since 1.0.0
hslToRGB
Section titled “hslToRGB”Color.hslToRGB(h: number, s: number, l: number): { r: number; g: number; b: number }Convert HSL values to RGB values (0-255).
Since 1.0.0
Color.hsv(h: number, s: number, v: number, a?: number): ColorCreate a Color from hue, saturation, and value (HSV) components.
Since 1.0.0
Color.num(n: number | string): ColorCreate a Color from a single packed Scratch-style number (0xAARRGGBB).
Since 1.0.0
Color.r: numberThe red component of this color, 0–255.
Since 1.0.0
Color.rgb(r: number, g: number, b: number, a?: number): ColorCreate a Color from red, green, and blue components (each 0–255).
Since 1.0.0
Example
setPenColor(Color.rgb(255, 0, 0)); // redrgbToHSL
Section titled “rgbToHSL”Color.rgbToHSL(r: number, g: number, b: number): { h: number; s: number; l: number }Convert RGB values (0-255) to an HSL object.
Since 1.0.0
rgbToHex
Section titled “rgbToHex”Color.rgbToHex(r: number | { r: number; g: number; b: number }, g?: number, b?: number): stringConvert RGB values (0-255) to a hex color string. Accepts either three separate values or a single {r, g, b} object.
Since 1.0.0
Color.s: numberThe saturation of this color, 0–100.
Since 1.0.0
Color.toHSL(): { h: number; s: number; l: number }Convert this color to an HSL object.
Since 1.0.0
toHSLString
Section titled “toHSLString”Color.toHSLString(forceIncludeAlpha?: boolean): stringConvert this color to an HSL CSS string.
Since 1.0.0
toHexString
Section titled “toHexString”Color.toHexString(forceIncludeAlpha?: boolean): stringConvert this color to a CSS hex string (e.g. “#ff0000”).
Since 1.0.0
Example
console.log(Color.rgb(255, 0, 0).toHexString()); // "#ff0000"toRGBA
Section titled “toRGBA”Color.toRGBA(): RGBAGet this color as an RGBA array with each component from 0 to 255.
Since 1.0.0
toRGBANormalized
Section titled “toRGBANormalized”Color.toRGBANormalized(): RGBANormalizedGet this color as an RGBA array with each component from 0 to 1.
Since 1.0.0
toRGBString
Section titled “toRGBString”Color.toRGBString(forceIncludeAlpha?: boolean): stringConvert this color to a CSS rgb()/rgba() string.
Since 1.0.0
toString
Section titled “toString”Color.toString(): stringConvert this color to a string (its rgb()/rgba() CSS form).
Since 1.0.0
Color.v: numberThe value (brightness) of this color, 0–100.
Since 1.0.0