- By
**qiana** - Follow User

- 147 Views
- Uploaded on

Download Presentation
## PowerPoint Slideshow about ' Logo Lesson 3' - qiana

**An Image/Link below is provided (as is) to download presentation**
Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

Presentation Transcript

Prerequisites for Lesson 3

- Before beginning this lesson, the student must be able to…
- Use simple Logo commands to make a shape.
- Create and edit a procedure.
- Use the following commands appropriately
- POTS
- SAVE
- LOAD

Objectives for Lesson 3

- After completing this lesson, the student will be able to…
- Move the turtle to any screen position.
- Determine the turtle’s screen position.
- Explain the term variable.
- Create procedures with variable input, using MAKE and RANDOM.

Logo Screen Positions

- The position of the Logo turtle on the screen is described by two numbers - a horizontal and a vertical coordinate.
- The center of the screen is the turtle’s home. Its designation is [0 0], and all other coordinates are measured from there.
- It is very much like graphing in algebra.

Logo Screen Positions

- The first of the two numbers describes the horizontal distance in turtle steps right or left of the center.
- For example, in the position [10 15], the 10 represents 10 turtle steps to the right of the center.
- In the position [-25 10], the -25 represents 25 turtle steps to the left of the center.

Logo Screen Positions

- The second of the two numbers describes the vertical distance in turtle steps above or below the center.
- For example, in the position [10 15], the 15 represents 15 turtle steps above the center.
- In the position [25 -10], the -10 represents 10 turtle steps below the center.

Guess the Positions

- Possible screen positions (depending on Logo version)

[-100 50]

2

1

[ 150 75]

4

[ 25 -25]

3

[0 -50]

Position Commands

- PR POS is the command used to print (in the command window) the current position of the turtle.
- SETPOS [numbernumber] or SETXY (numbernumber) sets the position of the turtle.
- SETX number changes only the first number
- SETY number changes only the second number
- HOME returns the turtle to [ 0 0 ]

Challenge

- What shape do you think would result from these commands (assume turtle starts at [0 0])? Click to see the answer.
- SETPOS [ 0 25 ]
- SETPOS [ 25 25 ]
- SETPOS [ 25 0 ]
- SETPOS [ 0 0 ] or HOME

Logo Variables

- A variable is a letter or word that represents a number that can vary (thus the term variable).
- In Logo, variables often have a colon in front of the letter or word.
- Sample Logo variables -
- :L2 :WIDTH :NAME :X

Logo Variables

- Variables must be assigned a value.
- The Logo command MAKE is often used to “fill up” a variable.
- For example, the command below puts the number 17 into the variable called :NUM (notice the quote and lack of colon)
MAKE “NUM 17

Logo Variables

- See if you can determine the final value of :Z after the commands below. (NOTE: * means multiply, / means divide)
- MAKE “Z 25
- MAKE “Z :Z * 2
- MAKE “Z :Z + 10
- MAKE “Z :Z / 2

Logo Variables

- :Z becomes 30 after several calculations.
- MAKE “Z 25 (:Z starts at 25)
- MAKE “Z :Z * 2 (:Z is multiplied by 2, :Z = 50)
- MAKE “Z :Z + 10 (10 is added to :Z, :Z = 60)
- MAKE “Z :Z / 2 (:Z is divided by 2, :Z = 30)

Logo Variables

- After you define the value of a variable, you can use it in Logo commands in place of any number.
- Examples:
- FD :X
- RT :D2
- REPEAT 4 [ FD :SIZE RT 90 ]

RANDOM

- Logo variables can also be filled with random numbers.
- The RANDOM command returns a number from 0 to a set limit.
- Example: RANDOM 10 returns a number between 0 and 9.
- Example: 1 + RANDOM 100 returns a number between 1 and 100.

RANDOM

- Examples of MAKE with RANDOM
- MAKE “Z RANDOM 15
- :Z becomes a number between 0 and 14

- MAKE “H23 1 + RANDOM 10
- :H23 becomes a number between 1 and 10

- MAKE “LENGTH 10 + RANDOM 50
- :LENGTH becomes a number between 10 and 59 (10 + 0 to 10 + 49)

Samples of Procedures with Variables (MAKE/RANDOM)

