Download presentation
Presentation is loading. Please wait.
Published byClement Spencer Modified over 9 years ago
1
Computer Science 1000 LOGO I
2
LOGO a computer programming language, typically used for education an old language (1967) the basics are simple: move a “turtle” around the screen the turtle can leave a “trail” using its pen even though it’s basic, very effective at teaching elementary programming concepts input/output, variables, loops, conditionals we will be using MSWLogo (free download, installed in labs)
3
Output Window Commander Window Turtle
4
LOGO Commands like other programming languages (e.g. Scratch), LOGO programming is made up of statements termed as commands basic syntax: e.g. … forward 10
5
LOGO – Interactive one of the easiest ways to use LOGO is to use the commander window type a command press Enter or press Execute two responses the command will be shown in the history the turtle will respond
6
Logo – Basic Movement forward moves the turtle forward indicates how many steps to move back moves the turtle backward indicates how many steps to move the direction of movement depends on which way the turtle is facing
9
Logo – Basic Movement many LOGO commands have a shorthand forward : fd back : bk these shorthand values are particularly useful when these commands are part of other commands
12
Movement note that both forward (fd) and back (bk) can take a negative value as input if fd, then moves backward if bk, then moves forward
15
Turning left turns the turtle counterclockwise by specified number of degrees shorthand: lt right turns the turtle clockwise by specified number of degrees shorthand: rt
17
Movement the direction that the turtle is facing affects the result of the forward and back commands simply stated, the turtle always moves in the direction it is pointing
19
Reset to reset the direction of the turtle, press the Reset button you can also use the cs command (short for clear screen)
20
Reset Pressed
22
Multiple Operations like Scratch, the power of LOGO programming is in combining multiple commands a simple way to do this: place multiple commands on the same line, separated by spaces
24
Example: draw a square with side length 100 Solution: forward 100 steps turn 90 degrees right forward 100 steps turn 90 degrees right forward 100 steps turn 90 degrees right forward 100 steps turn 90 degrees right
26
Loops LOGO offers similar looping functionality to Scratch the simplest loop: repeat syntax: repeat [ … ] These commands will be repeated this many times.
27
Example: Modify previous example: draw a square with only one fd and one rt command
29
Example: Modify the previous example to draw an octagon, sides of length 60 Solution: fd 60 steps turn 45 degrees Repeat 8 times
31
Pen Status all of the turtle movements thus far have resulted in a line being drawn behind the ability to draw is known as the turtle’s pen by default, it’s pen is down and a line is drawn we can lift the pen using the command pu (short for pen up)
32
Notice that no line is drawn behind turtle.
33
Pen Status we can drop the pen, and start drawing again, using the pd command (short for pen down) example: write a program that draws a dashed line, with each dash of length 10
35
Print LOGO allows us to print a value useful for debugging to print a number print to print text print “
37
Math LOGO allows us to do basic math, similar to both Excel and Scratch operators + : addition - : subtraction * : multiplication / : division
39
Math math expressions are typically used in other LOGO commands
41
Variables recall that a variable refers to named memory storage LOGO allows the use of variables built-in (like the Scratch answer block) user-defined we use a variable simply by writing its name
42
repcount a built-in variable used inside a repeat loop stores a number that number changes each time through the loop first time through the loop: 1 second time through the loop: 2 and so on ….
45
repcount can be used as input to other commands example: rewrite our dashed line example, but make each dash successfully larger than the next first dash: 10 units second dash: 20 units third dash: 30 units and so on …
47
Procedures a procedure allows us to define our own commands syntax: to end
48
Example: write a procedure called square that draws a square of side size 50 to square repeat 4 [ fd 50 rt 90 ] end
49
Procedures where do we define a procedure? Click the Edall button an editor window will pop up, for program entry your lab experience suggests an alternative method, if you prefer EdAll Button
50
From previous example: When you are finished editing, click File -> Save and Exit
51
Procedures once you have defined and saved a procedure, you can call it just as you would any other command
53
Procedures procedures can have more than one command for example, write a procedure that draws an X Solution: turn 45 degrees to the right forward 100 steps backward 200 steps forward 100 steps turn 90 degrees to the right forward 100 steps backward 200 steps forward 100 steps
56
Procedures just like other commands can be called in procedures, other procedures can also be called for example, write a procedure called squareX, that draws both an X, and a square
59
Input just like commands, procedures can take parameters also called inputs syntax: to procedure :param1 :param2... commands end
60
Input when we call a procedure with parameters, we must supply a value for those parameters when we call a procedure the parameters can then be used as a variable don’t forget the colon to printTwice :val print :val end
62
Example: write a procedure called dashedLine, that takes a number X as input, and draws X dashes
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.