Computers can represent colors in several ways, including RGB and HSL/HSB/HSV.
HSL, HSB, and HSV colors are what Scratch uses for its Pen blocks. These stand for "Hue, Saturation, and Lightness/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. Brightness is how bright a color appears. Saturation indicates how colorful a color is; a saturation of 0% means gray while 100% means as colorful as possible.
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.
- 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.
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.
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(1, 1, 1) is white (all light) and rgb(0.5, 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 are like RGB colors, but also include opacity. An alpha of 0 is clear; an alpha of 1 is opaque. For example, rgba(1, 0, 0, 0.5) 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.
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 following code can be used to use hexadecimal format colors:
set pen color to (join [0x] (hex))
This also works with ARGB colors.
Invisible Forum Colors
transparent appears invisible on the forums, so it is useful for obscuring answers.