- A variable size SQUARE
- TO SQUARE
- MAKE “SIZE 10 + RANDOM 100
- REPEAT 4 [FD :SIZE RT 90]
- END

Samples of Procedures with Variables (MAKE/RANDOM)

- A variable size TRIANGLE
- TO TRIANGLE
- MAKE “SIZE 25 + RANDOM 50
- REPEAT 3 [FD :SIZE RT 120]
- END

Samples of Procedures with Variables (MAKE/RANDOM)

- A variable size RECTANGLE
- TO RECTANGLE
- MAKE “S1 25 + RANDOM 50
- MAKE “S2 25 + RANDOM 100
- REPEAT 2 [FD :S1 RT 90 FD :S2 RT 90]
- END

Another Way to Fill a Variable

- You can also fill up a variable by defining it when you “run” a procedure.
- Look at this procedure:
- TO SQUARE :S
- REPEAT 4 [FD :S RT 90]
- END

- Somehow, the :S needs a value.

Another Way to Fill a Variable

- To start this procedure…
- TO SQUARE :S
- REPEAT 4 [FD :S RT 90]
- END

- …you would type SQUARE 50 or SQUARE 100 or SQUARE 87
- The number you type after the procedure name fills the variable.

Another Way to Fill a Variable

- Another example:
- TO TRIANGLE :F
- REPEAT 3 [FD :F RT 120]
- END

- To draw a triangle with sides of 50, type TRIANGLE 50 to start the procedure.

Another Way to Fill a Variable

- Consider this example:
- TO RECTANGLE :L :W
- REPEAT 2 [FD :L RT 90 FD :W RT 90]
- END

- You would need two numbers after the name of the procedure (the first becomes :L and the second becomes :W):
- RECTANGLE 50 100
- RECTANGLE 40 40

Self Check Lesson 3

- In the screen below, what is the best estimate of the turtle’s position?
- [-50 50]
- [50 -50]
- [50 50]
- [-50 -50]

Self Check Lesson 3

- In the screen below, what is the best estimate of the turtle’s position?
- [-50 50]
- [50 -50]
- [50 50]
- [-50 -50]

50

-50

Self Check Lesson 3

- Which of the following could not be the name of a Logo variable?
- :Z
- :The Size
- :SIZE
- :B123

Self Check Lesson 3

- Which of the following could not be the name of a Logo variable?
- :Z
- :The Size {no spaces allowed}
- :SIZE
- :B123

Self Check Lesson 3

- What will be the value of :BIG after the Logo commands below?
- MAKE “BIG 5
- MAKE “BIG :BIG + 25
- MAKE “BIG :BIG - 7

Self Check Lesson 3

- What will be the value of :BIG after the Logo commands below?
- MAKE “BIG 5 {:BIG=5}
- MAKE “BIG :BIG + 25 {:BIG=30}
- MAKE “BIG :BIG - 7 {:BIG=23}

Self Check Lesson 3

- Suppose you want a randomly chosen number between 1 and 10. Which of the following would generate that number?
- RANDOM 10
- RANDOM 1 + 10
- RANDOM 10 + 1

Self Check Lesson 3

- Suppose you want a randomly chosen number between 1 and 10. Which of the following would generate that number?
- RANDOM 10 {0 TO 9}
- RANDOM 1 + 10 {10.0 TO 10.999}
- RANDOM 10 + 1

Self Check Lesson 3

- Suppose you have entered the procedure below. What would you type to use it to draw a SQUARE with sides of 50?
- TO SQUARE :X
- REPEAT 4 [FD :X RT 90]
- END

- SQUARE
- SQUARE 50
- TO SQUARE 50

Self Check Lesson 3

- Suppose you have entered the procedure below. What would you type to use it to draw a SQUARE with sides of 50?
- TO SQUARE :X
- REPEAT 4 [FD :X RT 90]
- END

- SQUARE
- SQUARE 50
- TO SQUARE 50

Try Some Exercises

- Practice with procedures at http://www.csudh.edu/fisher/tbe540/LW3A.htm
- Check out screen positions at http://www.csudh.edu/fisher/tbe540/LW3.htm
- Try the hand-on exercise at http://www.csudh.edu/fisher/tbe540/LEX3.htm

Download Presentation

Connecting to Server..