Category: Canvas
Sets the fill color for the active canvas.
The fill color controls, for the active canvas, the interior color of shapes drawn with rect and circle. The outline color of circles and rectangles is set using setStrokeColor.
The color parameter must be a string enclosed in quotes, and can take one of four forms. It can be:
The default fill color is transparent.
// Draw a black bordered circle filled with yellow. createCanvas("canvas1"); setFillColor("yellow"); circle(160, 240, 100);
Example: Worried! Draw a worried emoticon face using filled shapes.
// Draw a worried emoticon face using filled shapes. createCanvas("canvas1"); setFillColor("yellow"); circle(160, 240, 100); setFillColor("black"); circle(125, 215, 20); circle(195, 215, 20); setFillColor("white"); rect(100, 260, 120, 20);
Example: 4 Ways Demonstrate all 4 ways to specify the color parameter.
// Demonstrate all four ways to specify the color parameter. createCanvas("canvas1"); // Sets the color using the name of a color in a string. setFillColor("chartreuse"); circle(50, 50, 40); // Sets the color using the hex value of a color in a string. setFillColor("#7fff00"); circle(100, 50, 40); // Sets the color using the rgb value of a color in a string. setFillColor("rgb(127, 255, 0)"); circle(50, 100, 40); // Sets the color using a rgba value of a color in a string. // The last value is the amount of transparency, a percentage between 0.0 and 1.0 setFillColor("rgba(127, 255, 0, 0.5)"); circle(100, 100, 40);
setFillColor(color)
Name | Type | Required? | Description |
---|---|---|---|
color | String | Yes | The color of the pen used to fill circles and rectangles. |
No return value. Outputs to the display only.
Found a bug in the documentation? Let us know at documentation@code.org
Found a bug in the documentation? Let us know at documentation@code.org