7.0 Color System and Flood Fill
7.0 Color System and Flood Fill
Logo includes a comprehensive color system based on the standard RGB model. Color is a distinct property that can be applied programmatically to the pen, the screen background, and fill operations, enabling the creation of visually rich and dynamic graphics. Understanding how to define and apply colors is essential for moving beyond simple line drawings to produce complete and polished graphical output. This manual concludes by covering Logo’s color commands and a practical workflow for filling enclosed shapes, reinforcing the key concepts required to develop sophisticated visual programs.
7.1 The RGB Color Model
Colors in Logo are defined using a Red, Green, and Blue (RGB) model, where any color is a mixture of these three primary components.
- Numeric Representation: A color is represented as a list of three numbers [r g b], where r, g, and b are integer values ranging from 0 to 255. This range is significant because 255 corresponds to 2^8 – 1, representing the 256 possible values for an 8-bit channel. The combination of three 8-bit channels for R, G, and B results in a 24-bit color system capable of representing millions of distinct colors.
- Example Values:
- Black (absence of color): [0 0 0]
- Red: [255 0 0]
- White (all colors combined): [255 255 255]
7.2 Color Command Reference
The following commands are used to set and query colors for different elements of the graphics environment.
| Command | Abbreviation | Purpose |
| setpencolor [r g b] | setpc [r g b] | Sets the color of the turtle’s pen. |
| setfloodcolor [r g b] | setfc [r g b] | Sets the color used by the fill command. |
| setscreencolor [r g b] | setsc [r g b] | Sets the background color of the drawing canvas. |
| show pencolor | Reports the current pen color RGB value. | |
| show floodcolor | Reports the current flood color RGB value. | |
| show screencolor | Reports the current screen color RGB value. | |
| fill | Fills a closed area with the current flood color. |
7.3 Applying Color: An Example Workflow
To draw a shape, set various colors, and fill the shape, a complete sequence of commands can be executed. The following runnable example demonstrates a full workflow, resulting in a red square filled with blue on a green background.
cs
home
setpensize [5 5]
setpencolor [255 0 0]
setfloodcolor [0 0 255]
setscreencolor [0 255 0]
repeat 4 [fd 40 rt 90]
pu
setxy 20 20
fill
ht