Computers can represent colors in several ways, including RGB, HSL, and HSB/HSV.
HSB Colors
HSB/HSV colors are what Scratch uses for its Pen blocks and Paint Editor. These stand for "Hue, Saturation, and Brightness/Value". Hue is what Scratch calls "color": red, orange, yellow, green, blue, indigo, violet, and everything in between are hues. Hue is usually represented by a position on a color wheel. Note that while normal HSB/HSV color has a hue range of 0 - 360, Scratch use a hue range of 0 - 100. To convert real HSB/HSV hue to Scratch hue, divide by 3.6. Brightness is how bright a color appears. Saturation indicates how much a color is there; a saturation of 0% means black/grey/white while 100% means full color.
Mixing HSB Colors
In Scratch projects, it is often necessary to mix two colors, often if a gradient needs to be drawn or if it is needed for a paint program feature. There are two methods.
Direct Mixing
- See also: wikipedia:HSL and HSV#To RGB
Direct color mixing needs some math, but it allows direct mixing of pen colors. This is useful for drawing shapes. First, convert the color and shade to RGB. Then find the averages of the R, G, and B values and convert the result back to HSB.
Sprite Mixing
Colors can also be mixed with sprites. Create two sprites, both rectangles of the wanted colors to mix. Then place them on top of each other, and set the ghost effect of the top one to 50.
To dynamically alter the colors being mixed, change the color effect.
Color Picker
In some Scratch blocks, an input is a color picker with sliders: the first, labelled "Color", allows the user to select the hue; the second saturation; and the final one brightness.
RGB Colors
RGB colors are represented by the amount of red, green, and blue light in them. For example, rgb(0, 0, 0) is black (no light); rgb(255, 255, 255) is white (all light) and rgb(128, 0, 0) is dark red (some red light). RGB colors can be mixed by averaging the R, G, and B values.
The following code can be used to change the pen color using RGB in Scratch:
set pen color to ((((R) * (65536)) + ((G) * (256))) + (B))
A reporter may be dropped into any color input. These colors are represented by 24-bit values. (Binary notation uses two distinct digits, 0 and 1, which computers represent using electric current; a bit is a binary digit. A 24-bit value is something that can be stored in no more than 24 bits, so there are 224, or 16,777,216 possible values.) Each component is an integer (or whole number) from 0 to 255.
RGBA Colors
RGBA colors are like RGB colors, but also include opacity. An alpha of 0 is clear; an alpha of 1 is opaque. For example, rgba(255, 0, 0, 128) is a translucent red color. If painted over a blue pixel, the pixel will become purple rather than red.
The following code can be used to change the pen color using RGBA in Scratch:
set pen color to ((((A) * (16777216)) + ((R) * (65536))) + (((G) * (256)) + (B)))
Scratch represents colors as 32-bit ARGB values. Make sure the values A, R, G, and B are integers (rounded) so they do not contribute to other colors' values. Also, alpha must be positive, because otherwise Scratch will not realize it was given an ARGB value.
Hexadecimal Colors
RGB colors are often written in hexadecimal notation, which uses sixteen distinct digits (0-9, then A-F). The first two digits represent the amount of red from 0 (00) to 255 (FF). The second two digits represent the amount of green from 0 (00) to 255 (FF). The third two digits represent the amount of blue from 0 (00) to 255 (FF). For example, red is 100% red, 0% blue, and 0% green. So the hex value would be #FF0000 (FF, 00, 00), where FF is the largest possible 2-digit hex number (so the color contains the most red). This variety is also called 24-bit RGB because there are 24 bits in this notation, 4 for each hexadecimal digit.
There is also a more compact variant of the RGB space, stored as one-digit hexadecimal values, called 12-bit RGB. Each color takes up 1.5 bytes, half that of 24-bit RGB, but there are only 163 (4,096) possible colors. For example, in 12-bit RGB, red is #F00, representing 100% red (F), 0% green (0), and 0% blue (0). To convert 12-bit RGB to 24-bit RGB, duplicate all the red, green, and blue digits. For example, #F6A becomes #FF66AA.
The Block Plugin and BBCode use hexadecimal notation for colors, as do many computer programs.
The following code can be used to use hexadecimal format colors:
set pen color to (join [0x] (hex))
This also works with ARGB colors.
Named Colors
Some colors have special names that many computers will recognize. These names are stored as Strings of letters, and are often case-insensitive.
For example, there are colors named red, orange, green, blue, teal, purple, and black.
Invisible Forum Colors
The colors transparent
and white
appear invisible on the forums, so it is useful for obscuring answers.