Logo – Variables ”; Previous Next A variable is the name of a memory location which can contain a value. In a computer, each memory location has an integer address. Since it would be hard to remember the address of each location containing a value used by a program, computer scientists have found ways of giving these locations, symbolic names. Once a variable has a name, we can use and manipulate it. Variables are given names which are strings of letters. A variable name can contain alphabets (case insensitive), digits and underscore. A variable name can be accessed in a computation using ‘:’ before it. Let us consider the following example in the screenshot. In the above example, we have defined two variables first_name, 100_last_name_200 and initialized them with values Amal and Das using the following statements − make “first_name “Amal make “100_last_name_200 “Das Also, we printed these two variables with statements print :first_name and print :100_last_name_200. The following example shows how to define numeric variables − Here, we have defined two numeric variables val1 and val2. We have also performed addition and subtraction using them. Print Page Previous Next Advertisements ”;
Category: logo
Logo – Controlling the Turtle & Pen ”; Previous Next Logo has a number of other drawing commands, some of which are given below. pu − penup pd − pendown ht − hideturtle dt − showturtle setpensize The pendown and penup commands tell the turtle to leave ink on the screen as it moves or not to leave ink, respectively. The hideturtle and showturtle commands hide or show the turtle, but do not affect its ability to leave ink as it moves. The home command causes the turtle to return to the center of the screen. It may leave ink behind, when the turtle returns to the center of the screen. The setpensize command decides the drawing pen size. penup or pu means pick pen up, so you can move turtle without leaving tracks. pendown or pd means pick pen down, so you can move the turtle and leave tracks. hideturtle or ht means hide the turtle, so you can admire your drawing. showturtle or st means show the turtle, so you can continue your drawing. setpensize means it can make the pen larger, easier to see. Default pen size is –[1 1]. Following are few practice commands with the desired results on the right. Print Page Previous Next Advertisements ”;
Logo – Strings
Logo – Strings ”; Previous Next Any sequence of alpha-numeric characters, for example – “america”, “emp1234”, etc. are examples of a string. Counting the characters is the most basic of all string processes. The answer to the question stringlength “abc12ef is given by the following procedure − to stringlength :s make “inputstring :s make “count 0 while [not emptyp :s] [ make “count :count + 1 print first :s make “s butfirst :s ] print (sentence :inputstring “has :count “letters) end In the above procedure –‘s’ is the variable containing the input string. Variable inputstring contains the copy of the input string. Variable count is initialized with 0. In the while loop, the condition checks whether the string has become empty or not. In each loop count, a variable is being increased by 1 to hold the length count. The statement print first :s, prints the first character only of the string stored in ‘s’. The statement make “s butfirst :s, retrieves the sub-string excluding the first character. After exiting from the while-loop, we have printed the character count or the length of the input string. Following is the execution and output of the code. Print Page Previous Next Advertisements ”;
Logo – Home
Logo Tutorial PDF Version Quick Guide Resources Job Search Discussion Logo is a programming language that is easy to learn. It is used for teaching students and children how to program a computer. It was developed to process a list of words. A command is an instruction, which the computer can understand and execute. In principle, the computer only understands very basic commands, which can then be combined to form more complicated instructions. Such a sequence of commands is called a computer program. Writing computer programs is not easy. There are programs which has millions of commands. To keep track of such a complicated program, it is very important to approach the task of writing a program in a structured and well-thought-out manner. This is what we will learn in this Logo programming course. Audience This tutorial is designed for those readers, who seek to understand the basic concepts of writing programs in Logo programming language and how its different commands function. Prerequisites There are no prerequisites for this tutorial, except for a wish to learn how a computer program works. Having basic computer operating knowledge will be an added advantage in understanding this tutorial. Print Page Previous Next Advertisements ”;
Logo – Turtle World
Logo – Turtle World ”; Previous Next Logo has a number of other additional drawing commands, some of these are given below. home cleartext or ct label setxy The label command takes a single word as a quoted string (e.g. “a_string”) or a list of words in [ ] brackets without quotation (e.g. [a string of letters]) and prints them on the graphics window at the location of the turtle. Let us consider the following code. The setxy command takes two arguments, treats the first as the value of the abscissa (horizontal axis) and the second as a value of the ordinate (vertical axis). It places the turtle at these coordinates, possibly leaving ink while reaching these coordinates. In the following three figures, we have shown how the setxy command can be used. The cleartext command, abbreviated ct, clears the text region of the command window. Exercise Following is an exercise to check your aptitude on what you have learned so far in this chapter. What kind of figure does the following command sequence produce? cs pu setxy -60 60 pd home rt 45 fd 85 lt 135 fd 120 Interpret these commands as you read them from left to right. Try it to find out the result. Following is a table of command summary. Command Name Purpose setx 100 Sets the turtle”s x-coordinate to +100 Moves it 100 points to the right of center No vertical change setx -200 Moves the turtle 200 points to the left of center No vertical change sety 150 Sets the turtle”s y-coordinate to 150 Moves it 150 points above center No horizontal change sety – 50 Moves the turtle 50 points below center No horizontal change setxy 100 100 Moves the turtle to xy coordinate 100 100 show xcor show ycor Reports the turtle’s x-coordinate Reports the turtle’s y-coordinate setheading 0 seth 0 Points the turtle straight up, “high noon” seth 120 Moves the turtle 120 degree to point to the four o’clock position The following screenshot is a practical demonstration of some of the above commands. Print Page Previous Next Advertisements ”;
Logo – Recursive Procedures
Logo – Recursive Procedures ”; Previous Next In a recursive procedure, there will be a recurrence call of the procedure within the procedure. Let us consider the following code − to spiral_recur :n if :n < 1 [stop] fd :n rt 20 spiral_recur 0.95 * :n end The procedure spiral_recur has been called from the procedure body itself. The following screenshot shows the execution and output of the code. Print Page Previous Next Advertisements ”;
Logo – Turtle
Logo – Turtle ”; Previous Next The simple Logo Drawing Commands move the Turtle forward and backward and also turn it right or left. The commands and their abbreviations are given below − fd – forward bk – backward rt – right lt – left cs – clearscreen Either version of these commands can be used. Except the cs command, each of these commands must be followed by one value called as its argument. The arguments for fd and bk are units; those of rt and lt are angles that can be any integer. A rotation by 360 is a complete rotation, therefore a rotation by 375 degrees is the same as 1/15 degrees. forward 60 or fd 60 means go forward 60 steps right 90 or rt 90 means right turn 90 degrees left 90 or lt 90 means left turn 90 degrees back 60 or bk 60 means go back 60 steps clearscreen or cs means erase all drawings. This sets the turtle at the center The graphics window has a coordinate system. The values of the two coordinates (normally called x and y) at the center are 0, 0. At the northeast corner, they are 250, 250; at the southeast corner, they are 250, -250. At the southwest corner, they are -250, -250; etc. If the turtle tries to walk off onto one side of the screen, it wraps around. The right side wraps to the left side and the top wraps to the bottom. Many programming systems work on the same kind of two-axis ‘xy’ coordinate plane, which we work with in Algebra as well. Here, ‘0 0’ is the center, or origin (no comma or parentheses here!). In its centered, zoom-“normal” state, Logo”s drawing screen shows an area of about 150 points up or down and 300 points right or left from the center. The turtle can be directed with headings that correspond to a compass rose, with 0 or 360 degrees pointing straight up, 90 degrees straight to the right, and so on. You can set a variable to a number between 0 and 360 and then walk on that path. Turtle Commands Now let us try some commands. Commands will be issued one per line followed by a carriage return. Several of these commands can be typed in succession in a command window followed by a carriage return. The effect on the turtle is the same. However, if you type a command, which requires one or more inputs and provide the missing input(s) on the next line, Logo will show an error. Following is a practice command, which shows the desired results on the right. The commands – fd 50 rt 120 fd 50 rt 120 fd 50 rt 120, cause the turtle to draw a triangle, as you can see by trying them out. These commands are read from the left to the right. Since the command fd requires one argument, it is taken as the next value. Similarly, rt takes an argument as well. Thus, Logo can give an unambiguous meaning to each of these character strings. For some Logo commands, separators are needed. Following are few practice commands with the desired results on the right. Following is an exercise to check your aptitude on what you have learned so far in this chapter. Print Page Previous Next Advertisements ”;