Beruflich Dokumente
Kultur Dokumente
The Logo Workshop is designed to teach kids the basics of computer programming through a series of hands-on activities using a language called Logo. Logo is an interactive programming language that is simple, powerful, and a fun language. This language is used to draw figures, type text, and perform some mathematical calculations logo uses a pen for all these. This pen looks like a triangle and we call it as a turtle. Meet the logo turtle here How to start with the logo Click on start, select All Programs, Select Microsoft windows Logo, and select Microsoft windows Logo option.
After selecting the Microsoft Windows Logo below window will appear, in that we used to work.
Menu Bar
Turtl e
Main Screen
Commander Window
Command Box
Main Screen: It is the place where we can draw figures, type text, and perform some mathematical calculations Commander Window: It is the place where commands are typed and executed. It further divides into two such as commander box and Recall List.
Commander Box: It is the area where we can give commands to the turtle. And executes by pressing enter key or clicking on Execute button Recall List Box: This area will keep a history of commands which had given to the turtle. This is the area from where we can call the previously executed commands. Execute Button: After typing command in the commander box if you press this button the command gets executes. Trace Button: This button is used for finding errors in the commands. Halt Button: It stops the turtle from further processing. Reset button: It clears the Main Screen.
Commands
Commands are the instruction given to the turtle. The turtle follows the commands which are given by the user. In this section we will learn the following commands FORWARD BACKWARD RIGHT LEFT HOME CLEARSCREEN CLEARTEXT PRINT FD BK RT LT CS CT PR
FORWARD COMMAND
This command is used to ask the turtle to draw line in the forward direction. Syntax: FORWARD <number Of Steps to Forward> (OR) FD <number Of Steps to Forward>
There should be a space between FD and number of steps When you give the FD command the turtle will move in the tip direction of the triangle pointing. Dont give more than one space between the command and the number. After giving the command in the command input box, please press enter key to tell the turtle to follow that command.
If you give command as FD 100 the turtle will move 100 steps forward like this
BACKWARD
This command will move the turtle in the backward direction. The short form of BACKWARD is BK (bk). When it moves backward it head still points upwards. Syntax: BACKWARD < number of steps backward> (OR) Bk <number of steps backward) Example: bk 100
If you give command as BK 100 the turtle will move 100 steps Backward like this
We can make the turtle move backward even without giving BK command we can do this by giving negative number to FD. For example FD -50 will move the turtle backward to 50 steps
RIGHT COMMAND
This command will make the turtle head to turn right side with an angle in the clockwise direction. Short form of RIGHT is RT (rt). Syntax: RIGHT <Angle> RT <Angle> RIGHT 45 RT 45
Example:
If you give the above command the turtle will move like this. The term turn means to move the turtles head in a circular way. Circle contains a total of 360 Angle.
LEFT COMMAND
This command will make the turtle head to turn left side with an angle in the anticlockwise direction. Short form of LEFT is LT or lt. Syntax: RIGHT <Angle> RT <Angle> Example: RIGHT 45 RT 45 If you give the above command the turtle will move like this.
LT 60
LT 145
RT 90
RT 135
HOME COMMAND
Using HOME command we can bring back the turtle to the center of the screen with the head pointing to upward direction. You can bring it from anywhere from the screen. During this the turtle will draw as it moves to the center of the screen.
CLEARSCREEN COMMAND
This command is used to clear the screen and brings the turtle to the center of the screen its head pointing to the upward direction. Short form of clearscreen is CS or cs.
CLEARTEXT
This command is used to clear the History of commands from the Recall List Box. Short form of cleartext is CT or ct.
Syntax:
CLEARTEXT CT
PRINT COMMAND
It is used to print some information on to the Recall List Box. Short form of print is PR. Syntax: PRINT
information or [Information].
Whatever you give with the [] that information will be displayed in the recall list box.
By using some symbols we can perform some arithmetic operation in logo. Operator + * / Symbol Addition Subtraction Multiplication Division
Syntax PR 4*8
The above gives you the 32 as display in recall list box
FD 5*50
This command will move 250 steps forward.
OPERATOR COMMANDS
Here we learn about SUM, DIFFERNECE, PRODUCT, QUOTIENT and REMAINDER Functions.
SUM FUNCTION: sum function will two values PR sum 12 12
DIFFERENCE FUNCTION: Difference function will give the difference between two values PR difference 12 3
QUOTIENT FUNCTION: It divides two numbers and gives the quotient as the result PR quotient 20 5
EMAINDER FUNCTION: It divides two numbers and gives the remainder as the result PR Remainder 25 5
Syntax: PENPAINT fd 40 PE fd 40 This will set the pen and moves forward to 40 steps by drawing. HIDETURTLE We have seen that after execution of any command we are seeing the turtle, if you want to hide the turtle after execution using the command called HIDETURTLE. Short form is HT SYNTAX: HIDETURTLE HT SHOWTURTLE If you want to see the turtle once again use the command called SHOWTURTLE. Short form is ST SYNTAX: SHOWTURTLE ST
SETPENCOLOR
Even we can draw color shapes, type text with some color. For this we can use a command called as SETPENCOLOR Syntax: SETPENCOLOR [R G B] R: RED(255) G: GREEN (255) B: BLUE (255 SETPENCOLOR SETPENCOLOR SETPENCOLOR SETPENCOLOR [0 0 0] this will set the pen color to black. [255 0 0] this will set the pen color to Red. [0 255 0] this will set the pen color to Green. [0 0 255] this will set the pen color to Blue.
WAIT COMMAND Wait commands will make the turtle wait for some time and starts draws. Syntax: REPEAT 4 [fd 50 rt 90 wait 20] this will draw four lines each with 20 millisecond wait.
Even we can use nested repeats in the commands. repeat 4 [repeat 4 [fd 100 rt 90] rt 90] REPETITION If you want to repeat any command more than once you can use the repetition command. Syntax: Repeat <number of times> [commands] Example: repeat 4 [fd 100 rt 90]
It will draw four lines of distance 100 with 90 degrees so it forms a rectangle as below.
Note: We must use the keyword repeat followed by a number and then a sequence of commands in [square brackets].
WAIT COMMAND Wait commands will make the turtle wait for some time and starts draws. Syntax: REPEAT 4 [fd 50 rt 90 wait 20] this will draw four lines each with 20 millisecond wait.
Even we can use nested repeats in the commands. repeat 4 [repeat 4 [fd 100 rt 90] rt 90] repeat 4 [fd 100 rt 90 wait 20] The command will draw one line and waits for 20 milliseconds and turn to right by 90 degrees and draws second line and it repeats the process two more times and completes the square. REPCOUNT REPCOUNT is always equal to the number of times the loop has been run. It is 1 the first time the loop is run, 2 on the second, 3 on the third, and so on.
DRAWING SQUIRAL
Drawing S Shape
REPEAT 750 [ RIGHT 90 REPEAT 4 [ FORWARD REPCOUNT * 3 RIGHT 72 ] RIGHT REPCOUNT ]
Drawing Triangle
Drawing Square
Drawing Polygon
SUBPROGRAMS
A subprogram is a named sequence of steps for another program to execute. Other names for subprograms are procedures and functions.
A subprogram or function Syntax Starts with to followed by subprogram name and ends with end Example To draw a square we can write a subprogram as To square Repeat 4 [fd 100 rt 90] End
How to call a subprogram Click on Edall button from commander window. You will get editor there you have to write the subprogram
Click on save and exit to return to the commander window. From commander window you can call to that subprogram as below
Here flower is a subprogram; it is calling other subprogram called square. If you give the command called flower in the commander window the following will be the output.
Click on file and select Save and exit, it will return you to commander window, enter boxpicture and press enter you can see the below output.
VARIABLES
We use the same procedure on different values, or variables. We don't want every square to be the same size we want variety. In Logo, we create variables whose values we can change. We'll use the same square procedure with a small change:
We give Logo a replacement value for :n on the command line. It means in the commander window just give one after other as below
COLORS
So far, all of our programs draw the black and white pictures. In this lesson, we are going to add colors to our pictures. Logo gives you two ways to pick a color. One way is to pick a color from a set of 16 commonly used colors. Another way is to create your own color by mixing different amounts of red, green, and blue. This gives you a choice of over 16 million different colors.
Color Index
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Color Name
Black Blue Green Cyan (light Blue) Red Magenta Yellow White Brown Light brown Dark green Darkish blue Tan Plum Orange Gray
[R
B]
[0 0 0] [0 0 255] [0 255 0] [0 255 255] [255 0 0] [255 0 255] [255 255 0] [255 255 255] [155 96 59] [197 136 18] [100 162 64] [120 187 187] [255 149 119] [144 113 208] [255 163 0] [183 183 183]
If you try to give the setscreencolor 16 it will set the screen color to black. If it is 17 it set the screen color to blue if it is 18 sets the screen color to green and so on means from 16 it will repeat the color from 0 to 15.
Try the above code and execute that by calling a command called squareflower in commander window.
Here first screen color is set to black, and then sets the pen color, first REPCOUNT is 1 means pen color is black as the repeat increase the pen color keeps on changes and makes the turtle move forward to six times REPCOUNT. It draws the below figure with different colors.
FLAGS
So far, all of our drawings have had two limitations. First, they are entirely made up of lines (no solid shapes). Second, all of the lines are connected. In this lesson, we will overcome these limitations. We will learn how to move the turtle without drawing a line. We will also learn how to fill in the outline of a shape with a solid color. Then we will draw some flags of various countries.
Syntax:
PENUP PENDOWN
Check the below command
REPEAT 10 [ PENUP FORWARD 5 PENDOWN FORWARD 5 ]
Filling Solid Shapes After drawing a shape we can make the turtle go inside the shape and fill with single color using a command called FILL.
In order to fill a shape first we need to set the flood color by using below syntax: Setfloodcolor 3 means cyan color Then use the command called Fill to fill any shape with blue color
repeat 2 [fd 100 rt 90 fd 50 rt 90] rt 90 pu fd 50 lt 90 pd repeat 2 [fd 100 rt 90 fd 50 rt 90] rt 90 pu fd 50 rt 90 pd rt 180 repeat 2 [fd 100 rt 90 fd 50 rt 90] lt 90 fd 100 rt 45 pu fd 4 pd setfloodcolor 14 fill bk 4 lt 45 rt 90 fd 100 pu rt 45 fd 4 setfloodcolor 3 fill The above code will give the Tri color flag of our nation.