INTRODUCTION |
The turtle draws its trail using a colored pen, for which it knows some additional instructions. As long as the pen is down, the turtle draws a trail. Using the statement penUp(), it moves its pen up and stops drawing. With penDown(), the pen is brought back down to the drawing area, so that a trail is drawn again. Using setPenColor(color) you can select the color of the pen. It is important that you put the name of the color inside quotation marks. As always in programming, the turtle knows only English color names. The following list is not complete, but here are some examples: yellow, gold, orange, red, maroon, violet, magenta, purple, navy, blue, skyblue, cyan, turquoise, lightgreen, green, darkgreen, chocolate, brown, black, gray, white. |
COLOR AND PEN WIDTH |
from gturtle import * makeTurtle() setLineWidth(60) setPenColor("red") forward(100) penUp() forward(50) penDown() setPenColor("yellow") dot(40) setLineWidth(5) setPenColor("black") back(15) hideTurtle()
|
MEMO |
The drawing pen of the turtle can change color with use of the statement setPenColor(color). With penUp() the turtle stops drawing, and with penDown() it continues to draw again. You can control the width of the line using setLineWidth(width). The turtle knows the so-called X11 colors. There are a few dozen names of colors which you can find on the Internet http://cng.seas.rochester.edu/CNG/docs/x11color.html . You can select all of these colors with the setPenColor(color) statement. |
FILLED AREAS |
from gturtle import * makeTurtle() setPenColor("sandybrown") setFillColor("sandybrown") startPath() forward(100) right(45) forward(72) right(90) forward(72) right(45) forward(100) fillPath() hideTurtle()
|
MEMO |
If you want to fill an area defined by a sequence of lines, you begin drawing with the command startPath(). Using fillPath(), the start point and the end point are connected and the enclosed area is filled. You can write comments by starting a code line with the # symbol. |
EXERCISES |
|