Category: Turtle
Sets the width of the line in pixels that the turtle draws behind it as it moves.
When artists draw pictures they use many different pens that can draw different line thicknesses. You can also change the thickness of the lines that the turtle draws. The default pen width is one pixel and the pen is by default in the down (drawing) position.
// Draw a line 10 pixels wide and 100 pixels long penWidth(10); moveForward(100);
Example: Skyscraper Draws a skyscraper.
// Draw a skyscraper. penWidth(20); moveForward(); penWidth(15); moveForward(); penWidth(10); moveForward(); penWidth(5); moveForward(); penWidth(1); moveForward();
Example: Sample Line Thicknesses Draws horizontal lines with thickness 10 pixels to 90 pixels, counting by 10.
// Draws horizontal lines with thickness 10 pixels to 90 pixels, counting by 10. penUp(); moveTo(0, 0); turnRight(90); for (var i = 1; i < 10; i++) { penDown(); penWidth(i * 10); moveForward(250); moveBackward(250); penUp(); turnRight(90); moveForward(i * 10 + 10); turnLeft(90); } |
penWidth(width);
Name | Type | Required? | Description |
---|---|---|---|
width | number | Yes | The width of the line in pixels that the turtle draws behind it as it moves. |
No return value. Modifies turtle drawing 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