LOGO Pen Control and Color Control

Pen Control and Color Control

The terms Pen Control and Color Control relate to how to control the turtle’s pen width and turtle’s pen color. Color Control commands also let us fill the shapes with any color.

All shapes we have drawn so far use black, thin outlines. LOGO’s color control commands let us draw shape outlines with a specified color. The Color Control commands can fill the shapes with a color you specify. The Pen Control commands let us specify the thickness of the shape’s outline. This is analogous to using a thick broad brush or a thin pen when you draw a drawing on paper.

These features are referred to as Pen Control and Color Control.

How Does Turtle Draw on the Screen

The turtle has a pen under its belly. As it moves, it can draw a trace on the screen. On this page, we will learn commands to control the turtle’s pen. These commands can move the turtle’s pen up or down. If the turtle’s pen is up, the turtle does not draw on the screen as it moves across the screen. On the other hand, if the turtle’s pen is down, the turtle draws on the screen as it moves across the screen.

‘PENUP’ command is used when you want to move the turtle without tracing the line.

Pen Control Commands

We will use the following Pen Control commands in this section.

  • PENUP
  • PENDOWN
  • SETPENSIZE

Pen Up command

One pen control command is called PENUP (abbreviated PU). The ‘PENUP’ command is used when you want to move the turtle without tracing the line. The PENUP command makes the turtle move its pen up so it will not draw when you issue a ‘FORWARD’ or ‘BACK’ command.

Pen Down Command

Another Pen Control command is called ‘PENDOWN’ (abbreviated PD). The PENDOWN command makes the turtle put its pen down so it will draw when you issue a ‘FORWARD’ or ‘BACK’ command to move the turtle.

Pen Size Command

What if you want the turtle to draw thicker or thinner lines? The SETPENSIZE command controls the width of the pen so that you can control the width of the traces drawn by the turtle.

The pen width can be changed from 1 (thin lines) to 10 (thick lines).

Command Format: SETPENSIZE size
where size is the width of the pen trace.

Example: 
SETPENSIZE 1 ; draws a thin line
SETPENSIZE 2 ; draws a thicker line
SETPENSIZE 10; draws a very thick line

Draw Shapes With Thin And Thick Outlines Using PEN Control Commands

The program below illustrates the use of “SETPENSIZE”, “PENUP”, and “PENDOWN” commands. Below is the screenshot of the output of the program.

PROGRAM EXAMPLE: PEN CONTROL
PENDOWN ;Put turtle pen down so it can draw a trace
;on the computer screen
REPEAT 4[FORWARD 100 RIGHT 90] ; Draw a square
PENUP ;Make turtle’s pen up so it cannot draw a trace.
RIGHT 90
FORWARD 200 ; Move turtle’s away from the first 
;square.  It would not draw since the pen is up
LEFT 90
PENDOWN ;Put turtle’s pen down so it will draw when it moves.
SETPENSIZE 5 ; Set pen size to a medium thick line.
REPEAT 4[FORWARD 100 RIGHT 90] ;Draw a second 
;square with medium thick lines.
PENUP ;Make the pen up before you move the turtle
RIGHT 90
FORWARD 200
LEFT 90
PENDOWN ; After the move, set the pen down
SETPENSIZE 10 ;Set the pen size to very thick lines.
REPEAT 4 [FORWARD 100 RIGHT 90] ;Draw the third square

The following is the program output.

color control. Use Pen Control commad to draw squares with thin and thick outlines.
PEN CONTROL COMMAND TO FRAW SQUARES WITH THIN AND THICK LINES

Color Control

So far we have been drawing shapes with lines that are black.  Won’t it be fun if the turtle can draw shapes with color pen instead of black pen? LOGO provides commands that can do just that.

Now, we will teach the turtle how to draw shapes’ outlines in various colors. We will also make the turtle fill the shapes with a color of our choosing. The color index table will help us to select the fill color using the color index table.

Color Control Commands

This section covers the various commands that control the color of the lines drawn by the turtle. These commands also control the color of the screen background.

SETPENCOLOR Command (How to Draw in Colors)

The SETPENCOLOR command selects the turtle’s pen color and the color of the lines that the turtle draws.

The SETPENCOLOR command has the following instruction formats.

SETPENCOLOR color

where color is a number from the color index table below. color has a value from 0 to 15.

For example, SETPENCOLOR 3 command will set the pen color cyan.

Alternatively, you can use the following format for the SETPENCOLOR command. This format specifies the color in words.

SETPENCOLOR “Red.  This command will set the pen color to RED.

The Color Index Table below specifies the color selected by the turtle for the color index from 0 to 15.

For Color Index = 0, the turtle will draw black lines. With a value of ‘1’, the turtle will draw blue lines.  A Color Index of 2 draws green lines and so on.

Color Index Table

color control. Color Index Table shows the colors and their corresponding indexes.
Color Index Table

http://fmslogo.sourceforge.net/workshop/

Sometimes, you may like to change the background color of the screen. The SETSCREENCOLOR command enables this feature.

SETSCREENCOLOR Command (Select Screen Background Color)

SETSCREENCOLOR command sets the background color of the screen. This command fills the entire screen’s background with the specified color as per Color Index Table color codes.

SETSCREENCOLOR has the following instruction format.

SETSCREENCOLOR color

