Color a robot
Paint a friendly robot with SVG. Try color names, hex codes, rounded corners, see-through colors and a smooth gradient, one small change at a time.
Ages 7 to 10, about 25 minutes. You will practice: How to color shapes with names and hex codes, How to round corners and add outlines, How see-through colors work with opacity, How to blend two colors with a gradient.
Goal: give a robot its own colors and a glowing chest.
The robot is built from simple shapes, like the ones in Draw with shapes. This project is all about color. Each example is live, so change the code and watch the robot change.
Step 1: Color names
You can color a shape with a word. Write it in the fill part, such as fill="steelblue". Browsers know about 140 color names, including tomato, gold, orchid and slategray.
Try this: change the body to seagreen, then the head to khaki. Which two colors do you like together?
Step 2: Hex codes
A color name is easy, but there are millions of colors and only a few names. A hex code lets you pick any of them. It starts with # and has six letters or digits, like #ff8800.
The six characters are three pairs. The pairs say how much red, green and blue light to mix. 00 means none and ff means the most. So #ff0000 is pure red, #00ff00 is pure green and #0000ff is pure blue.
Try this: change the body to #8e44ad for purple. Then try #e67e22 for orange. Nudge just one pair of characters and see how the color shifts.
Step 3: Rounded corners and outlines
Add rx="12" to a rectangle to round its corners. The bigger the number, the rounder the corner. Add a stroke and stroke-width for an outline. A dark outline can make a flat picture look neat and finished.
Try this: set the head to rx="30". It gets very round. What happens to the body if you do the same?
Step 4: See-through colors
fill-opacity says how solid a color is. 1 is fully solid. 0 is invisible. 0.35 lets the color behind show through. Here a soft yellow circle sits behind each eye, so the eyes seem to glow.
Try this: change both fill-opacity values to 0.7, then to 0.1. Notice that the order matters: the glow circles come before the eyes, so the eyes sit on top.
Step 5: A gradient chest panel
A gradient blends one color smoothly into another. You describe it once inside <defs>, which is a place for things you want to use later. Give it an id. Then use it with fill="url(#chest)". Each stop is a color, and offset says where along the blend it sits: 0 is the start and 1 is the end.
Try this: change the two stop-color values to #7fffd4 and #1e90ff for a sea-colored panel. Then change x2="0" y2="1" to x2="1" y2="0" so the blend runs from left to right.
To make the antenna light glow slowly, put this inside the antenna circle, before its closing tag. Keep the speed slow so it stays calm to look at.
<animate attributeName="fill-opacity" values="1;0.4;1" dur="4s" repeatCount="indefinite"/>
For teachers and families
Ask: “Which colors make the robot look friendly, and which make it look serious? Why?” As a classroom extension, have each child design a robot for a job, such as a garden helper or a space explorer, and explain their color choices. Keep a robot gallery, and let children guess each robot’s job from its colors. Read the hex codes aloud together to practice reading pairs of characters.
Next project: Make geometric patterns