5. Module 4: Enhancing Visual Creations
- Module 4: Enhancing Visual Creations
Once students have a firm grasp of programming logic, they can begin to infuse their creations with color, creativity, and an element of unpredictability. This module introduces the tools for controlling color and generating random numbers, empowering students to move beyond simple line drawings and foster their artistic expression through code.
5.1. Working with Color
Computer screens generate colors using the RGB model, where every color is a specific mixture of Red, Green, and Blue light. In Logo, the intensity of each component is represented by a number from 0 (no light) to 255 (full intensity). For example, [255 0 0] is pure red, [0 255 0] is pure green, and [0 0 0] is black.
Educator’s Note: The RGB model is a great topic for a hands-on classroom activity. Ask students to predict the RGB values for colors like yellow (red + green = [255 255 0]), purple (red + blue = [255 0 255]), or cyan (green + blue = [0 255 255]). Then, have them test their predictions using the setpencolor command to see the results.
The following commands allow for precise control over the colors used in a project.
| Command | Purpose |
| setpencolor [r g b] (setpc) | Sets the color of the line drawn by the turtle’s pen. |
| setfloodcolor [r g b] (setfc) | Sets the color that will be used by the fill command. |
| setscreencolor [r g b] (setsc) | Sets the background color of the drawing window. |
| fill | Fills an enclosed shape with the current floodcolor, starting from the turtle’s position. |
The following block of code demonstrates how to create a red square, fill it with blue, and set the background to green.
cs ; Clear the screen
setscreencolor [0 255 0] ; Set background to green
setpencolor [255 0 0] ; Set pen to red
setfloodcolor [0 0 255] ; Set fill color to blue
repeat 4 [fd 40 rt 90] ; Draw the square
pu ; Lift the pen to move without drawing
setxy 20 20 ; Move the turtle inside the square
fill ; Fill the shape with the blue floodcolor
ht ; Hide the turtle for a clean final image
5.2. Introducing Randomization
The random command introduces an element of unpredictability, allowing students to create programs that produce different results each time they are run. The command takes a single integer as an argument and generates a random integer between 0 and one less than that argument. For example, random 360 will produce a value from 0 to 359.
To see it in action, you can use the print command: print random 360
The output will be a different number within the specified range each time the command is executed.
From a pedagogical perspective, the random command is an excellent tool for exploration. Challenge students to use it with movement commands (e.g., rt random 360 and fd random 50) inside a repeat loop. This allows them to create their own, simpler version of the “random walk” algorithm from the previous module, reinforcing the fun and exploratory nature of programming with Logo.
These tools for color and randomization unlock a new level of creative potential for students’ projects.