where color is the color index from the Color Index Table above. color is from 0 – 15.

You can also use the following abbreviated instruction format.

SETSC color

LOGO provides us with an alternate instruction format that lets us specify the color in English word, instead of specifying the color index, as in the example below.

SETSC “Red.  This command sets the screen background color to RED.

Let us now use the above commands to draw a square with a blue outline instead of black. We will also specify the screen background color (yellow in the program example below).


Draw Square with Color Outline

The below program will draw a square with blue outlines on a yellow screen.

PROGRAM EXAMPLE: DRAW A SQUARE WITH COLOE OUTLINES
SETSCREENCOLOR 6 ; Set screen background yellow. 
;From color index table, '6' corresponds to yellow color.
SETPENCOLOR 1 ; Set pen color blue.
REPEAT 4 [FORWARD 200 RIGHT 90]

Enrichment

1)    Try different color lines with different background screens.
a) With hexagon, pentagon, and triangle shapes.
b) With different “SETPENSIZE” values.

Draw Color Spiral

On the “Loops in LOGO” page, we drew a spiral with black lines. We will now use the commands of this section to draw a spiral with color lines. The following program will draw a spiral with red lines.

PROGRAM EXAMPLE: DRAW A COLOR SPIRAL
To SPIRAL
    REPEAT 100  [ FORWARD REPCOUNT * 2  RIGHT 91 ] ;Define SPIRAL
END
SETPENCOLOR 4    ; pen color is red

SPIRAL ; Call SPIRAL Procedure

The program’s output is shown below.

Color Control. Draw a red spiral using LOGO Color Control Commands.
SPIRAL USING LOGO COLOR CONTROL COMMAND

The following section explores how the turtle can fill the shapes with color.

Fill Shapes With Color (SETFLOODCOLOR and FILL Commands)

LOGO has two commands that lets the programmer fill the shapes with a specific color. The following are the commands to fill the shapes with colors.

  • SETFLOODCOLOR
  • FILL

SETFLOODCOLOR

SETFLOODCOLOR command selects the fill color that the turtle will use to fill the shape with. The color selection is done using the color index number from the Color Index Table

The following are the instruction formats.

SETFLOODCOLOR color

where color is color index from the Color Index Table above and has a value from 0 to 15.

The abbreviated format is:

SETFC color

Fill Command

The FILL command fills the inside of the shape with a color specified by the SETFLOODCOLOR color command.

Fill Shapes With Color Specified by SETFLOODCOLOR Command

The program below draws a square and fills it with orange color.

Note: The turtle fills the square only if the turtle is inside the square shape.  Before we give the FILL instruction, we need to move the turtle inside the shape by issuing the RIGHT 45   FORWARD 4 instruction. However, before we move the turtle inside the shape, we need to instruct the turtle to lift its pen up with the PENUP command, or else the turtle will draw a line as it moves inside the shape.

PROGRAM EXAMPLE: A SQUARE SHAPE FILLED WITH A SPECIFIED COLOR

The program example below draws a square with its inside filled with color.

TO COLORSQUARE
  REPEAT 4 [FORWARD 100 RIGHT 90] ;The turtle will draw a square shape.
  PENUP ; Move pen up so the turtle does not draw a line.
  RIGHT 45   FORWARD 4 ; This command moves the turtle four spaces inside the square shape.
  SETFLOODCOLOR 14    ; now we set the flood color to orange
  FILL  ; fill the square with orange
; The following instructions move the turtle out of the filled shape.
  BACK 4
  LEFT 45
  PENDOWN
END
COLORSQUARE ; Call "COLORSQUARE" procedure.

Below is the screenshot of the output of the above program.

Color Control. Draw a square and fill the square with the orange color.
COLOR CONTROL: FILL COMMAND AND SETFLOODCOLOR COMMAND

Pen Control and Color Control – Draw a Color Spiral With Color Fill And Thick Outlines

We now know how to make the turtle draw shapes with colored lines and fill the shapes with color. The next program uses all the commands we have learned so far in one program. The program below uses the following instructions:

  • SETPENCOLOR
  • SETPENSIZE
  • SETFLOODCOLOR
  • FILL
  • REPEAT

The program below draws a star shape with thick red outlines and fills the star shape with light blue (cyan) color.

PROGRAM EXAMPLE: STAR WITH THICK OUTLINE AND COLOR FILL
To BLUESTAR
SETPENCOLOR 4 ; set red color for lines
SETPENSIZE 10 ; set thick line width
RIGHT 18 FORWARD 150
REPEAT 5 [RIGHT 144 FORWARD 150 LEFT 72 FORWARD 150] ;Draw STAR shape.
PENUP ; Set pen up so the turtle does not draw a 
;line when we move the turtle inside the STAR shape.
LEFT 20
BACK 20
SETFLOODCOLOR 3 ;Set flood color to light blue (Cyan).
FILL ; Fill the star shape with light brown color.
END

BLUESTAR; Call procedure "BLUESTAR".

The following is the program’s output.

Color Control SETPENCOLOR, SETPENSIZE, SETFLOODCOLOR, and FILL commands.
STAR SHAPE USING SETPENCOLOR, SETPENSIZE, SETFLOODCOLOR, and FILL commands

Copyright © 2019 – 2024 softwareprogramming4kids.com

All Rights Reserved

Verified by MonsterInsights