5.6 Artistic Turtles

In the Practice Exercises (see Section 5.4.6) you met the colors() function. Let’s have the Turtle put it to good use.

First of all, we might ask the Turtle to show us a sample of a given color:

Note the very thick lines specified above: turtle_lwd(50). Our turtle will draw a square with very thick sides that have the desired color. Let’s ask for burlywood. The resulting color-swatch is shown in Figure 5.14.

I'm drawing a burlywood square!

Figure 5.14: I’m drawing a burlywood square!

Feel free to ask for a random color. The result of the call below is shown in Figure 5.15.

I'm drawing a palegreen2 square!

Figure 5.15: I’m drawing a palegreen2 square!

The function below is the Turtle’s attempt to dash off a quick imitation of the work of Jackson Pollack, the great American abstract expressionist:

Note that the colors used are output to the console. Let’s have it make a picture with 50 strokes made by random-colored brushes. The resulting painting appears as Figure 5.16

Behold my masterpiece!

Figure 5.16: Behold my masterpiece!

## Behold my masterpiece!  It was painted with:
##  [1] "lightskyblue3"   "gray12"          "grey62"         
##  [4] "cyan"            "gray77"          "lightpink3"     
##  [7] "sandybrown"      "gray57"          "darkolivegreen2"
## [10] "snow3"           "grey43"          "sandybrown"     
## [13] "grey79"          "orangered1"      "blanchedalmond" 
## [16] "gray95"          "mediumpurple2"   "darkgoldenrod4" 
## [19] "purple"          "dodgerblue2"     "grey93"         
## [22] "violetred"       "steelblue2"      "grey71"         
## [25] "gold4"           "grey64"          "goldenrod2"     
## [28] "brown3"          "orangered2"      "gray"           
## [31] "gray52"          "darkgoldenrod3"  "grey70"         
## [34] "lightslategrey"  "aquamarine4"     "grey71"         
## [37] "grey5"           "darkslategray"   "gray19"         
## [40] "ivory1"          "deeppink"        "mediumorchid"   
## [43] "palevioletred1"  "wheat2"          "tan"            
## [46] "springgreen"     "thistle"         "chartreuse3"    
## [49] "grey9"           "royalblue4"